Command - Notification Handler

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
bosecorp
Posts: 929
Joined: Thu Jun 26, 2014 1:00 pm

Command - Notification Handler

Post 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$"
Last edited by rkennedy on Mon Oct 24, 2016 11:43 am, edited 2 times in total.
Reason: code block
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Command - Notification Handler

Post 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.
Be sure to check out our Knowledgebase for helpful articles and solutions!
bosecorp
Posts: 929
Joined: Thu Jun 26, 2014 1:00 pm

Re: Command - Notification Handler

Post 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
Last edited by dwhitfield on Fri Oct 14, 2016 1:58 pm, edited 1 time in total.
Reason: code block
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Command - Notification Handler

Post by ssax »

They should be comma separated as you have, is that not working for you?
bosecorp
Posts: 929
Joined: Thu Jun 26, 2014 1:00 pm

Re: Command - Notification Handler

Post by bosecorp »

I want to make sure before I put this into production. because the syntax isn't; clear on the documentation
bosecorp
Posts: 929
Joined: Thu Jun 26, 2014 1:00 pm

Re: Command - Notification Handler

Post by bosecorp »

I tried and looks like didn't work.

are these contacts required to have a user?
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Command - Notification Handler

Post 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.
bosecorp
Posts: 929
Joined: Thu Jun 26, 2014 1:00 pm

Re: Command - Notification Handler

Post 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
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Command - Notification Handler

Post by rkennedy »

Awesome, will close it out.

/close
Former Nagios Employee
Locked