Page 1 of 1

xi_service_notification_handler - $SERVICEDURATION$

Posted: Mon Aug 29, 2016 8:13 am
by skunk64
Hello,

I'm having problems with $SERVICEDURATION$ notification variable on Nagios XI.

On Nagios Core with $SERVICEDURATION$ notification variable in alert output, I get something like:
...
State: CRITICAL for 0d 3h 4m 7s
...


When using same configuration in xi_service_notification_handler on Nagios XI, it only shows days. Looks like:
...
State: CRITICAL for 0d
...


My question is: how to get Nagios XI to show days, hours, minutes and seconds like it is shown in Nagios Core?

There is another variable called $SERVICEDURATIONSEC$ which shows only seconds, but that's not what I want.

Thanks.

Re: xi_service_notification_handler - $SERVICEDURATION$

Posted: Mon Aug 29, 2016 1:37 pm
by ssax
I am unable to replicate this, it works properly on mine (XI 5.2.9), what version of XI are you running? Please post your xi_service_notification_handler definition and show us the email template that you have set for your user.


Thank you

Re: xi_service_notification_handler - $SERVICEDURATION$

Posted: Mon Aug 29, 2016 3:13 pm
by skunk64
Version: 5.2.9

xi_service_notification_handler

Code: Select all

/usr/bin/php /usr/local/nagiosxi/scripts/handle_nagioscore_notification.php --notification-type=service --contact="$CONTACTNAME$" --contactemail="$CONTACTEMAIL$" --type=$NOTIFICATIONTYPE$ --escalated="$NOTIFICATIONISESCALATED$" --author="$NOTIFICATIONAUTHOR$" --comments="$NOTIFICATIONCOMMENT$" --host="$HOSTNAME$" --hostaddress="$HOSTADDRESS$" --hostalias="$HOSTALIAS$" --hostdisplayname="$HOSTDISPLAYNAME$" --service="$SERVICEDESC$" --hoststate=$HOSTSTATE$ --hoststateid=$HOSTSTATEID$ --servicestate=$SERVICEDURATION$ --servicestateid=$SERVICESTATEID$ --lastservicestate=$LASTSERVICESTATE$ --lastservicestateid=$LASTSERVICESTATEID$ --servicestatetype=$SERVICESTATETYPE$ --currentattempt=$SERVICEATTEMPT$ --maxattempts=$MAXSERVICEATTEMPTS$ --serviceeventid=$SERVICEEVENTID$ --serviceproblemid=$SERVICEPROBLEMID$ --serviceoutput="$SERVICEOUTPUT$" --longserviceoutput="$LONGSERVICEOUTPUT$" --datetime="$LONGDATETIME$"
You'll notice that I have added $SERVICEDURATION$ under --servicestate. It's for testnig purposes and only way I could get it to show. When I insert --serviceduration=$SERVICEDURATION$ I don't get any information at all.

I'm not sure what you mean under email template. Please, provide more information.

Thank you.

Re: xi_service_notification_handler - $SERVICEDURATION$

Posted: Mon Aug 29, 2016 3:45 pm
by lmiltchev
Click on the username in the upper right corner, and go to "Notification Messages". In the "Service Alert Message" field, make sure you have:

Code: Select all

State: %servicestate%
Click on "Update Settings".

Send custom notification to test this setting. Did it work now?

Re: xi_service_notification_handler - $SERVICEDURATION$

Posted: Tue Aug 30, 2016 2:11 am
by skunk64
Yes, I got that:

Code: Select all

%type% Service Alert - %host%/%service% is %servicestate%

***** Nagios XI Alert *****

%alertsummary%

Notification Type: %type%

Service: %service%
Host: %host%
Address: %hostaddress%
State: %servicestate%
Last State: %lastservicestate%
Info:
%serviceoutput%
Date/Time: %datetime%

Respond: %responseurl%
Nagios URL: %xiserverurl%

Re: xi_service_notification_handler - $SERVICEDURATION$

Posted: Tue Aug 30, 2016 2:16 pm
by ssax
Please update your command to:

Code: Select all

/usr/bin/php /usr/local/nagiosxi/scripts/handle_nagioscore_notification.php --notification-type=service --contact="$CONTACTNAME$" --contactemail="$CONTACTEMAIL$" --type=$NOTIFICATIONTYPE$ --escalated="$NOTIFICATIONISESCALATED$" --author="$NOTIFICATIONAUTHOR$" --comments="$NOTIFICATIONCOMMENT$" --host="$HOSTNAME$" --hostaddress="$HOSTADDRESS$" --hostalias="$HOSTALIAS$" --hostdisplayname="$HOSTDISPLAYNAME$" --service="$SERVICEDESC$" --hoststate=$HOSTSTATE$ --hoststateid=$HOSTSTATEID$ --servicestate=$SERVICESTATE$ --servicestateid=$SERVICESTATEID$ --lastservicestate=$LASTSERVICESTATE$ --lastservicestateid=$LASTSERVICESTATEID$ --servicestatetype=$SERVICESTATETYPE$ --currentattempt=$SERVICEATTEMPT$ --maxattempts=$MAXSERVICEATTEMPTS$ --serviceeventid=$SERVICEEVENTID$ --serviceproblemid=$SERVICEPROBLEMID$ --serviceoutput="$SERVICEOUTPUT$" --longserviceoutput="$LONGSERVICEOUTPUT$" --datetime="$LONGDATETIME$" --serviceduration="$SERVICEDURATION$"
Then modify the email template you just posted to:

Code: Select all

Notification Type: %type%

Service: %service%
Host: %host%
Address: %hostaddress%
State: %servicestate%
Last State: %lastservicestate%
Info:
%serviceoutput%
Date/Time: %datetime%
Duration: %serviceduration%

Respond: %responseurl%
Nagios URL: %xiserverurl%
Try it again and see if it works.


Thank you

Re: xi_service_notification_handler - $SERVICEDURATION$

Posted: Wed Aug 31, 2016 8:00 am
by skunk64
It works!

Thanks very much for your help!

Re: xi_service_notification_handler - $SERVICEDURATION$

Posted: Wed Aug 31, 2016 9:14 am
by rkennedy
Awesome!

Are we good to mark this thread as resolved?

Re: xi_service_notification_handler - $SERVICEDURATION$

Posted: Tue Oct 18, 2016 6:58 am
by skunk64
Yep, resolved. :)

Re: xi_service_notification_handler - $SERVICEDURATION$

Posted: Tue Oct 18, 2016 10:35 am
by avandemore
Great, thanks for using the Nagios forums. If you have further issues, please open a new thread.