diff --git a/pandora_console/extras/mr/61.sql b/pandora_console/extras/mr/61.sql new file mode 100644 index 0000000000..8cff0d2944 --- /dev/null +++ b/pandora_console/extras/mr/61.sql @@ -0,0 +1,5 @@ +START TRANSACTION; + +ALTER TABLE `tserver` ADD COLUMN `server_keepalive_utimestamp` BIGINT NOT NULL DEFAULT 0; + +COMMIT; diff --git a/pandora_console/godmode/servers/servers.build_table.php b/pandora_console/godmode/servers/servers.build_table.php index 9629dccb22..a82933f640 100644 --- a/pandora_console/godmode/servers/servers.build_table.php +++ b/pandora_console/godmode/servers/servers.build_table.php @@ -110,6 +110,12 @@ foreach ($servers as $server) { ]; $data[0] = ''.strip_tags($server['name']).''; + $server_keepalive = time_w_fixed_tz($server['keepalive']); + + if ($server['server_keepalive_utimestamp'] > 0) { + $server_keepalive = $server['server_keepalive_utimestamp']; + } + // Status. $data[1] = ui_print_status_image(STATUS_SERVER_OK, '', true); if ($server['status'] == -1) { @@ -119,7 +125,7 @@ foreach ($servers as $server) { true ); } else if ((int) ($server['status'] === 0) - || (($date - time_w_fixed_tz($server['keepalive'])) > ($server['server_keepalive']) * 2) + || (($date - $server_keepalive) > ($server['server_keepalive']) * 2) ) { $data[1] = ui_print_status_image( STATUS_SERVER_DOWN, diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 3f90f157f8..c45758affe 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -1157,6 +1157,7 @@ CREATE TABLE IF NOT EXISTS `tserver` ( `stat_utimestamp` BIGINT NOT NULL DEFAULT 0, `exec_proxy` TINYINT UNSIGNED NOT NULL DEFAULT 0, `port` INT UNSIGNED NOT NULL DEFAULT 0, + `server_keepalive_utimestamp` BIGINT NOT NULL DEFAULT 0, PRIMARY KEY (`id_server`), KEY `name` (`name`) ) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 899254d02c..d33445a2fa 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -118,7 +118,7 @@ use Tie::File; use Time::Local; use Time::HiRes qw(time); eval "use POSIX::strftime::GNU;1" if ($^O =~ /win/i); -use POSIX qw(strftime); +use POSIX qw(strftime mktime); use threads; use threads::shared; use JSON qw(decode_json encode_json); @@ -3173,16 +3173,20 @@ sub pandora_update_server ($$$$$$;$$$$) { $version = $pa_config->{'version'} . ' (P) ' . $pa_config->{'build'} unless defined($version); my $master = ($server_type == SATELLITESERVER) ? 0 : $pa_config->{'pandora_master'}; - + + my ($year, $month, $day, $hour, $minute, $second) = split /[- :]/, $timestamp; + + my $keepalive_utimestamp = mktime($second, $minute, $hour, $day, $month-1, $year-1900); + # First run if ($server_id == 0) { # Create an entry in tserver if needed my $server = get_db_single_row ($dbh, 'SELECT id_server FROM tserver WHERE BINARY name = ? AND server_type = ?', $server_name, $server_type); if (! defined ($server)) { - $server_id = db_insert ($dbh, 'id_server', 'INSERT INTO tserver (name, server_type, description, version, threads, queued_modules, server_keepalive) - VALUES (?, ?, ?, ?, ?, ?, ?)', $server_name, $server_type, - 'Autocreated at startup', $version, $num_threads, $queue_size, $keepalive); + $server_id = db_insert ($dbh, 'id_server', 'INSERT INTO tserver (name, server_type, description, version, threads, queued_modules, server_keepalive, server_keepalive_utimestamp) + VALUES (?, ?, ?, ?, ?, ?, ?, ?)', $server_name, $server_type, + 'Autocreated at startup', $version, $num_threads, $queue_size, $keepalive, $keepalive_utimestamp); $server = get_db_single_row ($dbh, 'SELECT status FROM tserver WHERE id_server = ?', $server_id); if (! defined ($server)) { @@ -3193,14 +3197,14 @@ sub pandora_update_server ($$$$$$;$$$$) { $server_id = $server->{'id_server'}; } - db_do ($dbh, 'UPDATE tserver SET status = ?, keepalive = ?, master = ?, laststart = ?, version = ?, threads = ?, queued_modules = ?, server_keepalive = ? + db_do ($dbh, 'UPDATE tserver SET status = ?, keepalive = ?, master = ?, laststart = ?, version = ?, threads = ?, queued_modules = ?, server_keepalive = ?, server_keepalive_utimestamp = ? WHERE id_server = ?', - 1, $timestamp, $master, $timestamp, $version, $num_threads, $queue_size, $keepalive, $server_id); + 1, $timestamp, $master, $timestamp, $version, $num_threads, $queue_size, $keepalive, $keepalive_utimestamp, $server_id); return; } - - db_do ($dbh, 'UPDATE tserver SET status = ?, keepalive = ?, master = ?, version = ?, threads = ?, queued_modules = ?, server_keepalive = ? - WHERE id_server = ?', $status, $timestamp, $master, $version, $num_threads, $queue_size, $keepalive, $server_id); + + db_do ($dbh, 'UPDATE tserver SET status = ?, keepalive = ?, master = ?, version = ?, threads = ?, queued_modules = ?, server_keepalive = ?, server_keepalive_utimestamp = ? + WHERE id_server = ?', $status, $timestamp, $master, $version, $num_threads, $queue_size, $keepalive, $keepalive_utimestamp, $server_id); } ##########################################################################