From aa86dd2d9cd15b2cccf0aa0285139aa56cd33f18 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 13 Jun 2014 20:12:32 +0200 Subject: Determine system timezone using DateTime::Timezone --- Build.PL | 1 + Changelog | 2 +- README | 1 + bin/icli | 19 +++++++++++-------- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Build.PL b/Build.PL index 176314d..62105b6 100644 --- a/Build.PL +++ b/Build.PL @@ -41,6 +41,7 @@ my $build = Module::Build->new( 'Carp' => 0, 'DateTime' => 0, 'DateTime::Format::Strptime' => 0, + 'DateTime::TimeZone' => 0, 'Getopt::Long' => 0, 'List::MoreUtils' => 0, 'POSIX' => 0, diff --git a/Changelog b/Changelog index 5885f83..efbac97 100644 --- a/Changelog +++ b/Changelog @@ -1,6 +1,6 @@ git HEAD - * New dependencies: DateTime and DateTime::Format::Strptime + * New dependencies: DateTime, DateTime::Format::Strptime, DateTime::TimeZone * NOT BACKWARDS COMPATIBLE: Add -a/--action option to invoke generic actions on selected services. This replaces -a/--acknowledge with -aa/ -a acknowledge, -r/--recheck with -ar / -a recheck and diff --git a/README b/README index a8eaf1f..84bf42f 100644 --- a/README +++ b/README @@ -5,6 +5,7 @@ Requires: * perl v5.10 or newer with the following modules: * DateTime * DateTime::Format::Strptime + * DateTime::TimeZone * List::MoreUtils * Term::Size diff --git a/bin/icli b/bin/icli index abcab3a..414c3de 100755 --- a/bin/icli +++ b/bin/icli @@ -12,6 +12,7 @@ use App::Icli::ConfigData; use Carp qw(croak); use DateTime; use DateTime::Format::Strptime; +use DateTime::TimeZone; use Getopt::Long qw/:config bundling/; use List::MoreUtils qw(any firstval); use POSIX qw(strftime); @@ -1044,12 +1045,14 @@ sub dispatch_command { sub action_on_host { my ($host) = @_; + my $tz = DateTime::TimeZone->new( name => 'local' ); + 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 + time_zone => $tz->name, ); my $dt_start = $strp->parse_datetime($start); @@ -1095,12 +1098,14 @@ sub action_on_service { return; } + my $tz = DateTime::TimeZone->new( name => 'local' ); + 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 + time_zone => $tz->name, ); my $dt_start = $strp->parse_datetime($start); @@ -1296,8 +1301,8 @@ Note: Acknowledgement of host problems is not yet supported. 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. +YYYY-MM-DDTHH:MM:SS, where the "T" is literal. The timestamp is assumed to +be in the same time zone as the system running icli. If I is 0 (zero), a fixed downtime between I and I is scheduled. Otherwise, a flexible downtime which will start between @@ -1539,16 +1544,14 @@ None. =item * DateTime::Format::Strptime +=item * DateTime::TimeZone + =item * Term::Size =back =head1 BUGS AND LIMITATIONS -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. -- cgit v1.2.3