diff --git a/centreon-plugins/apps/antivirus/kaspersky/snmp/mode/updates.pm b/centreon-plugins/apps/antivirus/kaspersky/snmp/mode/updates.pm index 51aa71ed4..d60471cfc 100644 --- a/centreon-plugins/apps/antivirus/kaspersky/snmp/mode/updates.pm +++ b/centreon-plugins/apps/antivirus/kaspersky/snmp/mode/updates.pm @@ -24,6 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use centreon::plugins::misc; use DateTime; my $instance_mode; @@ -104,7 +105,7 @@ sub custom_last_calc { hour => $4, minute => $5, second => $6, - time_zone => $instance_mode->{option_results}->{timezone}, + %{$self->{tz}} ); $self->{result_values}->{diff} = time() - $dt->epoch; $self->{result_values}->{date_time} = $dt->datetime(); @@ -177,6 +178,7 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); + $self->{tz} = centreon::plugins::misc::set_timezone(name => $self->{option_results}->{timezone}); $instance_mode = $self; $self->change_macros(); } diff --git a/centreon-plugins/apps/backup/tsm/local/mode/actlog.pm b/centreon-plugins/apps/backup/tsm/local/mode/actlog.pm index f5017724c..b673be5d7 100644 --- a/centreon-plugins/apps/backup/tsm/local/mode/actlog.pm +++ b/centreon-plugins/apps/backup/tsm/local/mode/actlog.pm @@ -152,12 +152,13 @@ sub manage_selection { my %map_severity = (E => 'error', W => 'warning', I => 'information', S => 'severe', K => 'kernel'); my ($i, $current_time) = (1, time()); #2017-09-19 12:08:14.000000,I,"ANR1283I File count is incorrect fo..." + + my $tz = centreon::plugins::misc::set_timezone(name => $self->{option_results}->{timezone}); while ($response =~ /^(.*?),(.*?),(.*)$/mg) { my ($date, $severity, $message) = ($1, $2, $3); $date =~ /^(\d+)-(\d+)-(\d+)\s+(\d+)[:\/](\d+)[:\/](\d+)/; - my $dt = DateTime->new(year => $1, month => $2, day => $3, hour => $4, minute => $5, second => $6, - time_zone => $self->{option_results}->{timezone}); + my $dt = DateTime->new(year => $1, month => $2, day => $3, hour => $4, minute => $5, second => $6, %$tz); next if (defined($self->{option_results}->{memory}) && defined($last_time) && $last_time > $dt->epoch); diff --git a/centreon-plugins/apps/backup/tsm/local/mode/sessions.pm b/centreon-plugins/apps/backup/tsm/local/mode/sessions.pm index c08f24477..9db693310 100644 --- a/centreon-plugins/apps/backup/tsm/local/mode/sessions.pm +++ b/centreon-plugins/apps/backup/tsm/local/mode/sessions.pm @@ -161,12 +161,12 @@ sub manage_selection { $self->{sessions} = {}; $self->{global} = { total => 0 }; + my $tz = centreon::plugins::misc::set_timezone(name => $self->{option_results}->{timezone}); while ($response =~ /^(.*?),(.*?),(.*?),(.*?),(.*?)$/mg) { my ($session_id, $client_name, $start_time, $state, $session_type) = ($1, $2, $3, $4, $5); $start_time =~ /^(\d+)-(\d+)-(\d+)\s+(\d+)[:\/](\d+)[:\/](\d+)/; - my $dt = DateTime->new(year => $1, month => $2, day => $3, hour => $4, minute => $5, second => $6, - time_zone => $self->{option_results}->{timezone}); + my $dt = DateTime->new(year => $1, month => $2, day => $3, hour => $4, minute => $5, second => $6, %$tz); if (defined($self->{option_results}->{filter_clientname}) && $self->{option_results}->{filter_clientname} ne '' && $client_name !~ /$self->{option_results}->{filter_clientname}/) { diff --git a/centreon-plugins/apps/java/awa/jmx/mode/agent.pm b/centreon-plugins/apps/java/awa/jmx/mode/agent.pm index 98e09e62d..e71db64f6 100644 --- a/centreon-plugins/apps/java/awa/jmx/mode/agent.pm +++ b/centreon-plugins/apps/java/awa/jmx/mode/agent.pm @@ -142,7 +142,8 @@ sub manage_selection { { name => 'Active' }, { name => 'Name' } ] }, ]; my $result = $options{custom}->get_attributes(request => $self->{request}, nothing_quit => 1); - + my $tz = centreon::plugins::misc::set_timezone(name => $self->{option_results}->{timezone}); + foreach my $mbean (keys %{$result}) { $mbean =~ /name=(.*?)(,|$)/i; my $name = $1; @@ -164,7 +165,7 @@ sub manage_selection { hour => $4, minute => $5, second => $6, - time_zone => $self->{option_results}->{timezone}, + %$tz ); $self->{agent}->{$display} = { diff --git a/centreon-plugins/apps/protocols/ftp/mode/date.pm b/centreon-plugins/apps/protocols/ftp/mode/date.pm index 85a2d00cf..30b455b1c 100644 --- a/centreon-plugins/apps/protocols/ftp/mode/date.pm +++ b/centreon-plugins/apps/protocols/ftp/mode/date.pm @@ -24,6 +24,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; +use centreon::plugins::misc; use apps::protocols::ftp::lib::ftp; # How much arguments i need and commands manages @@ -133,6 +134,7 @@ sub run { $self->{output}->output_add(severity => 'OK', short_msg => "All file times are ok."); + my $tz = centreon::plugins::misc::set_timezone(name => $self->{option_results}->{timezone}); foreach my $name (sort keys %file_times) { my $diff_time = $current_time - $file_times{$name}; @@ -140,7 +142,7 @@ sub run { threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); my $display_date = scalar(localtime($file_times{$name})); if (defined($self->{option_results}->{timezone}) && $self->{option_results}->{timezone} ne '') { - $display_date = DateTime->from_epoch(epoch => $file_times{$name}, time_zone => $self->{option_results}->{timezone})->datetime() + $display_date = DateTime->from_epoch(epoch => $file_times{$name}, %$tz)->datetime() } $self->{output}->output_add(long_msg => sprintf("%s: %s seconds (time: %s)", $name, $diff_time, $display_date)); diff --git a/centreon-plugins/apps/toshiba/storemate/sql/mode/maintenanceplan.pm b/centreon-plugins/apps/toshiba/storemate/sql/mode/maintenanceplan.pm index 1a107f40b..484758e79 100644 --- a/centreon-plugins/apps/toshiba/storemate/sql/mode/maintenanceplan.pm +++ b/centreon-plugins/apps/toshiba/storemate/sql/mode/maintenanceplan.pm @@ -152,6 +152,7 @@ sub manage_selection { } my ($i, $current_time) = (1, time()); + my $tz = centreon::plugins::misc::set_timezone(name => $self->{option_results}->{timezone})); while (my $row = $self->{sql}->fetchrow_hashref()) { # date form: 2017-09-22 01:01:08.133 $row->{LOGDATE} =~ /^(\d+)-(\d+)-(\d+)\s+(\d+)[:\/](\d+)[:\/](\d+)/; diff --git a/centreon-plugins/centreon/plugins/misc.pm b/centreon-plugins/centreon/plugins/misc.pm index faee2d8dc..927ae26ec 100644 --- a/centreon-plugins/centreon/plugins/misc.pm +++ b/centreon-plugins/centreon/plugins/misc.pm @@ -480,6 +480,24 @@ sub get_threshold_litteral { return $perf_output; } +sub set_timezone { + my (%options) = @_; + + return {} if (!defined($options{name}) || $options{name} eq ''); + + centreon::plugins::misc::mymodule_load(output => $options{output}, module => 'DateTime::TimeZone', + error_msg => "Cannot load module 'DateTime::TimeZone'."); + if (DateTime::TimeZone->is_valid_name($options{name})) { + return { time_zone => DateTime::TimeZone->new(name => $options{name}) }; + } + + centreon::plugins::misc::mymodule_load(output => $options{output}, module => 'POSIX', + error_msg => "Cannot load module 'POSIX'."); + $ENV{TZ} = $options{name}; + POSIX::tzset(); + return {}; +} + 1; __END__ diff --git a/centreon-plugins/hardware/server/ibm/mgmt_cards/imm/snmp/mode/eventlog.pm b/centreon-plugins/hardware/server/ibm/mgmt_cards/imm/snmp/mode/eventlog.pm index 0e14db77c..2f8a41b06 100644 --- a/centreon-plugins/hardware/server/ibm/mgmt_cards/imm/snmp/mode/eventlog.pm +++ b/centreon-plugins/hardware/server/ibm/mgmt_cards/imm/snmp/mode/eventlog.pm @@ -159,6 +159,7 @@ sub manage_selection { } my ($i, $current_time) = (1, time()); + my $tz = centreon::plugins::misc::set_timezone(name => $self->{option_results}->{timezone}); foreach my $oid (keys %{$snmp_result}) { next if ($oid !~ /^$mapping->{eventLogSeverity}->{oid}\.(.*)$/); my $instance = $1; @@ -167,8 +168,7 @@ sub manage_selection { my $date = $result->{eventLogDate} . ' ' . $result->{eventLogTime}; $date =~ /^(\d+)\/(\d+)\/(\d+)\s+(\d+)[:\/](\d+)[:\/](\d+)/; - my $dt = DateTime->new(year => $3, month => $1, day => $2, hour => $4, minute => $5, second => $6, - time_zone => $self->{option_results}->{timezone}); + my $dt = DateTime->new(year => $3, month => $1, day => $2, hour => $4, minute => $5, second => $6, %$tz); next if (defined($self->{option_results}->{memory}) && defined($last_time) && $last_time > $dt->epoch); diff --git a/centreon-plugins/network/adva/fsp3000/snmp/mode/alarms.pm b/centreon-plugins/network/adva/fsp3000/snmp/mode/alarms.pm index 038a627f8..a519a015d 100644 --- a/centreon-plugins/network/adva/fsp3000/snmp/mode/alarms.pm +++ b/centreon-plugins/network/adva/fsp3000/snmp/mode/alarms.pm @@ -303,8 +303,9 @@ sub manage_selection { $timezone = sprintf("%s%02d%02d", $date[7], $date[8], $date[9]); } + my $tz = centreon::plugins::misc::set_timezone(name => $timezone); my $dt = DateTime->new(year => $date[0], month => $date[1], day => $date[2], hour => $date[3], minute => $date[4], second => $date[5], - time_zone => $timezone); + %$tz); next if (defined($self->{option_results}->{memory}) && defined($last_time) && $last_time > $dt->epoch); diff --git a/centreon-plugins/snmp_standard/mode/ntp.pm b/centreon-plugins/snmp_standard/mode/ntp.pm index f84aa1ead..7deabd372 100644 --- a/centreon-plugins/snmp_standard/mode/ntp.pm +++ b/centreon-plugins/snmp_standard/mode/ntp.pm @@ -101,6 +101,7 @@ sub run { $timezone = sprintf("%s%02d%02d", $remote_date[7], $remote_date[8], $remote_date[9]); # format +0630 } + my $tz = centreon::plugins::misc::set_timezone(name => $timezone); my $dt = DateTime->new( year => $remote_date[0], month => $remote_date[1], @@ -108,7 +109,7 @@ sub run { hour => $remote_date[3], minute => $remote_date[4], second => $remote_date[5], - time_zone => $timezone, + %$tz ); $distant_time = $dt->epoch; diff --git a/centreon-plugins/storage/dell/compellent/local/mode/hbausage.pm b/centreon-plugins/storage/dell/compellent/local/mode/hbausage.pm index 2200253b9..de34fd448 100644 --- a/centreon-plugins/storage/dell/compellent/local/mode/hbausage.pm +++ b/centreon-plugins/storage/dell/compellent/local/mode/hbausage.pm @@ -150,7 +150,7 @@ sub parse_date { } my $dt = DateTime->new(year => $1, month => $2, day => $3, hour => $4, minute => $5, second => $6, - time_zone => $self->{option_results}->{timezone}); + %{$self->{tz}}); return $dt; } @@ -169,10 +169,11 @@ sub check_options { } my ($dt_start, $dt_end); + $self->{tz} = centreon::plugins::misc::set_timezone(name => $self->{option_results}->{timezone}); if (defined($self->{option_results}->{end_time}) && $self->{option_results}->{end_time} ne '') { $dt_end = $self->parse_date(date => $self->{option_results}->{end_time}); } else { - $dt_end = DateTime->now(time_zone => $self->{option_results}->{timezone}); + $dt_end = DateTime->now(%{$self->{tz}}); } $self->{end_time} = $self->get_iso8601(date => $dt_end); @@ -315,4 +316,4 @@ Can be: 'read-iops', 'read-usage', 'read-latency', =back -=cut \ No newline at end of file +=cut diff --git a/centreon-plugins/storage/purestorage/restapi/mode/pgroupreplication.pm b/centreon-plugins/storage/purestorage/restapi/mode/pgroupreplication.pm index 83659014c..8acb9648f 100644 --- a/centreon-plugins/storage/purestorage/restapi/mode/pgroupreplication.pm +++ b/centreon-plugins/storage/purestorage/restapi/mode/pgroupreplication.pm @@ -118,6 +118,7 @@ sub manage_selection { # {"name": "prod:PROD-SQL-SERVER.6620", "created": "2018-10-15T13:05:06Z", "started": "2018-10-15T13:05:06Z", "completed": "2018-10-15T13:05:53Z", "physical_bytes_written": 4183179644, "source": "prod:PROD-SQL-SERVER", "progress": 1.0, "data_transferred": 4609709762} # ... #] + my $tz = centreon::plugins::misc::set_timezone(name => $self->{option_results}->{timezone}); foreach my $entry (@{$result}) { next if ($entry->{name} !~ /(.*)\.[0-9]+$/); my $pgroup_name = $1; @@ -129,16 +130,14 @@ sub manage_selection { } $entry->{created} =~ /^(\d+)-(\d+)-(\d+)T(\d+)[:\/](\d+)[:\/](\d+)Z$/; - my $dt = DateTime->new(year => $1, month => $2, day => $3, hour => $4, minute => $5, second => $6, - time_zone => $self->{option_results}->{timezone}); + my $dt = DateTime->new(year => $1, month => $2, day => $3, hour => $4, minute => $5, second => $6, %tz); my $created_time = $dt->epoch; my $creation_seconds = time() - $created_time; next if (defined($self->{pgroup}->{$pgroup_name}->{creation_seconds}) && $creation_seconds > $self->{pgroup}->{$pgroup_name}->{creation_seconds}); $entry->{completed} =~ /^(\d+)-(\d+)-(\d+)T(\d+)[:\/](\d+)[:\/](\d+)Z$/; - $dt = DateTime->new(year => $1, month => $2, day => $3, hour => $4, minute => $5, second => $6, - time_zone => $self->{option_results}->{timezone}); + $dt = DateTime->new(year => $1, month => $2, day => $3, hour => $4, minute => $5, second => $6, %$tz); my $completed_time = $dt->epoch; $self->{pgroup}->{$pgroup_name} = {