Last active
August 11, 2017 21:09
-
-
Save doublemarket/5493912 to your computer and use it in GitHub Desktop.
notification stop/start script for nagios (all services on hosts in the hostgroup)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# enable/disable all notifications for hosts | |
# in the hostgroup | |
# using Nagios external commands | |
NOW=`date +%s` | |
CMDFILE='/var/spool/nagios/cmd/nagios.cmd' | |
# enable notification for the hostgroup | |
f_enable() { | |
/usr/bin/printf "[%lu] ENABLE_HOSTGROUP_HOST_NOTIFICATIONS;%s\n" $NOW $HOST > $CMDFILE | |
if [ $? -eq 0 ] ;then | |
echo | |
echo "Success" | |
echo "Issued command : [$NOW] ENABLE_HOSTGROUP_HOST_NOTIFICATIONS:$HOST" | |
else | |
echo "Error" | |
exit 1 | |
fi | |
/usr/bin/printf "[%lu] ENABLE_HOSTGROUP_SVC_NOTIFICATIONS;%s\n" $NOW $HOST > $CMDFILE | |
if [ $? -eq 0 ] ;then | |
echo | |
echo "Success" | |
echo "Issued command : [$NOW] ENABLE_HOSTGROUP_SVC_NOTIFICATIONS:$HOST" | |
else | |
echo "Error" | |
exit 1 | |
fi | |
} | |
# disable notification for the hostgroup | |
f_disable() { | |
/usr/bin/printf "[%lu] DISABLE_HOSTGROUP_HOST_NOTIFICATIONS;%s\n" $NOW $HOST > $CMDFILE | |
if [ $? -eq 0 ] ;then | |
echo | |
echo "Success" | |
echo "Issued command : [$NOW] DISABLE_HOSTGROUP_HOST_NOTIFICATIONS:$HOST" | |
else | |
echo "Error" | |
exit 1 | |
fi | |
/usr/bin/printf "[%lu] DISABLE_HOSTGROUP_SVC_NOTIFICATIONS;%s\n" $NOW $HOST > $CMDFILE | |
if [ $? -eq 0 ] ;then | |
echo | |
echo "Success" | |
echo "Issued command : [$NOW] DISABLE_HOSTGROUP_SVC_NOTIFICATIONS:$HOST" | |
else | |
echo "Error" | |
exit 1 | |
fi | |
} | |
f_usage() { | |
echo | |
echo " Enable/disable all notifications for hosts" | |
echo " in the hostgroup" | |
echo " using Nagios external commands" | |
echo | |
echo " usage: sh $0 [enable|disable] hostgroupname" | |
echo | |
} | |
# MAIN | |
if [ $# -eq 2 ] ;then | |
HOST=$2 | |
case $1 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