44 lines
1 KiB
Bash
44 lines
1 KiB
Bash
#!/usr/bin/env bash
|
|
#
|
|
# Schedule a custom downtime
|
|
|
|
icinga_user="FIXME"
|
|
icinga_pw="FIXME"
|
|
cgi_path="https://example.org/icinga/cgi-bin/cmd.cgi?"
|
|
commandfile='/var/spool/icinga/cmd/icinga.cmd'
|
|
|
|
if [ -z $1 ]; then $0 -h; exit 1; fi
|
|
|
|
while getopts ":s:d:h" opt; do
|
|
case $opt in
|
|
s)
|
|
tmp=$(echo "$OPTARG" | sed 's/,/ /g')
|
|
vm=($tmp) # convert $tmp to array
|
|
;;
|
|
d)
|
|
duration=$OPTARG
|
|
;;
|
|
h)
|
|
echo "Usage: $(basename $0) -s VM1[,VM2] -d DURATION IN SECONDS"
|
|
exit 0
|
|
;;
|
|
\?)
|
|
echo "Invalid option: -$OPTARG" >&2
|
|
exit 1
|
|
;;
|
|
:)
|
|
echo "Option -$OPTARG requires an argument." >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
now=$(date +%s)
|
|
now_h=$(date -d @$now +"%m-%d-%Y %H:%M:%S")
|
|
to=$(($now+$duration))
|
|
to_h=$(date -d @$to +"%m-%d-%Y %H:%M:%S")
|
|
|
|
for system in "${vm[@]}"; do
|
|
url="fixed=1&cmd_typ=86&cmd_mod=2&start_time=$now_h&end_time=$to_h&host=$system&com_author=FIXME&com_data=Automated%20downtime&btnSubmit=Commit"
|
|
$(which curl) -v -u "$icinga_user":"$icinga_pw" "$cgi_path" -d "$url"
|
|
done
|