Is it possible to have 2 notifications template

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
cesar.garza
Posts: 80
Joined: Mon Aug 19, 2013 3:14 pm

Re: Is it possible to have 2 notifications template

Post by cesar.garza »

slansing wrote:We're looking into this and will get back to you.
Any suggestion slansing ??
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Is it possible to have 2 notifications template

Post by abrist »

Can you run the notification handler script from the cli? Replace the macros with the proper data, for example:

Code: Select all

/usr/local/nagios/libexec/messageone_recovery RECOVERY Test_Service Host_Alias Host_Address HARD Current_Time Service_Is_OK "http://response.url" <email>
Make sure to replace <email> with your email.
Test the handler above, and then check the maillog:

Code: Select all

tail -25 /var/log/maillog
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
cesar.garza
Posts: 80
Joined: Mon Aug 19, 2013 3:14 pm

Re: Is it possible to have 2 notifications template

Post by cesar.garza »

abrist wrote:Can you run the notification handler script from the cli? Replace the macros with the proper data, for example:

Code: Select all

/usr/local/nagios/libexec/messageone_recovery RECOVERY Test_Service Host_Alias Host_Address HARD Current_Time Service_Is_OK "http://response.url" <email>
Make sure to replace <email> with your email.
Test the handler above, and then check the maillog:

Code: Select all

tail -25 /var/log/maillog

Hey abrist, i tried the above thing and it didn't work. that's what you ask me to do ??

Code: Select all

root@stg-nagios01:~#
root@stg-nagios01:~# /usr/local/nagios/libexec/messageone_recovery RECOVERY Test_Service Host_Alias Host_Address HARD Current_Time Service_Is_OK "http://response.url" <[email protected]>
-bash: syntax error near unexpected token `newline'
root@stg-nagios01:~#

abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Is it possible to have 2 notifications template

Post by abrist »

Try: (remove the <>)

Code: Select all

/usr/local/nagios/libexec/messageone_recovery RECOVERY Test_Service Host_Alias Host_Address HARD Current_Time Service_Is_OK "http://response.url" [email protected]
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
cesar.garza
Posts: 80
Joined: Mon Aug 19, 2013 3:14 pm

Re: Is it possible to have 2 notifications template

Post by cesar.garza »

I got this ...

Code: Select all

root@stg-nagios01:~#
root@stg-nagios01:~#
root@stg-nagios01:~# /usr/local/nagios/libexec/messageone_recovery RECOVERY Test_Service Host_Alias Host_Address HARD Current_Time Service_Is_OK "http://response.url" [email protected]
/usr/local/nagios/libexec/messageone_recovery: 18: [: RECOVERY: unexpected operator
root@stg-nagios01:~#
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Is it possible to have 2 notifications template

Post by abrist »

Ok, I missed a syntax error in your script. The condition/antecedent must be on the same line as the 'if' statement:

Code: Select all

#! /bin/sh

NOTIFICATIONTYPE=$1
SERVICEDESC=$2
HOSTALIAS=$3
HOSTADDRESS=$4
SERVICESTATE=$5
LONGDATETIME=$6
SERVICEOUTPUT=$7
SERVICEACTIONURL=$8
CONTACTEMAIL=$9


if [ "${NOTIFICATIONTYPE}" == "RECOVERY" ]; then 
    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: ${NOTIFICATIONTYPE}\n\nService: ${SERVICEDESC}\nHost: ${HOSTALIAS}\nAddress: ${HOSTADDRESS}\nState: ${SERVICESTATE}\n\nDate/Time: ${LONGDATETIME}\n\nAdditional Info:\n\n${SERVICEOUTPUT}\n\nURL: ${SERVICEACTIONURL}$\n" | /usr/bin/mail -s "** ${NOTIFICATIONTYPE} Service Alert: ${HOSTALIAS}/${SERVICEDESC} is ${SERVICESTATE} **" ${CONTACTEMAIL};

fi
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
cesar.garza
Posts: 80
Joined: Mon Aug 19, 2013 3:14 pm

Re: Is it possible to have 2 notifications template

Post by cesar.garza »

I am still getting the same error . The only thing that changed is number from (18) to (14).

Code: Select all

root@stg-nagios01:/usr/local/nagios/libexec#
root@stg-nagios01:/usr/local/nagios/libexec# /usr/local/nagios/libexec/messageone_recovery RECOVERY Test_Service Host_Alias Host_Address HARD Current_Time Service_Is_OK "http://response.url" [email protected]
/usr/local/nagios/libexec/messageone_recovery: 14: [: RECOVERY: unexpected operator
root@stg-nagios01:/usr/local/nagios/libexec#
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Is it possible to have 2 notifications template

Post by abrist »

hmmm. How about:

Code: Select all

#! /bin/sh

NOTIFICATIONTYPE=$1
SERVICEDESC=$2
HOSTALIAS=$3
HOSTADDRESS=$4
SERVICESTATE=$5
LONGDATETIME=$6
SERVICEOUTPUT=$7
SERVICEACTIONURL=$8
CONTACTEMAIL=$9


if [ "$NOTIFICATIONTYPE" == "RECOVERY" ] 
then
    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE\n\nService: $SERVICEDESC\nHost: $HOSTALIAS\nAddress: $HOSTADDRESS\nState: $SERVICESTATE\n\nDate/Time: $LONGDATETIME\n\nAdditional Info:\n\n$SERVICEOUTPUT\n\nURL: $SERVICEACTIONURL$\n" | /usr/bin/mail -s "** $NOTIFICATIONTYPE Service Alert: $HOSTALIAS/$SERVICEDESC is $SERVICESTATE **" $CONTACTEMAIL;

fi
I tested it and it works . . .
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
cesar.garza
Posts: 80
Joined: Mon Aug 19, 2013 3:14 pm

Re: Is it possible to have 2 notifications template

Post by cesar.garza »

Still getting error. is there any dependencies for that ? I have attached a screenshot so you can see if i am doing anything wrong.
Attachments
5.jpg
1.jpg
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Is it possible to have 2 notifications template

Post by abrist »

What is your default shell (/bin/sh)?
Try changing the sha-bang from:

Code: Select all

#!/bin/sh
To:

Code: Select all

#!/bin/bash 
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
Locked