Skip to content

Instantly share code, notes, and snippets.

@doublemarket
Last active October 10, 2015 12:28
Show Gist options
  • Save doublemarket/3689713 to your computer and use it in GitHub Desktop.
Save doublemarket/3689713 to your computer and use it in GitHub Desktop.
notification stop/start script for nagios (all services on the host)
#!/bin/sh
# enable/disable all 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_HOST_AND_CHILD_NOTIFICATIONS;%s\n" $NOW $HOST > $CMDFILE
if [ $? -eq 0 ] ;then
echo "Success"
echo
echo "Issued command : [$NOW] ENABLE_HOST_AND_CHILD_NOTIFICATIONS:$HOST"
else
echo "Error"
exit 1
fi
}
# disable notification for the host
f_disable() {
/usr/bin/printf "[%lu] DISABLE_HOST_AND_CHILD_NOTIFICATIONS;%s\n" $NOW $HOST > $CMDFILE
if [ $? -eq 0 ] ;then
echo "Success"
echo
echo "Issued command : [$NOW] DISABLE_HOST_AND_CHILD_NOTIFICATIONS:$HOST"
else
echo "Error"
exit 1
fi
}
f_usage() {
echo "Enable/disable all notifications for the host"
echo "using Nagios external commands"
echo
echo "usage: sh $0 hostname [enable|disable]"
}
# MAIN
if [ $# -eq 2 ] ;then
HOST=$1
case $2 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