#!/usr/bin/perl

# this is a generic producer of downtime notification for a service
#  from now+x minutes to now+y minutes
#
#  (c) Gatekeeper Technology Ltd. 2009, 2010
#
#  Made available under the GPLv3

use Time::Local ;

$timenow = time() ;
@timenow = localtime($timenow) ;

$host		= shift @ARGV;
$service	= shift @ARGV;
$startmin	= shift @ARGV;
$endmin		= shift @ARGV;
$reason		= shift @ARGV;

if ( not ( defined($host) && defined($service) && defined($startmin) && defined($endmin) && defined($reason) ) ) {
  print "Usage: $0 host service startmin endmin reason\n" ;
  print "\n" ;
  print "   emits a line suitable for feeding to nagios' RW file, booking downtime\n" ;
  print "   for service running on host, from startmin minutes in the future to\n" ;
  print "   endmin minutes in the future, giving reason.\n" ;
  print "\n" ;
  exit 1 ;
}

$start = $timenow + 60*$startmin ;
$stop  = $timenow + 60*$endmin ;

print "[$timenow] SCHEDULE_SVC_DOWNTIME;$host;$service;$start;$stop;1;0;7200;ty3212;CRON-based downtime: $reason\n" ;

exit 0 ;
