EventHandler update MySQL query
Posted: Tue May 23, 2017 7:01 am
Good day
Running a check to see if a port is open on a link;
Then if it an event happens the eventshandler runs a script to update a mysqldb to set it from "On" to "Off".
Events Handler script;
But the update query does not run.
Service
Anything I'm missing
nagios has rights to run the mysqlclient query and the mysql command works straight from bash running as nagios.
Running a check to see if a port is open on a link;
Code: Select all
#!/bin/bash
# portcheck tool
SERVER=$1
PORT=$2
usage()
{
echo -e "\n USAGE: ./${0##*/} [host|ip] \n"
exit
}
check_port()
{
local host="${SERVER}"
local port="${PORT}"
if nc -w 5 -z ${host-ip} ${port} 2>/dev/null
then
echo -e "OK - ${host}:${port} is open"
exit 0
else
echo -e "CRITICAL - ${host}:${port} is closed"
exit 2
fi
}
[[ $# -ne 2 ]] && usage
check_port ${1} ${2}
Events Handler script;
Code: Select all
#!/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 0Code: Select all
define command{
command_name xxxx_xxxx
command_line /usr/local/nagios/libexec/eventhandlers/xxxxxx $SERVICESTATE$ $SERVICESTATETYPE$ $SERVICEATTEMPT$
}Code: Select all
define service{
use xxxxx-service
host_name apache2
service_description xxxxxxxxxxxxx
check_command check_xxxxx!hostname!PortNumber
event_handler xxxx_xxxx
register 1
}nagios has rights to run the mysqlclient query and the mysql command works straight from bash running as nagios.