Skip to content

Instantly share code, notes, and snippets.

@doublemarket
Last active April 19, 2016 17:46
Show Gist options
  • Save doublemarket/3689723 to your computer and use it in GitHub Desktop.
Save doublemarket/3689723 to your computer and use it in GitHub Desktop.
notification stop/start script for nagios (specific service)
#!/bin/sh
# enable/disable specific service notifications for the host
# using Nagios external commands
NOW=`date +%s`
CMDFILE='/var/spool/nagios/cmd/nagios.cmd'
# enable notification for the host
f_enable() {
/usr/bin/printf "[%lu] ENABLE_SVC_NOTIFICATIONS;%s;%s\n" $NOW $HOST $SERVICE > $CMDFILE
if [ $? -eq 0 ] ;then
echo "Success"
echo
echo "Issued command : [$NOW] ENABLE_SRV_NOTIFICATIONS;$HOST;$SERVICE"
else
echo "Error"
exit 1
fi
}
# disable notification for the host
f_disable() {
/usr/bin/printf "[%lu] DISABLE_SVC_NOTIFICATIONS;%s;%s\n" $NOW $HOST $SERVICE > $CMDFILE
if [ $? -eq 0 ] ;then
echo "Success"
echo
echo "Issued command : [$NOW] DISABLE_SRV_NOTIFICATIONS;$HOST;$SERVICE"
else
echo "Error"
exit 1
fi
}
f_usage() {
echo "Enable/disable specific service notifications for the host"
echo "using Nagios external commands"
echo
echo "usage: sh $0 hostname servicename [enable|disable]"
}
# MAIN
if [ $# -eq 3 ] ;then
HOST=$1
SERVICE=$2
case $3 in
enable)
f_enable;;
disable)
f_disable;;
*)
f_usage
exit 1;;
esac
else
f_usage
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment