From 2e0321fc6e2a75cdfcee0ab41826a176a64cfd1f Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 7 Oct 2020 18:48:17 +0200 Subject: [PATCH 1/4] Limit server down notifications once a day --- .../include/class/ConsoleSupervisor.php | 45 +++++++++++++------ 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/pandora_console/include/class/ConsoleSupervisor.php b/pandora_console/include/class/ConsoleSupervisor.php index 5caad6f9e8..62acd97a93 100644 --- a/pandora_console/include/class/ConsoleSupervisor.php +++ b/pandora_console/include/class/ConsoleSupervisor.php @@ -45,6 +45,13 @@ enterprise_include_once('include/functions_cron.php'); class ConsoleSupervisor { + /** + * Being executed while navigation. + * + * @var boolean + */ + private $quick; + /** * Show if console supervisor is enabled or not. * @@ -149,8 +156,6 @@ class ConsoleSupervisor */ public function runBasic() { - global $config; - /* * PHP configuration warnings: * NOTIF.PHP.SAFE_MODE @@ -213,30 +218,35 @@ class ConsoleSupervisor * Check if the Server and Console has * the same versions. */ + $this->checkConsoleServerVersions(); /* * Check if AllowOverride is None or All. * NOTIF.ALLOWOVERIDE.MESSAGE */ + $this->checkAllowOverrideEnabled(); /* * Check if AllowOverride is None or All. * NOTIF.HAMASTER.MESSAGE */ + $this->checkHaStatus(); /* * Check if the Pandora Console log * file remains in old location. */ + $this->checkPandoraConsoleLogOldLocation(); /* * Check if the audit log file * remains in old location. */ + $this->checkAuditLogOldLocation(); } @@ -462,16 +472,19 @@ class ConsoleSupervisor * Check if the Server and Console has * the same versions. */ + $this->checkConsoleServerVersions(); /* * Check if AllowOverride is None or All. */ - $this->checkAllowOverrideEnabled(); - /* - * Check if HA status. - */ + $this->checkAllowOverrideEnabled(); + + /* + * Check if HA status. + */ + if (enterprise_installed()) { $this->checkHaStatus(); } @@ -480,11 +493,13 @@ class ConsoleSupervisor * Check if the audit log file * remains in old location. */ + $this->checkAuditLogOldLocation(); /* - Check if AllowOverride is None or All. - */ + * Check if AllowOverride is None or All. + */ + $this->checkAllowOverrideEnabled(); } @@ -594,7 +609,7 @@ class ConsoleSupervisor public function notify( array $data, int $source_id=0, - int $max_age=86400 + int $max_age=SECONDS_1DAY ) { // Uses 'check failed' logic. if (is_array($data) === false) { @@ -663,8 +678,8 @@ class ConsoleSupervisor // NOTIF.SERVER.MASTER. // NOTIF.SERVER.STATUS.ID_SERVER. if (preg_match('/^NOTIF.SERVER/', $data['type']) === true) { - // Component notifications require be inmediate. - $max_age = 0; + // Send notification once a day. + $max_age = SECONDS_1DAY; } // Else ignored. @@ -943,7 +958,7 @@ class ConsoleSupervisor { global $config; - $remote_config_dir = io_safe_output($config['remote_config']); + $remote_config_dir = (string) io_safe_output($config['remote_config']); if (enterprise_installed() && isset($config['license_nms']) @@ -1183,6 +1198,8 @@ class ConsoleSupervisor */ public function checkPandoraServers() { + global $config; + $servers = db_get_all_rows_sql( 'SELECT id_server, @@ -1280,6 +1297,8 @@ class ConsoleSupervisor */ public function checkPandoraServerMasterAvailable() { + global $config; + $n_masters = db_get_value_sql( 'SELECT count(*) as n @@ -2524,7 +2543,7 @@ class ConsoleSupervisor } - /* + /** * Check if Pandora console log file remains in old location. * * @return void From 64bd9bfc79b397cf1394e4a1269459cbc3f3de4e Mon Sep 17 00:00:00 2001 From: Luis Calvo Date: Thu, 5 Nov 2020 16:14:06 +0100 Subject: [PATCH 2/4] Fixed safe input on cli delete_group --- pandora_server/util/pandora_manage.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index ba141b545f..193635a3f9 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -5734,7 +5734,7 @@ sub cli_delete_group() { my $group_id = get_group_id($dbh,$group_name); exist_check($group_id, 'group name', $group_name); - $group_id = db_do ($dbh, 'DELETE FROM tgrupo WHERE nombre=?', $group_name); + $group_id = db_do ($dbh, 'DELETE FROM tgrupo WHERE nombre=?', safe_input($group_name)); if($group_id == -1) { print_log "[ERROR] A problem has been ocurred deleting group '$group_name'\n\n"; From 2632256c10e2a74a441dd9f2e4b65024f78b14c7 Mon Sep 17 00:00:00 2001 From: alejandro-campos Date: Wed, 11 Nov 2020 17:45:21 +0100 Subject: [PATCH 3/4] fixed agent creation with unique ip condition --- pandora_console/include/functions_api.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index a7f6ef8c81..b69bc9efe0 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -1570,7 +1570,9 @@ function api_set_new_agent($thrash1, $thrash2, $other, $thrash3) $nombre_agente = $alias; } - if ($direccion_agente != '') { + $exists_ip = false; + + if ($config['unique_ip'] && $direccion_agente != '') { $exists_ip = db_get_row_sql('SELECT direccion FROM tagente WHERE direccion = "'.$direccion_agente.'"'); } From 112144094317c6607ebc950204c60a471983eb24 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Thu, 26 Nov 2020 11:28:31 +0100 Subject: [PATCH 4/4] Clean only recovered servers --- .../include/class/ConsoleSupervisor.php | 47 ++++++++++++++----- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/pandora_console/include/class/ConsoleSupervisor.php b/pandora_console/include/class/ConsoleSupervisor.php index 3a73f4b402..2d14003ba2 100644 --- a/pandora_console/include/class/ConsoleSupervisor.php +++ b/pandora_console/include/class/ConsoleSupervisor.php @@ -86,17 +86,17 @@ class ConsoleSupervisor * * @var boolean */ - public $verbose; + public $interactive; /** * Constructor. * - * @param boolean $verbose Show output while executing or not. + * @param boolean $interactive Show output while executing or not. * * @return class This object */ - public function __construct(bool $verbose=true) + public function __construct(bool $interactive=true) { $source = db_get_row( 'tnotification_source', @@ -104,7 +104,7 @@ class ConsoleSupervisor io_safe_input('System status') ); - $this->verbose = $verbose; + $this->interactive = $interactive; if ($source === false) { $this->enabled = false; @@ -512,13 +512,13 @@ class ConsoleSupervisor * Update targets for given notification using object targets. * * @param array $notification Current notification. - * @param boolean $update Only update db targets, no email. + * @param boolean $send_mails Only update db targets, no email. * * @return void */ public function updateTargets( array $notification, - bool $update=false + bool $send_mails=true ) { $notification_id = $notification['id_mensaje']; $blacklist = []; @@ -537,7 +537,7 @@ class ConsoleSupervisor ); $insertion_string .= ','; - if ($update === false) { + if ($send_mails === true) { // Send mail. if (isset($user['also_mail']) && $user['also_mail'] == 1) { enterprise_hook( @@ -571,7 +571,7 @@ class ConsoleSupervisor ); $insertion_string .= ','; - if ($update === false) { + if ($send_mails === true) { // Send mail. if (isset($group['also_mail']) && $group['also_mail'] == 1) { enterprise_hook( @@ -693,7 +693,9 @@ class ConsoleSupervisor $prev = db_get_row( 'tmensajes', 'subtype', - $data['type'] + $data['type'], + false, + false ); if ($prev !== false @@ -712,7 +714,7 @@ class ConsoleSupervisor ], ['id_mensaje' => $prev['id_mensaje']] ); - $this->updateTargets($prev, true); + $this->updateTargets($prev, false); return; } @@ -1242,8 +1244,29 @@ class ConsoleSupervisor $this->cleanNotifications('NOTIF.SERVER.STATUS%'); return; } else { - // Clean notifications. Only show notif for down servers. - $this->cleanNotifications('NOTIF.SERVER.STATUS%'); + // Clean notifications. Only show notif for down servers + // ONLY FOR RECOVERED ONES. + $servers_working = db_get_all_rows_sql( + 'SELECT + id_server, + name, + server_type, + server_keepalive, + status, + unix_timestamp() - unix_timestamp(keepalive) as downtime + FROM tserver + WHERE + unix_timestamp() - unix_timestamp(keepalive) <= server_keepalive + OR status != 0' + ); + + if (is_array($servers_working) === true) { + foreach ($servers_working as $server) { + $this->cleanNotifications( + 'NOTIF.SERVER.STATUS'.$server['id_server'] + ); + } + } } foreach ($servers as $server) {