Page 1 of 1

Nagios XI Command Notification URL

Posted: Tue Jan 06, 2015 3:59 pm
by emartine
I apparently misunderstood how the notification command was being used... so here is my second attempt at trying to fix an issue here on our end.

The host-notify-by-email is being used as the command to send notifications for a service:

/usr/bin/printf "%b" "***** Nagios Monitor XI Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\nAuthor: $NOTIFICATIONAUTHOR$\nComment: $NOTIFICATIONCOMMENT$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n\nResponse URL:\n\n %responseurl%" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$

Is it possible to have the responseurl in bold above be the Nagios XI URL leading to the service issue in nagios xi?

Re: Nagios XI Command Notification URL

Posted: Tue Jan 06, 2015 5:17 pm
by emartine
/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\nResponse URL:\nhttps://<nagioshostname>/nagiosxi/includes/components/xicore/status.php?show=servicedetail&host=$HOSTNAME$&service=$$(echo "$SERVICEDESC$" | sed 's/%/%25/g;s/\\/%2F/g;s/ /%20/g;s/!/%21/g;s/\"/%22/g;s/#/%23/g;s/\$/%24/g;s/\&/%26/g;s/'\''/%27/g;s/(/%28/g;s/)/%29/g;s/:/%3A/g')" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$

I've come close. If I get rid of the sed part it works but I just need some help with the sed portion of it in order to make it more url safe.

Re: Nagios XI Command Notification URL

Posted: Tue Jan 06, 2015 5:19 pm
by abrist
Possibly, but you will not be able to use the %<var>% macros as they are specific to the php (xi_*_notificati5on_handler) scripts, not the sendmail commands.
You will need to url encode the link as hostnames/service descriptions can include spaces and other non-alphanumeric characters.

EDIT:

Looking at your regex from your newest post. It seems close.

In fact, it looks like it is working from my shell. What issues are you currently having with it?

Re: Nagios XI Command Notification URL

Posted: Wed Jan 07, 2015 11:21 am
by emartine
When I add it to the command, notifications stop. We receive no new notifications. If I remove most of the sed piece and leave just sed 's/ /%20/g' it goes through without issue. A colleague recommended the below syntax and it seems to work better as it includes the frames when the url is clicked on and it also brings you to the login prompt instead of giving a timeout error in the browser if you are not logged in. For this to work properly a user must be logged into nagiosxi so I will probably also need to add a note to the notification URL stating that. Still.... the sed piece is still not quite there yet. What log will errors for this show up in?




/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\nResponse URL:\nhttps://nagiosservername/nagiosxi/?xiwindow=https%3A%2F%2Fnagiosservername%2Fnagiosxi%2Fincludes%2Fcomponents%2Fxicore%2Fstatus.php%3Fshow=servicedetail%26dest=auto%26host=$HOSTNAME$%26service=$$(echo "$SERVICEDESC$" | sed 's/ /%20/g')" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$

Re: Nagios XI Command Notification URL

Posted: Wed Jan 07, 2015 11:56 am
by abrist
Maybe the semi-colons are not handled correctly by nagios. Try with multiple seds and pipes?

Code: Select all

$$(echo "$SERVICEDESC$" | sed 's/%/%25/g' | sed 's/\\/%2F/g' | sed 's/ /%20/g;s/!/%21/g' | sed 's/\"/%22/g' | sed 's/#/%23/g' | sed 's/\$/%24/g' | sed 's/\&/%26/g' | sed 's/'\''/%27/g' | sed 's/(/%28/g' | sed 's/)/%29/g' | sed 's/:/%3A/g'