sched_downtime.pl 956 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #! /usr/bin/perl -w
  2. #
  3. # Marko Riedel, EDV Neue Arbeit gGmbH, mriedel@neuearbeit.de
  4. #
  5. #
  6. #
  7. #
  8. use POSIX qw(strtol);
  9. my $command_file = '/usr/local/nagios/var/rw/nagios.cmd';
  10. my $hour = (60*60);
  11. my $next_day = (24*60*60);
  12. my $downtimes =
  13. [
  14. {
  15. host => 'somehost',
  16. service => 'SERVICE',
  17. times => [ ["00:00", 9], ["18:00", 6] ]
  18. }
  19. ];
  20. foreach my $entry (@$downtimes) {
  21. my ($secstart, $secend, $cmd, $current);
  22. $current = `/bin/date +"%s"`;
  23. chomp $current;
  24. foreach my $tperiod (@{ $entry->{times} }){
  25. $secstart = strtol(`/bin/date -d "$tperiod->[0]" +"%s"`);
  26. $secend = $secstart+$tperiod->[1]*$hour;
  27. $secstart += $next_day;
  28. $secend += $next_day;
  29. $cmd = "[$current] SCHEDULE_SVC_DOWNTIME;";
  30. $cmd .= "$entry->{host};$entry->{service};";
  31. $cmd .= "$secstart;$secend;";
  32. $cmd .= "1;0;$0;automatically scheduled;\n";
  33. print STDERR $cmd;
  34. system "echo \"$cmd\" >> $command_file";
  35. }
  36. }