#!/bin/sh

# Write a command to the Nagios command file to cause
# it to schedule downtime for a host

# Based on ../nagios/contrib/eventhandlers/disable_notifications by Ethan Galstad.
#
# Rev: Tue Nov  4 09:30:16 2003  (amen@tashtego.west.ora.com)

Host=$1

Duration=$[$2*60]

User=`/usr/bin/id -un`

Comment="Autogenerated downtime"

echocmd="/bin/echo"

CommandFile="/usr/local/nagios/var/rw/nagios.cmd"

# get the current date/time in seconds since UNIX epoch
datetime=`date +%s`

Start=$datetime

End=$[$Start+$Duration]

# create the command line to add to the command file
cmdline="[$datetime] SCHEDULE_HOST_DOWNTIME;$Host;$Start;$End;1;$Duration;$User;$Comment"

# append the command to the end of the command file
#$echocmd $cmdline
$echocmd $cmdline >> $CommandFile

