Page 1 of 1

Command - Notification Handler

Posted: Fri Oct 14, 2016 7:25 am
by bosecorp
Hi

I am trying to do couple things.

I want to switch from using the phone number on the user to the "Addon Address 1"field in the contact.

Code: Select all

echo "$HOSTOUTPUT$" | grep -v "orphan" >/dev/null && /usr/bin/php /usr/local/nagiosxi/scripts/handle_nagioscore_notification.php --notification-type=host --contact="$CONTACTNAME$" --contactemail="$CONTACTEMAIL$" --type=$NOTIFICATIONTYPE$ --escalated="$NOTIFICATIONISESCALATED$" --author="$NOTIFICATIONAUTHOR$" --comments="$NOTIFICATIONCOMMENT$" --host="$HOSTNAME$" --hostaddress="$HOSTADDRESS$" --hostalias="$HOSTALIAS$" --hostdisplayname="$HOSTDISPLAYNAME$" --hoststate=$HOSTSTATE$ --hoststateid=$HOSTSTATEID$ --lasthoststate=$LASTHOSTSTATE$ --lasthoststateid=$LASTHOSTSTATEID$ --hoststatetype=$HOSTSTATETYPE$ --currentattempt=$HOSTATTEMPT$ --maxattempts=$MAXHOSTATTEMPTS$ --hosteventid=$HOSTEVENTID$ --hostproblemid=$HOSTPROBLEMID$ --hostoutput="$HOSTOUTPUT$" --longhostoutput="$LONGHOSTOUTPUT$" --datetime="$LONGDATETIME$"
the second thing I am trying to do is create another notification handler so only uses the "Email Address" field in the contact. using again the command below

Code: Select all

echo "$HOSTOUTPUT$" | grep -v "orphan" >/dev/null && /usr/bin/php /usr/local/nagiosxi/scripts/handle_nagioscore_notification.php --notification-type=host --contact="$CONTACTNAME$" --contactemail="$CONTACTEMAIL$" --type=$NOTIFICATIONTYPE$ --escalated="$NOTIFICATIONISESCALATED$" --author="$NOTIFICATIONAUTHOR$" --comments="$NOTIFICATIONCOMMENT$" --host="$HOSTNAME$" --hostaddress="$HOSTADDRESS$" --hostalias="$HOSTALIAS$" --hostdisplayname="$HOSTDISPLAYNAME$" --hoststate=$HOSTSTATE$ --hoststateid=$HOSTSTATEID$ --lasthoststate=$LASTHOSTSTATE$ --lasthoststateid=$LASTHOSTSTATEID$ --hoststatetype=$HOSTSTATETYPE$ --currentattempt=$HOSTATTEMPT$ --maxattempts=$MAXHOSTATTEMPTS$ --hosteventid=$HOSTEVENTID$ --hostproblemid=$HOSTPROBLEMID$ --hostoutput="$HOSTOUTPUT$" --longhostoutput="$LONGHOSTOUTPUT$" --datetime="$LONGDATETIME$"

Re: Command - Notification Handler

Posted: Fri Oct 14, 2016 9:57 am
by lmiltchev
In addition to the $CONTACTEMAIL$ macro, you should have $CONTACTADDRESSx$ macro in your command ($CONTACTADDRESS1$, $CONTACTADDRESS2$, ...). See our Nagios Core documentation on the topic.
addressx: Address directives are used to define additional "addresses" for the contact. These addresses can be anything - cell phone numbers, instant messaging addresses, etc. Depending on how you configure your notification commands, they can be used to send out an alert to the contact. Up to six addresses can be defined using these directives (address1 through address6). The $CONTACTADDRESSx$ macro will contain this value.
https://assets.nagios.com/downloads/nag ... ml#contact

Example:
define command {
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios Monitor XI Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$ $CONTACTADDRESS1$
}
Let us know if this helped.

Re: Command - Notification Handler

Posted: Fri Oct 14, 2016 1:28 pm
by bosecorp
So, will it be something like this

Code: Select all

echo "$HOSTOUTPUT$" | grep -v "orphan" >/dev/null && /usr/bin/php /usr/local/nagiosxi/scripts/handle_nagioscore_notification.php --notification-type=host --contact="$CONTACTNAME$" --contactemail="$CONTACTEMAIL$,$CONTACTADDRESS1$" --type=$NOTIFICATIONTYPE$ --escalated="$NOTIFICATIONISESCALATED$" --author="$NOTIFICATIONAUTHOR$" --comments="$NOTIFICATIONCOMMENT$" --host="$HOSTNAME$" --hostaddress="$HOSTADDRESS$" --hostalias="$HOSTALIAS$" --hostdisplayname="$HOSTDISPLAYNAME$" --hoststate=$HOSTSTATE$ --hoststateid=$HOSTSTATEID$ --lasthoststate=$LASTHOSTSTATE$ --lasthoststateid=$LASTHOSTSTATEID$ --hoststatetype=$HOSTSTATETYPE$ --currentattempt=$HOSTATTEMPT$ --maxattempts=$MAXHOSTATTEMPTS$ --hosteventid=$HOSTEVENTID$ --hostproblemid=$HOSTPROBLEMID$ --hostoutput="$HOSTOUTPUT$" --longhostoutput="$LONGHOSTOUTPUT$" --datetime="$LONGDATETIME$"
should I put coma or spaces between. that is the part wasn't clear to me with reading the documentation

Re: Command - Notification Handler

Posted: Fri Oct 14, 2016 2:10 pm
by ssax
They should be comma separated as you have, is that not working for you?

Re: Command - Notification Handler

Posted: Fri Oct 14, 2016 2:12 pm
by bosecorp
I want to make sure before I put this into production. because the syntax isn't; clear on the documentation

Re: Command - Notification Handler

Posted: Fri Oct 14, 2016 3:16 pm
by bosecorp
I tried and looks like didn't work.

are these contacts required to have a user?

Re: Command - Notification Handler

Posted: Mon Oct 17, 2016 9:43 am
by ssax
Yes, in order to use the XI notification handlers they need to have an associated user.

I took a look at the code though and it seems that the XI notification handlers don't currently support it, the way it works now is to pull the email address from the user and it will ignore the contactemail information passed into the command.

Re: Command - Notification Handler

Posted: Sun Oct 23, 2016 4:43 pm
by bosecorp
I figured it out. I am found another notification handler that uses only the contact fields

thanks a lot. you can close the ticket

Re: Command - Notification Handler

Posted: Mon Oct 24, 2016 11:42 am
by rkennedy
Awesome, will close it out.

/close