Skip to content

Instantly share code, notes, and snippets.

@mikeda
Created May 27, 2013 06:10
Show Gist options
  • Save mikeda/5655421 to your computer and use it in GitHub Desktop.
Save mikeda/5655421 to your computer and use it in GitHub Desktop.
ホストを指定してNagiosのアラートを停止するスクリプト
#!/bin/bash
### 使い方
### アラート停止:nagios_alert.sh stop web01 db01
### アラート再開:nagios_alert.sh start web01 db01
command_file="/var/spool/nagios/cmd/nagios.cmd"
if [ $# -lt 2 ];then
echo "usage: $0 <start|stop> hosts1 host2 ..."
exit 1
elif [ ! -p "$command_file" -o ! -w "$command_file" ];then
echo "Can't write command_file:'$command_file'"
exit 1
fi
action=$1;shift
hosts=$@
if [ "$action" = start ];then
commands="ENABLE_HOST_NOTIFICATIONS ENABLE_HOST_SVC_NOTIFICATIONS"
elif [ "$action" = stop ];then
commands="DISABLE_HOST_NOTIFICATIONS DISABLE_HOST_SVC_NOTIFICATIONS"
else
echo "wrong action"
exit 1
fi
now=$(date +%s)
for host in $hosts;do
for command in $commands;do
echo "[$now] $command;$host"
done
done > $command_file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment