From f397b657f17a48a81f73b7ade6659088a45c6eb3 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Tue, 15 Mar 2016 16:02:27 +0100 Subject: [PATCH] Added new server_keepalive column to have individual keepalive TICKETS #3273 --- .../pandoradb_migrate_6.0_to_6.1.mysql.sql | 6 ++++++ .../pandoradb_migrate_6.0_to_6.1.oracle.sql | 6 ++++++ .../godmode/servers/servers.build_table.php | 8 ++++---- pandora_console/include/functions_servers.php | 6 +++--- pandora_console/pandoradb.oracle.sql | 1 + pandora_console/pandoradb.postgreSQL.sql | 1 + pandora_console/pandoradb.sql | 1 + pandora_server/bin/pandora_server | 9 +++++++-- pandora_server/lib/PandoraFMS/Core.pm | 19 ++++++++++--------- pandora_server/lib/PandoraFMS/DataServer.pm | 2 +- 10 files changed, 40 insertions(+), 19 deletions(-) diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.mysql.sql index 611620659f..831efe6859 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.mysql.sql @@ -3,3 +3,9 @@ -- --------------------------------------------------------------------- ALTER TABLE talert_templates ADD COLUMN `min_alerts_reset_counter` tinyint(1) DEFAULT 0; + +-- ---------------------------------------------------------------------- +-- Table `tserver` +-- ---------------------------------------------------------------------- + +ALTER TABLE tserver ADD COLUMN `server_keepalive` int(11) DEFAULT 0; diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.oracle.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.oracle.sql index e727b8e558..1ede58f9cb 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.oracle.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.oracle.sql @@ -3,3 +3,9 @@ -- --------------------------------------------------------------------- ALTER TABLE talert_templates ADD COLUMN min_alerts_reset_counter NUMBER(5, 0) DEFAULT 0; + +-- ---------------------------------------------------------------------- +-- Table `tserver` +-- ---------------------------------------------------------------------- + +ALTER TABLE tserver ADD COLUMN server_keepalive NUMBER(10, 0) DEFAULT 0; diff --git a/pandora_console/godmode/servers/servers.build_table.php b/pandora_console/godmode/servers/servers.build_table.php index 0ae432f682..5f03a29c64 100644 --- a/pandora_console/godmode/servers/servers.build_table.php +++ b/pandora_console/godmode/servers/servers.build_table.php @@ -30,6 +30,7 @@ if (! check_acl ($config["id_user"], 0, "AW")) { global $tiny; global $hidden_toggle; +$date = time(); $servers = servers_get_info(); if ($servers === false) { @@ -84,12 +85,11 @@ foreach ($servers as $server) { $data[0] = '' . $server['name'] . ''; - if ($server['status'] == 0) { + //Status + $data[1] = ui_print_status_image (STATUS_SERVER_OK, '', true); + if (($server['status'] == 0) || (($date - strtotime($server['keepalive'])) > ($server['server_keepalive'])*2)) { $data[1] = ui_print_status_image (STATUS_SERVER_DOWN, '', true); } - else { - $data[1] = ui_print_status_image (STATUS_SERVER_OK, '', true); - } // Type $data[2] = '' . $server["img"]; diff --git a/pandora_console/include/functions_servers.php b/pandora_console/include/functions_servers.php index 1ee10a099c..bf0435350d 100644 --- a/pandora_console/include/functions_servers.php +++ b/pandora_console/include/functions_servers.php @@ -765,19 +765,19 @@ function servers_check_status () { $sql = "SELECT COUNT(id_server) FROM tserver WHERE status = 1 - AND keepalive > NOW() - INTERVAL 15 MINUTE"; + AND keepalive > NOW() - INTERVAL server_keepalive*2 SECOND"; break; case "postgresql": $sql = "SELECT COUNT(id_server) FROM tserver WHERE status = 1 - AND keepalive > NOW() - INTERVAL '15 MINUTE'"; + AND keepalive > NOW() - INTERVAL 'server_keepalive*2 SECOND'"; break; case "oracle": $sql = "SELECT COUNT(id_server) FROM tserver WHERE status = 1 - AND keepalive > systimestamp - INTERVAL '15' MINUTE"; + AND keepalive > systimestamp - INTERVAL 'server_keepalive*2' SECOND"; break; } $status = (int) db_get_sql ($sql); //Cast as int will assure a number value diff --git a/pandora_console/pandoradb.oracle.sql b/pandora_console/pandoradb.oracle.sql index 4543e7d3e2..4a26daa234 100755 --- a/pandora_console/pandoradb.oracle.sql +++ b/pandora_console/pandoradb.oracle.sql @@ -1001,6 +1001,7 @@ CREATE TABLE tserver ( lag_modules NUMBER(10, 0) DEFAULT 0, total_modules_running NUMBER(10, 0) DEFAULT 0, my_modules NUMBER(10, 0) DEFAULT 0, + server_keepalive NUMBER(10, 0) DEFAULT 0, stat_utimestamp NUMBER(19, 0) DEFAULT 0 ); CREATE INDEX tserver_name_idx ON tserver(name); diff --git a/pandora_console/pandoradb.postgreSQL.sql b/pandora_console/pandoradb.postgreSQL.sql index 7695d49bcd..af12bede75 100755 --- a/pandora_console/pandoradb.postgreSQL.sql +++ b/pandora_console/pandoradb.postgreSQL.sql @@ -820,6 +820,7 @@ CREATE TABLE "tserver" ( "lag_modules" INTEGER NOT NULL default 0, "total_modules_running" INTEGER NOT NULL default 0, "my_modules" INTEGER NOT NULL default 0, + "server_keepalive" INTEGER NOT NULL default 0, "stat_utimestamp" BIGINT NOT NULL default 0 ); CREATE INDEX "tserver_name_idx" ON "tserver"("name"); diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 7bdec3a447..125185cf84 100755 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -895,6 +895,7 @@ CREATE TABLE IF NOT EXISTS `tserver` ( `lag_modules` int(11) NOT NULL default 0, `total_modules_running` int(11) NOT NULL default 0, `my_modules` int(11) NOT NULL default 0, + `server_keepalive` int(11) NOT NULL default 0, `stat_utimestamp` bigint(20) NOT NULL default '0', PRIMARY KEY (`id_server`), KEY `name` (`name`) diff --git a/pandora_server/bin/pandora_server b/pandora_server/bin/pandora_server index eead79c04e..12d3cd412d 100755 --- a/pandora_server/bin/pandora_server +++ b/pandora_server/bin/pandora_server @@ -606,8 +606,13 @@ sub main() { $server->update(); } - # Update fallen servers - db_do ($DBH, "UPDATE tserver SET status = 0 WHERE keepalive < ?", strftime ("%Y-%m-%d %H:%M:%S", localtime(time() - $Config{'keepalive'}))); + # Update fallen servers + my @servers_db = get_db_rows ($DBH, "SELECT id_server, server_keepalive FROM tserver"); + for (@servers_db) { + my %server_db = %$_; + my $expected_update = strftime ("%Y-%m-%d %H:%M:%S", localtime(time() - $server_db{'server_keepalive'} * 2)); + db_do ($DBH, "UPDATE tserver SET status = 0 WHERE keepalive < ? AND id_server = ?", $expected_update, $server_db{'id_server'}); + } # Set the master server pandora_set_master(\%Config, $DBH); diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 6f4aedf0c6..c42e96e5b2 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -2197,12 +2197,13 @@ Update server status: =cut ########################################################################## -sub pandora_update_server ($$$$$$;$$$) { +sub pandora_update_server ($$$$$$;$$$$) { my ($pa_config, $dbh, $server_name, $server_id, $status, - $server_type, $num_threads, $queue_size, $version) = @_; + $server_type, $num_threads, $queue_size, $version, $keepalive) = @_; $num_threads = 0 unless defined ($num_threads); $queue_size = 0 unless defined ($queue_size); + $keepalive = $pa_config->{'keepalive'} unless defined ($keepalive); my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime()); $version = $pa_config->{'version'} . ' (P) ' . $pa_config->{'build'} unless defined($version); @@ -2215,9 +2216,9 @@ sub pandora_update_server ($$$$$$;$$$) { # Create an entry in tserver if needed my $server = get_db_single_row ($dbh, 'SELECT id_server FROM tserver WHERE 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) - VALUES (?, ?, ?, ?, ?, ?)', $server_name, $server_type, - 'Autocreated at startup', $version, $num_threads, $queue_size); + $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 = get_db_single_row ($dbh, 'SELECT status FROM tserver WHERE id_server = ?', $server_id); if (! defined ($server)) { @@ -2228,14 +2229,14 @@ sub pandora_update_server ($$$$$$;$$$) { $server_id = $server->{'id_server'}; } - db_do ($dbh, 'UPDATE tserver SET status = ?, keepalive = ?, master = ?, laststart = ?, version = ?, threads = ?, queued_modules = ? + db_do ($dbh, 'UPDATE tserver SET status = ?, keepalive = ?, master = ?, laststart = ?, version = ?, threads = ?, queued_modules = ?, server_keepalive = ? WHERE id_server = ?', - 1, $timestamp, $master, $timestamp, $version, $num_threads, $queue_size, $server_id); + 1, $timestamp, $master, $timestamp, $version, $num_threads, $queue_size, $keepalive, $server_id); return; } - db_do ($dbh, 'UPDATE tserver SET status = ?, keepalive = ?, master = ?, version = ?, threads = ?, queued_modules = ? - WHERE id_server = ?', $status, $timestamp, $master, $version, $num_threads, $queue_size, $server_id); + 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); } ########################################################################## diff --git a/pandora_server/lib/PandoraFMS/DataServer.pm b/pandora_server/lib/PandoraFMS/DataServer.pm index 92324bed0e..e86f063553 100644 --- a/pandora_server/lib/PandoraFMS/DataServer.pm +++ b/pandora_server/lib/PandoraFMS/DataServer.pm @@ -817,7 +817,7 @@ sub process_xml_server ($$$$) { $version = '' unless defined($version); # Update server information - pandora_update_server ($pa_config, $dbh, $data->{'server_name'}, 0, 1, $server_type, $threads, $modules, $version); + pandora_update_server ($pa_config, $dbh, $data->{'server_name'}, 0, 1, $server_type, $threads, $modules, $version, $data->{'keepalive'}); } 1;