From 70d51413c932a00a30b4de5d1bb26cb8bc3410a3 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Thu, 2 Jan 2020 15:46:27 +0100 Subject: [PATCH] timelocal to strftime --- pandora_server/lib/PandoraFMS/Core.pm | 8 +++++--- pandora_server/lib/PandoraFMS/DataServer.pm | 4 ++-- pandora_server/lib/PandoraFMS/PluginTools.pm | 2 +- pandora_server/lib/PandoraFMS/Tools.pm | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 21a84956eb..bd353fa753 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -118,7 +118,7 @@ use XML::Simple; use HTML::Entities; use Time::Local; use Time::HiRes qw(time); -use POSIX qw(strftime); +use POSIX qw(strftime floor); use threads; use threads::shared; use JSON qw(decode_json encode_json); @@ -1660,7 +1660,9 @@ sub pandora_process_module ($$$$$$$$$;$) { pandora_update_module_on_error ($pa_config, $module, $dbh); return; } - my $last_try = ($1 == 0) ? 0 : timelocal($6, $5, $4, $3, $2 - 1, $1 - 1900); + + my $last_try = ($1 == 0) ? 0 : strftime("%s", $6, $5, $4, $3, $2 - 1, $1 - 1900); + my $save = ($module->{'history_data'} == 1 && ($agent_status->{'datos'} ne $processed_data || $last_try < ($utimestamp - 86400))) ? 1 : 0; # Received stale data. Save module data if needed and return. @@ -3823,7 +3825,7 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$$) { # Check time threshold $alert->{'last_fired'} = '1970-01-01 00:00:00' unless defined ($alert->{'last_fired'}); return unless ($alert->{'last_fired'} =~ /(\d+)\-(\d+)\-(\d+) +(\d+):(\d+):(\d+)/); - my $last_fired = ($1 > 0) ? timelocal($6, $5, $4, $3, $2 - 1, $1 - 1900) : 0; + my $last_fired = ($1 > 0) ? strftime("%s", $6, $5, $4, $3, $2 - 1, $1 - 1900) : 0; my $utimestamp = time (); my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime($utimestamp)); diff --git a/pandora_server/lib/PandoraFMS/DataServer.pm b/pandora_server/lib/PandoraFMS/DataServer.pm index 38a33fc263..14b27964fc 100644 --- a/pandora_server/lib/PandoraFMS/DataServer.pm +++ b/pandora_server/lib/PandoraFMS/DataServer.pm @@ -309,7 +309,7 @@ sub process_xml_data ($$$$$) { my $utimestamp = 0; eval { if ($timestamp =~ /(\d+)[\/|\-](\d+)[\/|\-](\d+) +(\d+):(\d+):(\d+)/) { - $utimestamp = timelocal($6, $5, $4, $3, $2 -1 , $1 - 1900); + $utimestamp = strftime("%s", $6, $5, $4, $3, $2 -1 , $1 - 1900); } }; @@ -837,7 +837,7 @@ sub process_module_data ($$$$$$$$$$) { } my $utimestamp; eval { - $utimestamp = timelocal($6, $5, $4, $3, $2 - 1, $1 - 1900); + $utimestamp = strftime("%s", $6, $5, $4, $3, $2 - 1, $1 - 1900); }; if ($@) { logger($pa_config, "Invalid timestamp '$timestamp' from module '$module_name' agent '$agent_name'.", 3); diff --git a/pandora_server/lib/PandoraFMS/PluginTools.pm b/pandora_server/lib/PandoraFMS/PluginTools.pm index 36ce54b116..e21adbf231 100644 --- a/pandora_server/lib/PandoraFMS/PluginTools.pm +++ b/pandora_server/lib/PandoraFMS/PluginTools.pm @@ -2382,7 +2382,7 @@ sub get_unix_time { eval { use Time::Local; my ($mday,$mon,$year,$hour,$min,$sec) = split(/[\s$separator_dates$separator_hours]+/, $str_time); - $time = timelocal($sec,$min,$hour,$mday,$mon-1,$year); + $time = strftime("%s", $sec,$min,$hour,$mday,$mon-1,$year); }; if ($@) { return 0; diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index a2a7e2b174..7736a6f31b 100755 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -1734,7 +1734,7 @@ sub cron_valid_date { my $utime; eval { local $SIG{__DIE__} = sub {}; - $utime = timelocal(0, $min, $hour, $mday, $month, $year); + $utime = strftime("%s", 0, $min, $hour, $mday, $month, $year); }; if ($@) { return 0;