From 733e076bb91606bd6ababf828b2693ca9fefbf9a Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sat, 31 May 2014 22:32:41 +0200 Subject: support downtime scheduling still needs some polishing, this will follow later --- bin/icli | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 95 insertions(+), 10 deletions(-) (limited to 'bin') diff --git a/bin/icli b/bin/icli index cf8f93a..c28b413 100755 --- a/bin/icli +++ b/bin/icli @@ -10,6 +10,8 @@ no if $] >= 5.018, warnings => 'experimental::smartmatch'; use App::Icli::ConfigData; use Carp qw(croak); +use DateTime; +use DateTime::Format::Strptime; use Getopt::Long qw/:config bundling/; use List::MoreUtils qw(any firstval); use POSIX qw(strftime); @@ -440,13 +442,17 @@ sub parse_action { return; } + my @raw_args; + my %actionmap = ( a => 'acknowledge', + d => 'downtime', r => 'recheck', R => 'force_recheck', ); - ( $action, @action_args ) = split( /:/, $action ); + ( $action, @raw_args ) = split( /:/, $action ); + @action_args = split( /,/, join( ':', @raw_args ) ); $list_type = q{}; if ( exists $actionmap{$action} ) { @@ -943,12 +949,41 @@ sub action_on_host { my ($host) = @_; given ($action) { + when ('downtime') { + my ( $start, $end, $duration, $comment, @opts ) = @action_args; + my $strp = DateTime::Format::Strptime->new( + pattern => '%Y-%m-%dT%H:%M:%S', + time_zone => 'Europe/Berlin', # TODO read from system + ); + + my $dt_start = $strp->parse_datetime($start); + my $dt_end = $strp->parse_datetime($end); + my $fixed = $duration ? 0 : 1; + my $command = 'SCHEDULE_HOST_DOWNTIME'; + my $addendum = q{}; + + $duration *= 3600; + + if ( 'children' ~~ \@opts ) { + $command = 'SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME'; + $addendum = ' and its children'; + } + if ( 'trigger_children' ~~ \@opts ) { + $command = 'SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME'; + $addendum = ' and its children (triggered)'; + } + + dispatch_command( $command, $host, $dt_start->epoch, $dt_end->epoch, + $fixed, 0, $duration, 'cli', $comment ); + say "Scheduled host downtime for '$host'$addendum"; + } when ('recheck') { dispatch_command( 'SCHEDULE_HOST_SVC_CHECKS', $host, time() ); say "Scheduled check of * on '$host'"; } when ('force_recheck') { - dispatch_command( 'SCHEDULE_FORCED_HOST_SVC_CHECKS', $host, time() ); + dispatch_command( 'SCHEDULE_FORCED_HOST_SVC_CHECKS', $host, + time() ); say "Scheduled forced check of * on '$host'"; } default { @@ -965,17 +1000,36 @@ sub action_on_service { } given ($action) { + when ('downtime') { + my ( $start, $end, $duration, $comment, @opts ) = @action_args; + my $strp = DateTime::Format::Strptime->new( + pattern => '%Y-%m-%dT%H:%M:%S', + time_zone => 'Europe/Berlin', # TODO read from system + ); + + my $dt_start = $strp->parse_datetime($start); + my $dt_end = $strp->parse_datetime($end); + my $fixed = $duration ? 0 : 1; + + $duration *= 3600; + + dispatch_command( 'SCHEDULE_SVC_DOWNTIME', $host, $service, + $dt_start->epoch, $dt_end->epoch, + $fixed, 0, $duration, 'cli', $comment ); + say "Scheduled service downtime for '$service' on '$host'"; + } when ('recheck') { dispatch_command( 'SCHEDULE_SVC_CHECK', $host, $service, time() ); say "Scheduled check of '$service' on '$host'"; } when ('force_recheck') { - dispatch_command( 'SCHEDULE_FORCED_SVC_CHECK', $host, $service, time() ); + dispatch_command( 'SCHEDULE_FORCED_SVC_CHECK', $host, $service, + time() ); say "Scheduled forced check of '$service' on '$host'"; } when ('Acknowledge') { - dispatch_command( 'ACKNOWLEDGE_SVC_PROBLEM', $host, $service, 2, 1, 1, - 'cli', $action_args[0] ); + dispatch_command( 'ACKNOWLEDGE_SVC_PROBLEM', $host, $service, 2, 1, + 1, 'cli', $action_args[0] ); say "Acknowledged $host/$service: $action_args[0]"; } default { @@ -1096,9 +1150,9 @@ aneurysm/{Libraries,Websites} >> with shell expansion). =item B<-a>|B<--action> I[:I] -Run I on all matching services. I is a colon-separated list of -action arguments and depends on the action in question. I may also be -a one or two letter shortcut. +Run I on all matching hosts or services. I is a comma-separated +list of action arguments and depends on the action in question. I may +also be a one or two letter shortcut. The following actions are supported: @@ -1112,6 +1166,26 @@ persistent. Note: Acknowledgement of host problems is not yet supported. +=item d|downtime I,I,I,I[,I] + +Schedule a non-triggered host or service (depending on the filter arguments) +downtime. I and I are timestamps and must be formatted as +YYYY-MM-DDTHH:MM:SS, where the "T" is literal. At this moment, they are always +interpreted in the Europe/Berlin timezone, this will change in the future. + +If I is 0 (zero), a fixed downtime between I and I +is scheduled. Otherwise, a flexible downtime which will start between +I and I and last I hours is scheduled. I +may be a float. + +If a host is selected and I contains "children", a downtime for all of +its children will be scheduled with the same parameters as the host's. +Likewise, if I contains "trigger_children", a triggered downtime for all +of the host's children will be scheduled. + +I refers to the downtime's comment field and must not contain the +"," (comma) character. + =item r|recheck Schedule an immediate recheck @@ -1333,14 +1407,25 @@ None. =item * autodie (included with perl >= 5.10.1) +=item * DateTime + +=item * DateTime::Format::Strptime + =item * Term::Size =back =head1 BUGS AND LIMITATIONS -This software is in early development stages. So there will probably be quite -a lot. +When scheduling a downtime, the start and stop times are always interpreted +in the Europe/Berlin timezone. Also, the duration parameter is always +interpreted in hours. + +It is probably not clear from the documentation when an action will operate +on hosts and when on services. + +Note that this software is not yet stable. Command line options may be changed +/ removed and thus break backwards compatibility at any time. =head2 REPORTING BUGS -- cgit v1.2.3