From 747a63a2ba6e19e27e9da334d01889b10454586e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Su=C3=A1rez?= Date: Wed, 6 Mar 2024 09:41:48 -0600 Subject: [PATCH] Add agent_disabled functionality --- pandora_console/extras/mr/68.sql | 1 + .../godmode/servers/servers.build_table.php | 8 ++++++++ .../status_sets/default/server_standby.png | Bin 0 -> 2764 bytes .../default/server_standby_ball.png | Bin 0 -> 2988 bytes pandora_console/include/constants.php | 4 ++-- pandora_console/include/functions_modules.php | 4 ++++ pandora_console/include/functions_ui.php | 1 + pandora_console/pandoradb.sql | 1 + pandora_server/lib/PandoraFMS/Core.pm | 18 ++++++++++++------ pandora_server/lib/PandoraFMS/DataServer.pm | 4 ++-- 10 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 pandora_console/images/status_sets/default/server_standby.png create mode 100644 pandora_console/images/status_sets/default/server_standby_ball.png diff --git a/pandora_console/extras/mr/68.sql b/pandora_console/extras/mr/68.sql index eb2a99c6ee..c72067b5d8 100644 --- a/pandora_console/extras/mr/68.sql +++ b/pandora_console/extras/mr/68.sql @@ -157,5 +157,6 @@ CREATE TABLE IF NOT EXISTS `tmetaconsole_ha_databases` ( `master` tinyint unsigned DEFAULT '0', PRIMARY KEY (`node_id`, `host`) ) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; +ALTER TABLE `tserver` ADD COLUMN `disabled` BOOLEAN NOT NULL DEFAULT FALSE; COMMIT; \ No newline at end of file diff --git a/pandora_console/godmode/servers/servers.build_table.php b/pandora_console/godmode/servers/servers.build_table.php index 58c9f02a7d..beebb0286e 100644 --- a/pandora_console/godmode/servers/servers.build_table.php +++ b/pandora_console/godmode/servers/servers.build_table.php @@ -133,6 +133,14 @@ foreach ($servers as $server) { __('Server has crashed.'), true ); + + } else if ((int) ($server['disabled'] == 1)){ + $data[1] = ui_print_status_image( + STATUS_SERVER_STANDBY, + __('Server was manually disabled.'), + true + ); + } else if ((int) ($server['status'] === 0) || (($date - $server_keepalive) > ($server['server_keepalive']) * 2) ) { diff --git a/pandora_console/images/status_sets/default/server_standby.png b/pandora_console/images/status_sets/default/server_standby.png new file mode 100644 index 0000000000000000000000000000000000000000..21e8a6e2cc1ac88cebf4551684782fd24d7d2966 GIT binary patch literal 2764 zcma)8d5jZP81HHb3yPxPt^v`>Ul-2j9$9AP4P1?SB@Av(_ z`|@S^yn!!_w75eE^>LV zcHnC7gkgslEUbI(?%}nG*%KZZR{!hp_YU?&`kL;%;o6qb{VT3Ix!Qi~%;=wY9DgnQ ztuM0c7<1zFncJh!|M2$8>>;=*dVJ2whUt6tNssTTeP`FwS*w1J|2439|5tH#(xPoO z*`1Fqctw0-)3H-yzHXL}Zah@Ix*P{I^%DY63?NZ>1L^Y5D9WwHwAI=bpO1?@-OD zTMiuj_`ppcyuSO%jmy?|pLi*~_}TS={hiX;T}S4e`)Nhr`lqK3-+SdVb!{NK{MY@KyyLb${)O(HA3b+?%$E5tEYFI6Z0I^Q>-Ldw&&OvH zQzk7E4jnhu33)hVo2B!PIIr2oPe_+7#pkl4ru~vBlr)GrN zaTFZP3bc?KgGyH|H$j?wLjMTRi4 z6-zT6&Cn^r2xCUZ3DMZpybo!!wY5a7+l5Hsn6Wu%vYZ#N=`?Z7McYo(JSCVKWIBA=bG;t!KrA^lj9N3Z)RViW2jFocFRfR<wuviY zv0MpU(VU{{i0LRkjBd&e+K;26xa_v0vSk342S8*1&+t-7k(tWa<(e`!B3rI_N{zF` z0TQgDK1YiW=4*&$)L&=bEM8YAOL{U}^MN?&W8S@KD z3NFavEfWk8(uLz9j11dg~ z`~nxFDN+=2eMclj^IlMR>_|Z;ZdmCMJwwwoxx#K#OQS9al9Y1+An+pR13(f*Nh-?C zLY9pSoltSW%kwm)D)Jqe2;!`3X_!E)sVCfBLjRv#Y`5HKA?O%Z)G$&Z+8y(R%JnvX zhQiQ6SOMUDq(lH8<$%mdvL7%YAcF$5)lju~ZzU-2llkBfD4rZDbm0GjN#V#i-Z<-!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=I&w>!u}>B>gGASMxm0-DrkS3)O9pR7{eLs7j!qt3X|fj&W?%%M!dh$`EcB z>mfL|+e5G}3h*KeVu0le`pt#{M@~$Zi$NBn6eGqcf}vv!!E!83L}e~YNQ}(MbTlea zE*{5FBMAPMun%XPRQ|OkDOxejNcr$aMNMb((uk4*ZI+12OnWF7!_h3wczE8;(RoBW zFibcZ$P`UE83xB>NvMN{L|ADhCB^}%t8rV3%>PFU84-d85G~D!Xj;;T+rJCQl$~wv z41`1rKnE1VqPC!z2u%qzFSsd!@(5HO+N8-!tg{@HVFfo_5G7E!YGlz8{}+s!MSy(6 zN{eXzAqzNG>I0sY8^a;VjTXr5x-(8RUKuS_<=u zF|5;zRX?PtvX(K6>68$Ok|EK`&J_V|2{?bf^~t@5fT6%b)EQa|G7lG~Aon@l?%KYm zJEvQYn%rh^!{yM&Wu0@vGX@wUB(=s~4*GuOr5ZdrU7_E@Dw5}%=VC0>{a@s_c1@sE@ zi=|Jc-g8?gsOg<>wI;0Qj9T8+H3(a;QIUXZYGs2fIkOwF1Or~3zI(SO4X<5XIOLC1uaN#SUasih<2pUy`N8nh7@DwXlZdy{)2pgP_gha! oZrV0_RJi3}<@@tSHQ5Nq?Wg;H|Lxi?C%U_ZYo~^`1fHD#FB?buEC2ui literal 0 HcmV?d00001 diff --git a/pandora_console/include/constants.php b/pandora_console/include/constants.php index 48046e2905..4c640ec3b6 100644 --- a/pandora_console/include/constants.php +++ b/pandora_console/include/constants.php @@ -325,7 +325,7 @@ define('STATUS_ALERT_DISABLED', 'alert_disabled.png'); define('STATUS_SERVER_OK', 'server_ok.png'); define('STATUS_SERVER_DOWN', 'server_down.png'); define('STATUS_SERVER_CRASH', 'server_crash.png'); - +define('STATUS_SERVER_STANDBY', 'server_standby.png'); // Status images (ball). // For modules. @@ -351,7 +351,7 @@ define('STATUS_ALERT_DISABLED_BALL', 'alert_disabled_ball.png'); define('STATUS_SERVER_OK_BALL', 'server_ok_ball.png'); define('STATUS_SERVER_DOWN_BALL', 'server_down_ball.png'); define('STATUS_SERVER_CRASH_BALL', 'server_crash_ball.png'); - +define('STATUS_SERVER_STANDBY_BALL', 'server_standby_ball.png'); // Events criticity. diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index 2fb31c87b2..0ce82b1cc0 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -2851,6 +2851,10 @@ function modules_get_color_status($status, $force_module=false) case STATUS_SERVER_CRASH_BALL: return COL_CRITICAL; + case STATUS_SERVER_STANDBY: + case STATUS_SERVER_STANDBY_BALL: + return COL_WARNING; + case AGENT_MODULE_STATUS_WARNING: case AGENT_STATUS_WARNING: case STATUS_MODULE_WARNING: diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index 0f46c890a0..2ab5c1be83 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -3454,6 +3454,7 @@ function get_shape_status_set($type) case STATUS_SERVER_OK: case STATUS_SERVER_DOWN: case STATUS_SERVER_CRASH: + case STATUS_SERVER_STANDBY: $return = ['class' => 'status_small_squares']; break; diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index c53fefe586..fe3eb7ebaa 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -1157,6 +1157,7 @@ CREATE TABLE IF NOT EXISTS `tserver` ( `exec_proxy` TINYINT UNSIGNED NOT NULL DEFAULT 0, `port` INT UNSIGNED NOT NULL DEFAULT 0, `server_keepalive_utimestamp` BIGINT NOT NULL DEFAULT 0, + `disabled` BOOLEAN NOT NULL DEFAULT FALSE, 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 5d3d34f870..2fe0572a3a 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -3374,12 +3374,14 @@ 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, $keepalive) = @_; + $server_type, $num_threads, $queue_size, $version, $keepalive, $disabled, $remote_config) = @_; $num_threads = 0 unless defined ($num_threads); $queue_size = 0 unless defined ($queue_size); + $remote_config = 0 unless defined($remote_config); + $disabled = 0 unless defined($disabled); $keepalive = $pa_config->{'keepalive'} unless defined ($keepalive); my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime()); @@ -3393,13 +3395,12 @@ sub pandora_update_server ($$$$$$;$$$$) { # 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, server_keepalive_utimestamp) - VALUES (?, ?, ?, ?, ?, ?, ?, ?)', $server_name, $server_type, - 'Autocreated at startup', $version, $num_threads, $queue_size, $keepalive, $keepalive_utimestamp); + $server_id = db_insert ($dbh, 'id_server', 'INSERT INTO tserver (name, server_type, description, version, threads, queued_modules, server_keepalive, server_keepalive_utimestamp, disabled) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)', $server_name, $server_type, + 'Autocreated at startup', $version, $num_threads, $queue_size, $keepalive, $keepalive_utimestamp, $disabled); $server = get_db_single_row ($dbh, 'SELECT status FROM tserver WHERE id_server = ?', $server_id); if (! defined ($server)) { @@ -3408,6 +3409,10 @@ sub pandora_update_server ($$$$$$;$$$$) { } } else { $server_id = $server->{'id_server'}; + + if(!$remote_config){ + db_do ($dbh, 'UPDATE tserver SET disabled = ? WHERE id_server = ?', $disabled, $server_id); + } } db_do ($dbh, 'UPDATE tserver SET status = ?, keepalive = ?, master = ?, laststart = ?, version = ?, threads = ?, queued_modules = ?, server_keepalive = ?, server_keepalive_utimestamp = ? @@ -7206,6 +7211,7 @@ sub pandora_disable_autodisable_agents ($$) { GROUP BY tm.id_agente ) AS subquery WHERE subquery.unknown_count >= subquery.sync_modules;'; + my @agents_autodisabled = get_db_rows ($dbh, $sql); return if ($#agents_autodisabled < 0); diff --git a/pandora_server/lib/PandoraFMS/DataServer.pm b/pandora_server/lib/PandoraFMS/DataServer.pm index cb2c5afc4c..5601c1eef7 100644 --- a/pandora_server/lib/PandoraFMS/DataServer.pm +++ b/pandora_server/lib/PandoraFMS/DataServer.pm @@ -1067,9 +1067,9 @@ sub process_xml_server ($$$$) { $modules = 0 unless defined($modules); $threads = 0 unless defined($threads); $version = '' unless defined($version); - + # Update server information - pandora_update_server ($pa_config, $dbh, $data->{'server_name'}, 0, 1, $server_type, $threads, $modules, $version, $data->{'keepalive'}); + pandora_update_server ($pa_config, $dbh, $data->{'server_name'}, 0, 1, $server_type, $threads, $modules, $version, $data->{'keepalive'}, $data->{'disabled'}, $data->{'remote_config'}); }