/
shed_downtime.sh
executable file
·115 lines (94 loc) · 2.9 KB
/
shed_downtime.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash
## ./cmd.cgi
# getcgivars(): Unsupported REQUEST_METHOD -> ''
#
# I'm guessing you're trying to execute the CGI from a command line.
# In order to do that, you need to set the REQUEST_METHOD environment
# variable to either "GET", "HEAD", or "POST". When using the
# GET and HEAD methods, arguments can be passed to the CGI
# by setting the "QUERY_STRING" environment variable. If you're
# using the POST method, data is read from standard input. Also of
# note: if you've enabled authentication in the CGIs, you must set the
# "REMOTE_USER" environment variable to be the name of the user you're
# "authenticated" as.
WORKINGDIR="$( cd "$( dirname "$0" )" && pwd )"
source "$WORKINGDIR/settings.sh"
METHOD="GET"
OK="OK"
FAIL="FAIL!"
DEBUG=0
helpstr="Usage: $0 -h <host> [-h <host>] [-H <hours>] [-m <minutes>]
-h <host> - The host you want to put into downtime.
-H <hours> - The number of hours you want the host(s) in downtime for [Default = 1].
-m <minutes> - The number of minutes you want the host(s) in downtime for. [Default = 0].
-S <Start Date> - The number of minutes you want the host(s) in downtime for. [Default = 0].
-E <End Date> - The number of minutes you want the host(s) in downtime for. [Default = 0].
-f - Used fix time (must use -S, -E).
"
hosts=""
hour=1
minute=0
num_hosts=0
sdate=""
edate=""
FIXED=0
while getopts "h:H:m:S:E:f" option
do
case $option in
h) hosts="$hosts $OPTARG"
let "num_hosts+=1";;
H) hour=$OPTARG;;
m) minute=$OPTARG;;
S) sdate=$OPTARG;;
E) edate=$OPTARG;;
f) FIXED=1;;
\?) echo "$helpstr"
exit 3;;
esac
done
if [ $num_hosts -eq 0 ]
then
echo "$helpstr"
exit 3
fi
export REQUEST_METHOD="$METHOD"
export REMOTE_USER="$USER"
if [ $FIXED -eq 1 ]
then
startdate="`date +"%m-%d-%Y+%H%%3A%M%%3A%S" -d"$sdate"`"
enddate="`date +"%m-%d-%Y+%H%%3A%M%%3A%S" -d"$edate"`"
else
startdate="`date +"%m-%d-%Y+%H%%3A%M%%3A%S"`"
enddate="`date +"%m-%d-%Y+%H%%3A%M%%3A%S" -d"now +$hour hours +$minute minute"`"
fi
for host in $hosts
do
echo -n "Putting '$host' into downtime for $hour:$minute (h:m)....."
#Put the host into downtime
export QUERY_STRING="cmd_typ=55&cmd_mod=2&host=$host&com_data=Put+into+downtime+by+blah&trigger=0&start_time=$startdate&end_time=$enddate&fixed=$FIXED&hours=$hour&minutes=$minute&childoptions=0&btnSubmit=Commit"
$NAGIOS_CMD &> /dev/null
if [ $DEBUG -eq 1 ]
then
echo $QUERY_STRING
fi
if [ $? -gt 0 ]
then
echo $FAIL
else
echo $OK
fi
echo -n "Putting all services on '$host' into downtime for $hour:$minute (h:m)....."
#Put all the services for the host into downtime.
export QUERY_STRING="cmd_typ=86&cmd_mod=2&host=$host&com_data=Put+into+downtime+by+blah&trigger=0&start_time=$startdate&end_time=$enddate&fixed=$FIXED&hours=$hour&minutes=$minute&btnSubmit=Commit"
$NAGIOS_CMD %> /dev/null
if [ $DEBUG -eq 1 ]
then
echo $QUERY_STRING
fi
if [ $? -gt 0 ]
then
echo $FAIL
else
echo $OK
fi
done