Page 1 of 1
macros fail in mail notification
Posted: Tue Feb 19, 2019 2:16 pm
by rbozdog
Hi
I have the following issue when receiving mail notifications n Nagios core 4.4.3.
The mail content:
Code: Select all
***** Nagios *****
Notification Type: CUSTOM
Service: $
Host: HOST ALIAS
Address: 0.0.0.0(IS AN EXAMPLE)
State: $
Date/Time: Tue Feb 19 20:48:05 EET 2019
Additional Info:
$
The subject:
Code: Select all
** CUSTOM Service Alert: HOST ALIAS/$ is $ **
As you can see the macros are returning just a $ not the value.
The command line is:
Code: Select all
/usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /bin/mailx -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
The command line for the HOST notifications is the same (the default one) and it's working, just for the services is doing this.
Thank you in advance!
Re: macros fail in mail notification
Posted: Tue Feb 19, 2019 5:40 pm
by lmiltchev
Can you show us the actual service definition?
Re: macros fail in mail notification
Posted: Wed Feb 20, 2019 2:11 am
by rbozdog
These are my service definitions:
Code: Select all
define service {
use generic-service
hostgroup_name conn-main
servicegroups main-service
service_description PING
check_command check_ping!200.0,20%!600.0,60%
max_check_attempts 5
check_interval 5
retry_interval 1
notifications_enabled 1
}
Code: Select all
define service {
use generic-service
hostgroup_name port24
servicegroups switch-service
service_description PORT24
check_command check_snmp!-C NMM -o ifOperStatus.10024 -r 1 -m RFC1213-MIB
notifications_enabled 1
notification_period 24x7
notification_options c,r
notification_interval 960
max_check_attempts 5
check_interval 5
retry_interval 1
contact_groups admins
notifications_enabled 1
}
Code: Select all
define service {
use generic-service
hostgroup_name ups
servicegroups ups-service
service_description Main Battery Status
check_command snmp_ups_stat!NMM
notifications_enabled 1
notification_period 24x7
notification_options c,r
notification_interval 960
max_check_attempts 5
check_interval 5
retry_interval 1
contact_groups admins
notifications_enabled 1
}
Re: macros fail in mail notification
Posted: Wed Feb 20, 2019 9:19 am
by lmiltchev
We need some more information. Who is the contact that is having issues with notifications (macros not resolving)? Is he/she a member of the "admins" contact group or is added to the "generic-service" template? We need to see this contact's config. It is possible that the service notification handler (notify-service-by-email) is set as both - host and service notification command. In this case, if you had a host notification, the output would be messed up, and the macros wouldn't resolve (e.g. $SERVICEDESC$ and $SERVICESTATE$ wouldn't exist).
You could also enable debugging in the nagios.cfg file and set the debug_level=2048. Create a condition that is going to bring a "test" service to a hard CRITICAL state. Post the actual email notification that you receive and the /usr/local/nagios/var/nagios.debug file on the forum.
Re: macros fail in mail notification
Posted: Wed Feb 20, 2019 11:48 am
by rbozdog
All the contacts are having this issue, but this the contacts definition:
Code: Select all
define contact {
contact_name rbozdog
use generic-contact
alias Rares Bozdog
service_notification_period 24x7
host_notification_period 24x7
service_notification_options c,r
host_notification_options d,r
service_notification_commands notify-host-by-email
host_notification_commands notify-service-by-email
email rbozdog@mail.com
}
Also the contact tempate:
Code: Select all
define contact {
name generic-contact ; The name of this contact template
service_notification_period 24x7 ; service notifications can be sent anytime
host_notification_period 24x7 ; host notifications can be sent anytime
service_notification_options w,u,c,r,f,s ; send notifications for all service states, flapping events, and scheduled downtime events
host_notification_options d,u,r,f,s ; send notifications for all host states, flapping events, and scheduled downtime events
service_notification_commands notify-service-by-email ; send service notifications via email
host_notification_commands notify-host-by-email ; send host notifications via email
register 0 ; DON'T REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!
}
And the contact groups:
Code: Select all
define contactgroup {
contactgroup_name admins
alias Nagios Administrators
members rbozdog
}
For every state is this problem so I sent a costum notification:
Code: Select all
[1550679657.801291] [2048.1] [pid=28645] **** BEGIN MACRO PROCESSING ***********
[1550679657.801298] [2048.1] [pid=28645] Processing: 'HOST NOTIFICATION: rbozdog;HOSTNAME;CUSTOM ($HOSTSTATE$);notify-service-by-email;$HOSTOUTPUT$;$NOTIFICATIONAUTHOR$;$NOTIFICATIONCOMMENT$
'
[1550679657.801312] [2048.1] [pid=28645] Done. Final output: 'HOST NOTIFICATION: rbozdog;HOSTNAME;CUSTOM (UP);notify-service-by-email;PING OK - Packet loss = 0%, RTA = 43.18 ms;RBozdog;test
'
[1550679657.801319] [2048.1] [pid=28645] **** END MACRO PROCESSING *************
The e-mail notification:
Code: Select all
***** Nagios *****
Notification Type: CUSTOM
Service: $
Host: ALIAS
Address: 0.0.0.0
State: $
Date/Time: Wed Feb 20 18:38:43 EET 2019
Additional Info:
$
The e-mail subject:
Code: Select all
** CUSTOM Service Alert: ALIAS/$ is $ **
I can see in the debug that is as you said, the service is processed as a host notification, but what is the solution?
Thank you!
Re: macros fail in mail notification
Posted: Wed Feb 20, 2019 12:02 pm
by lmiltchev
You notifications commands are "switched"...
Change this (in the rbozdog's definition):
Code: Select all
service_notification_commands notify-host-by-email
host_notification_commands notify-service-by-email
to this:
Code: Select all
service_notification_commands notify-service-by-email
host_notification_commands notify-host-by-email
to see if this is going to fix your issue.
Update: As you said "All the contacts are having this issue, but this...", most probably you have the actual commands "flipped" (switched) as well. Make sure that notify-host-by-email and notify-service-by-email are correctly defined.
Can you show us both notification commands?
Re: macros fail in mail notification
Posted: Wed Feb 20, 2019 12:54 pm
by rbozdog
OMG! Sorry for my mistake... I am so embarrassed.
I was looking for the problem deeper and I didn't saw my stupid mistake.
That was the problem and now is working excellent.
Sorry again for bothering you with my stupid mistake!
Thanks a lot for your support!
Re: macros fail in mail notification
Posted: Wed Feb 20, 2019 1:00 pm
by lmiltchev
I am glad I could help!