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.
#!/bin/bash
ON=$(mysql -hxxx.xxx.xxx.xxx -e"update xxxx.xxxx set Value='On' where Category='ExternalServices' and Param='xxxx';")
OFF=$(mysql -hxxx.xxx.xxx.xxx -e"update xxxx.xxxx set Value='Off' where Category='ExternalServices' and Param='xxxx';")
case "$1" in
OK) $ON
;;
WARNING) # Don't do anything
;;
UNKNOWN) # Don't do anything
;;
CRITICAL)
case "$2" in
SOFT)
case "$3" in
1) # Don't do anything
;;
2) # Don't do anything
;;
3) # Don't do anything
;;
esac
;;
HARD)
case "$3" in
1) #Only from state 3
;;
2) #Only from state 3
;;
3) $OFF
;;
esac
;;
esac
;;
esac
exit 0
This directive is used to determine whether or not the event handler for this service is enabled. Values: 0 = disable service event handler, 1 = enable service event handler.
I think the default setting is disabled so you will have to enable it.
Be sure to check out our Knowledgebase for helpful articles and solutions!
May 24 06:38:35 nagios nagios: SERVICE NOTIFICATION: antonsms;apache2;{SERVICE DESCRIPTION};CRITICAL;notify-by-tgn-service;CRITICAL - {HOST}:{PORT} is closed
May 24 06:38:35 nagios nagios: SERVICE EVENT HANDLER: apache2;{SERVICE DESCRIPTION};CRITICAL;HARD;3;{EVENTHANDLER COMMAND NAME}
I can also confirm that it runs after the query I've added
When event handlers and check commands are executed by Nagios, they are run as the nagios user account.
One test you can do is to change to the nagios user account and run your script. To do that, run the following in a shell. Fill in the macros so the combination needed to get the Value set to On or Off in the MYSQL update command.
tgriep wrote:When event handlers and check commands are executed by Nagios, they are run as the nagios user account.
One test you can do is to change to the nagios user account and run your script. To do that, run the following in a shell. Fill in the macros so the combination needed to get the Value set to On or Off in the MYSQL update command.
nagios@nagios:/root$ bash -x /usr/local/nagios/libexec/eventhandlers/xxxxxx $SERVICESTATE$ $SERVICESTATETYPE$ $SERVICEATTEMPT$
++ mysql -hxxx.xxx.xxx.xxx '-eupdate DATABASE.TABLE set Value='\''On'\'' where Category='\''ExternalServices'\'' and Param='\''{FIELDNAME}'\'';'
+ ON=
++ mysql -hxxx.xxx.xxx.xxx '-eupdate DATABASE.TABLE set Value='\''Off'\'' where Category='\''ExternalServices'\'' and Param='\''{FIELDNAME}'\'';'
+ OFF=
+ case "$1" in
+ exit 0
nagios@nagios:/root$
#!/bin/bash
echo $1 >>/tmp/event
echo $2 >>/tmp/event
echo $3 >>/tmp/event
case "$1" in
OK)
mysql -hxxx.xxx.xxx.xxx -e"update xxxx.xxxx set Value='On' where Category='ExternalServices' and Param='xxxx';"
;;
WARNING) # Don't do anything
;;
UNKNOWN) # Don't do anything
;;
CRITICAL)
case "$2" in
SOFT)
case "$3" in
1) # Don't do anything
;;
2) # Don't do anything
;;
3) # Don't do anything
;;
esac
;;
HARD)
case "$3" in
1) #Only from state 3
;;
2) #Only from state 3
;;
3)
mysql -hxxx.xxx.xxx.xxx -e"update xxxx.xxxx set Value='Off' where Category='ExternalServices' and Param='xxxx';"
;;
esac
;;
esac
;;
esac
exit 0
Then run it and see what is passed to the script by looking at the /tmp/event file.
If the scripts starts to function, you can remove these 3 lines from the script.