Page 1 of 1

Custom notification variables

Posted: Fri Apr 24, 2015 11:02 am
by BanditBBS
Ok, so we want to add a custom notification variable to our alerts. We can do it and it works great. This variable is to let our Service Desk know if a host in Windows or Linux to help tickets get assigned to proper queues. Our Windows hosts is a much lower number, so adding the custom variable to those ~140 hosts is what we'll do first and maybe not ever set it on the linux hosts. My issue is, if we set it up it works great, but for hosts we don't set the custom variable on, where we put it in the notification messages there is a "$"

Is there a way to suppress the $ when a variable is empty, is that a bug or is that intended?

Re: Custom notification variables

Posted: Fri Apr 24, 2015 1:08 pm
by lmiltchev
Is there a way to suppress the $ when a variable is empty, is that a bug or is that intended?
I am not sure if this "qualifies" as a bug. It is not intended for sure... :) It would be nice to see something more descriptive instead of "$", perhaps "macro is not defined" or even an empty string.

I would like to point out that you will see the text in the notification anyway:

Text: Value //when defined
Text: $ // when is not defined

There could be a way to modify the notification handler command with a bash "one liner", which will verify if the macro is set or not. For example:

if set - display the value
if not - display nothing or display something like "not set".

I haven't tested this but I am curious to see if this is going to work. Seeing one extra "$" in the notifications is not a big deal anyway, but if you are like me, I am sure you are annoyed by it. :) I will play with this to see if I can make it work.

Re: Custom notification variables

Posted: Fri Apr 24, 2015 1:27 pm
by BanditBBS
lmiltchev wrote:I am not sure if this "qualifies" as a bug. It is not intended for sure... :)
Umm...ok, I'll give it to you that unintended doesn't always = bug, lol.

I'm very interested in this modification to notification command using to test if it is filled in. You more or less mean like a wrapper script, right? I think that'd be totally doable. I'm going to play around with it also!

Re: Custom notification variables

Posted: Fri Apr 24, 2015 2:29 pm
by tmcdonald
Gonna swat this off our dashboard for now. Unintended behavior Bug us again after the weekend.

Re: Custom notification variables

Posted: Fri Apr 24, 2015 2:38 pm
by BanditBBS
tmcdonald wrote:Gonna swat this off our dashboard for now. Unintended behavior Bug us again after the weekend.
HAHAHA...sorry for putting back on the dashboard, but I got it :)

Notification command is now this:

Code: Select all

/usr/local/nagios/libexec/not_wrapper_service.sh service "$CONTACTNAME$" "$CONTACTEMAIL$" $NOTIFICATIONTYPE$ "$NOTIFICATIONISESCALATED$" "$NOTIFICATIONAUTHOR$" "$NOTIFICATIONCOMMENT$" "$HOSTNAME$" "$HOSTADDRESS$" "$HOSTALIAS$" "$HOSTDISPLAYNAME$" "$SERVICEDESC$" $HOSTSTATE$ $HOSTSTATEID$ $SERVICESTATE$ $SERVICESTATEID$ $LASTSERVICESTATE$ $LASTSERVICESTATEID$ $SERVICESTATETYPE$ $SERVICEATTEMPT$ $MAXSERVICEATTEMPTS$ $SERVICEEVENTID$ $SERVICEPROBLEMID$ "$SERVICEOUTPUT$" "$LONGSERVICEOUTPUT$" "$LONGDATETIME$" "$_HOSTPROD$" "$_HOSTOSTYPE$"
My shell script is this:

Code: Select all

#!/bin/bash
#
# XI Notification handler Wrapper to populate unset custom variables
#
#/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$" --prod="$_HOSTPROD$" --ostype="$_HOSTOSTYPE$"
#
if [ "${28}" == "$" ]; then
        os="--ostype=\"Not defined\""
else
        os="--ostype=\"${28}\""
fi

command="/usr/bin/php /usr/local/nagiosxi/scripts/handle_nagioscore_notification.php --notification-type=\"$1\" --contact=\"$2\" --contactemail=\"$3\" --type=$4 --escalated=\"$5\" --author=\"$6\" --comments=\"$7\" --host=\"$8\" --hostaddress=\"$9\" --hostalias=\"${10}\" --hostdisplayname=\"${11}\" --service=\"${12}\" --hoststate=${13} --hoststateid=${14} --servicestate=${15} --servicestateid=${16} --lastservicestate=${17} --lastservicestateid=${18} --servicestatetype=${19} --currentattempt=${20} --maxattempts=${21} --serviceeventid=${22} --serviceproblemid=${23} --serviceoutput=\"${24}\" --longserviceoutput=\"${25}\" --datetime=\"${26}\" --prod=\"${27}\" $os"

eval $command
exit 0

Re: Custom notification variables

Posted: Fri Apr 24, 2015 2:40 pm
by tmcdonald
BanditBBS wrote:HAHAHA...sorry for putting back on the dashboard, but I got it :)
*swat* Go away :)



I'll lock this now