Changes to service notifications not invoked
Changes to service notifications not invoked
Hi,
I modified the notify-service-by-email command to include a Comment field with the macro $NOTIFICATIONCOMMENT$. The change is accepted and even reflected in commands.cfg when I write out the config files, but the mail doesn't include the text I added. In fact, I don't even see the "Additional Info" field that's there before I made a change. Is email generated elsewhere? TIA.
define command {
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** Nagios Monitor XI Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n\nComment: $NOTIFICATIONCOMMENT$" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}
I modified the notify-service-by-email command to include a Comment field with the macro $NOTIFICATIONCOMMENT$. The change is accepted and even reflected in commands.cfg when I write out the config files, but the mail doesn't include the text I added. In fact, I don't even see the "Additional Info" field that's there before I made a change. Is email generated elsewhere? TIA.
define command {
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** Nagios Monitor XI Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n\nComment: $NOTIFICATIONCOMMENT$" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}
- Kyle
Re: Changes to service notifications not invoked
Today I noted in nagios.log that the notification doesn't appear to be done by the normal notify-service-by-email script but by this xi_service_notification_handler.
Wed Apr 13 9:36:38 2011 SERVICE NOTIFICATION: admins;localhost;Check Badness;OK;xi_service_notification_handler;OK: All hunky dory.
Where on my current Nagios Core systems, it's clearly the script.
Wed Apr 13 9:22:59 2011 SERVICE NOTIFICATION: admins;bt-na01;check-netapp-vols;WARNING;notify-service-by-email;/vol/oracle (86% gt 85% warn threshold)
Can someone tell me if this is how notifications are done in XI and point out where the email body fields are constructed? I can see NOTIFICATIONCOMMENTS being passed to the /usr/local/nagiosxi/scripts/handle_nagioscore_notification.php script as an argument but don't know where those go from there as I don't know PHP. Am I going down the right path here? If so, when is the regular notify-service-by-email used by XI or is it at all?
Wed Apr 13 9:36:38 2011 SERVICE NOTIFICATION: admins;localhost;Check Badness;OK;xi_service_notification_handler;OK: All hunky dory.
Where on my current Nagios Core systems, it's clearly the script.
Wed Apr 13 9:22:59 2011 SERVICE NOTIFICATION: admins;bt-na01;check-netapp-vols;WARNING;notify-service-by-email;/vol/oracle (86% gt 85% warn threshold)
Can someone tell me if this is how notifications are done in XI and point out where the email body fields are constructed? I can see NOTIFICATIONCOMMENTS being passed to the /usr/local/nagiosxi/scripts/handle_nagioscore_notification.php script as an argument but don't know where those go from there as I don't know PHP. Am I going down the right path here? If so, when is the regular notify-service-by-email used by XI or is it at all?
- Kyle
-
tonyyarusso
- Posts: 1128
- Joined: Wed Mar 03, 2010 12:38 pm
- Location: St. Paul, MN, USA
- Contact:
Re: Changes to service notifications not invoked
That's correct - XI routes notifications through a separate handler, so that it can honor various other user settings made available in XI. If you were to delve into the Core Config Manager, you would see that contacts reference a template called "xi_contact_generic", which in turn is defined as using the commands "xi_host_notification_handler" and "xi_service_notification_handler", which are PHP scripts. These already include a $NOTIFICATIONCOMMENT$ macro.
The settings for formatting the text of e-mails are defined on a per-user basis. You can access your by clicking your username in the upper right corner of the XI interface, and then navigating to "Notification Messages" in the left sidebar.
The settings for formatting the text of e-mails are defined on a per-user basis. You can access your by clicking your username in the upper right corner of the XI interface, and then navigating to "Notification Messages" in the left sidebar.
Re: Changes to service notifications not invoked
Ah, I see - thanks. Is there any way to change the base per-user format from the initial roll-out or change it globally afterward? And while I can appreciate the per-user customization, I can also see someone ruining their settings.
- Kyle
-
tonyyarusso
- Posts: 1128
- Joined: Wed Mar 03, 2010 12:38 pm
- Location: St. Paul, MN, USA
- Contact:
Re: Changes to service notifications not invoked
Unfortunately I believe this lies within the encrypted code, so you wouldn't have access to it.hhlodge wrote:Ah, I see - thanks. Is there any way to change the base per-user format from the initial roll-out
Yes, although there is not a GUI for this currently. These settings are stored in PostgreSQL, in the 'nagiosxi' database, in the 'xi_usermeta' table.hhlodge wrote:or change it globally afterward?
Some raw background on what that looks like:
Code: Select all
nagiosxi=# \d xi_usermeta
Table "public.xi_usermeta"
Column | Type | Modifiers
-------------+------------------------+-------------------------------------------------------------------
usermeta_id | integer | not null default nextval('xi_usermeta_usermeta_id_seq'::regclass)
user_id | integer | not null
keyname | character varying(255) | not null
keyvalue | text |
autoload | smallint | default (0)::smallint
Indexes:
"xi_usermeta_pkey" PRIMARY KEY, btree (usermeta_id)
"xi_usermeta_user_id_key" UNIQUE, btree (user_id, keyname)
"xi_usermeta_autoload_idx" btree (autoload)
Code: Select all
nagiosxi=# select * from xi_usermeta where keyname='notification_messages';
usermeta_id | user_id | keyname | keyvalue | autoload
-------------+---------+-----------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------+----------
182 | 18 | notification_messages | a:2:{s:5:"email";a:2:{s:4:"host";a:2:{s:7:"subject";s:46:"%type% Host Alert - %hostalias% is %hoststate%";s:7:"message";s:188:"***** Nagios XI Alert *****
Notification Type: %type%
Host: %host%
State: %hoststate%
Address: %hostaddress%
Info: %hostoutput%
Date/Time: %datetime%
Nagios URL: %xiserverurl%
";}s:7:"service";a:2:{s:7:"subject";s:62:"%type% Service Alert - %hostalias%/%service% is %servicestate%";s:7:"message";s:222:"***** Nagios XI Alert *****
Notification Type: %type%
Service: %service%
Host: %hostalias%
Address: %hostaddress%
State: %servicestate%
Info:
%serviceoutput%
Date/Time: %datetime%
Nagios URL: %xiserverurl%
";}}s:10:"mobiletext";a:2:{s:4:"host";a:2:{s:7:"subject";s:17:"%type% Host Alert";s:7:"message";s:130:"Host: %host%
State: %hoststate%
Address: %hostaddress%
Info: %hostoutput%
Date/Time: %datetime%
Nagios URL: %xiserverurl%
";}s:7:"service";a:2:{s:7:"subject";s:20:"%type% Service Alert";s:7:"message";s:162:"Service: %service%
Host: %hostalias%
Address: %hostaddress%
State: %servicestate%
Info:
%serviceoutput%
Date/Time: %datetime%
Nagios URL: %xiserverurl%
";}}} | 1
(1 row)
Code: Select all
nagiosxi=# SELECT * FROM xi_usermeta LEFT JOIN xi_users USING (user_id) WHERE keyname='notification_messages' AND username='nagiosadmin';-
tonyyarusso
- Posts: 1128
- Joined: Wed Mar 03, 2010 12:38 pm
- Location: St. Paul, MN, USA
- Contact:
Re: Changes to service notifications not invoked
Note: This seemed appropriate for a feature request to look at for the future: http://tracker.nagios.com/view.php?id=140
Re: Changes to service notifications not invoked
I now have my notifications customized as I'd like them. I see the macros within these are not the standard Nagios macros but ones that I just happen to notice were the --option=%MACRO% names to the PHP script. A regular user would never know or see this. I looked in the user guide and see no mention of this there either and there's no help button on the page, so there's a big gap here in assistance for the users. Are these new macros published anywhere? I couldn't find it. Thanks again.
- Kyle
-
tonyyarusso
- Posts: 1128
- Joined: Wed Mar 03, 2010 12:38 pm
- Location: St. Paul, MN, USA
- Contact:
Re: Changes to service notifications not invoked
Sadly, no. I starting looking into it a while back and got sidetracked with other things. I'll add you to my "contact when this is done" list.
http://tracker.nagios.com/view.php?id=45
http://tracker.nagios.com/view.php?id=45
Re: Changes to service notifications not invoked
I'll put them here in case someone searches for it. In general, they're quite close. I just happen to pick ones that differed a lot.
Service notification macros:
%author% = "$NOTIFICATIONAUTHOR$"
%comments% = "$NOTIFICATIONCOMMENT$"
%contact% = "$CONTACTNAME$"
%contactemail% = "$CONTACTEMAIL$"
%currentattempt% = $SERVICEATTEMPT$
%datetime% = "$LONGDATETIME$
%escalated% = "$NOTIFICATIONISESCALATED$"
%hostaddress% = "$HOSTADDRESS$"
%hostalias% = "$HOSTALIAS$"
%host% = "$HOSTNAME$"
%hoststate% = $HOSTSTATE$
%hoststateid% = $HOSTSTATEID$
%lastservicestateid% = $LASTSERVICESTATEID$
%lastservicestate% = $LASTSERVICESTATE$
%longserviceoutput% = "$LONGSERVICEOUTPUT$"
%maxattempts% = $MAXSERVICEATTEMPTS$
%serviceeventid% = $SERVICEEVENTID$
%serviceoutput% = "$SERVICEOUTPUT$"
%serviceproblemid% = $SERVICEPROBLEMID$
%service% = "$SERVICEDESC$"
%servicestateid% = $SERVICESTATEID$
%servicestate% = $SERVICESTATE$
%servicestatetype% = $SERVICESTATETYPE$
%type% = $NOTIFICATIONTYPE$
Service notification macros:
%author% = "$NOTIFICATIONAUTHOR$"
%comments% = "$NOTIFICATIONCOMMENT$"
%contact% = "$CONTACTNAME$"
%contactemail% = "$CONTACTEMAIL$"
%currentattempt% = $SERVICEATTEMPT$
%datetime% = "$LONGDATETIME$
%escalated% = "$NOTIFICATIONISESCALATED$"
%hostaddress% = "$HOSTADDRESS$"
%hostalias% = "$HOSTALIAS$"
%host% = "$HOSTNAME$"
%hoststate% = $HOSTSTATE$
%hoststateid% = $HOSTSTATEID$
%lastservicestateid% = $LASTSERVICESTATEID$
%lastservicestate% = $LASTSERVICESTATE$
%longserviceoutput% = "$LONGSERVICEOUTPUT$"
%maxattempts% = $MAXSERVICEATTEMPTS$
%serviceeventid% = $SERVICEEVENTID$
%serviceoutput% = "$SERVICEOUTPUT$"
%serviceproblemid% = $SERVICEPROBLEMID$
%service% = "$SERVICEDESC$"
%servicestateid% = $SERVICESTATEID$
%servicestate% = $SERVICESTATE$
%servicestatetype% = $SERVICESTATETYPE$
%type% = $NOTIFICATIONTYPE$
- Kyle
Re: Changes to service notifications not invoked
Thank you for this, very useful! 