xi_service_notification_handler - $SERVICEDURATION$

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
skunk64
Posts: 9
Joined: Mon Oct 26, 2015 8:43 am

xi_service_notification_handler - $SERVICEDURATION$

Post 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.
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: xi_service_notification_handler - $SERVICEDURATION$

Post 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
skunk64
Posts: 9
Joined: Mon Oct 26, 2015 8:43 am

Re: xi_service_notification_handler - $SERVICEDURATION$

Post 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.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: xi_service_notification_handler - $SERVICEDURATION$

Post 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?
Be sure to check out our Knowledgebase for helpful articles and solutions!
skunk64
Posts: 9
Joined: Mon Oct 26, 2015 8:43 am

Re: xi_service_notification_handler - $SERVICEDURATION$

Post 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%
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: xi_service_notification_handler - $SERVICEDURATION$

Post 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
skunk64
Posts: 9
Joined: Mon Oct 26, 2015 8:43 am

Re: xi_service_notification_handler - $SERVICEDURATION$

Post by skunk64 »

It works!

Thanks very much for your help!
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: xi_service_notification_handler - $SERVICEDURATION$

Post by rkennedy »

Awesome!

Are we good to mark this thread as resolved?
Former Nagios Employee
skunk64
Posts: 9
Joined: Mon Oct 26, 2015 8:43 am

Re: xi_service_notification_handler - $SERVICEDURATION$

Post by skunk64 »

Yep, resolved. :)
avandemore
Posts: 1597
Joined: Tue Sep 27, 2016 4:57 pm

Re: xi_service_notification_handler - $SERVICEDURATION$

Post by avandemore »

Great, thanks for using the Nagios forums. If you have further issues, please open a new thread.
Previous Nagios employee
Locked