Merge branch 'ent-6445-excesivo-tiempo-de-carga-web-cuando-un-servidor-esta-caido' into 'develop'

Limit server down notifications once a day

See merge request artica/pandorafms!3513
This commit is contained in:
Daniel Rodriguez 2020-11-26 11:46:39 +01:00
commit ff22a366ca
2 changed files with 57 additions and 34 deletions

View File

@ -535,7 +535,7 @@ $table_advanced->data[0][1] = html_print_input_text(
); );
$table_advanced->data[0][3] = __('Unit'); $table_advanced->data[0][3] = __('Unit');
$table_advanced->data[0][4] = html_print_input_text ( $table_advanced->data[0][4] = html_print_input_text(
'unit', 'unit',
$unit, $unit,
'', '',
@ -548,17 +548,17 @@ $table_advanced->data[0][4] = html_print_input_text (
$classdisabledBecauseInPolicy $classdisabledBecauseInPolicy
); );
// $table_advanced->colspan[1][4] = 3; // $table_advanced->colspan[1][4] = 3;
//$table_advanced->data[0][4] = html_print_extended_select_for_unit( // $table_advanced->data[0][4] = html_print_extended_select_for_unit(
// 'unit', // 'unit',
// $unit, // $unit,
// '', // '',
// '', // '',
// '0', // '0',
// false, // false,
// true, // true,
// false, // false,
// false // false
//); // );
$table_advanced->colspan[0][4] = 3; $table_advanced->colspan[0][4] = 3;
$module_id_policy_module = 0; $module_id_policy_module = 0;

View File

@ -86,17 +86,17 @@ class ConsoleSupervisor
* *
* @var boolean * @var boolean
*/ */
public $verbose; public $interactive;
/** /**
* Constructor. * Constructor.
* *
* @param boolean $verbose Show output while executing or not. * @param boolean $interactive Show output while executing or not.
* *
* @return class This object * @return class This object
*/ */
public function __construct(bool $verbose=true) public function __construct(bool $interactive=true)
{ {
$source = db_get_row( $source = db_get_row(
'tnotification_source', 'tnotification_source',
@ -104,16 +104,16 @@ class ConsoleSupervisor
io_safe_input('System status') io_safe_input('System status')
); );
$this->verbose = $verbose; $this->interactive = $interactive;
if ($source === false) { if ($source === false) {
$this->notificationsEnabled = false; $this->enabled = false;
$this->sourceId = null; $this->sourceId = null;
$this->targetGroups = null; $this->targetGroups = null;
$this->targetUsers = null; $this->targetUsers = null;
} else { } else {
$this->notificationsEnabled = (bool) $source['enabled']; $this->enabled = (bool) $source['enabled'];
$this->sourceId = $source['id']; $this->sourceId = $source['id'];
// Assign targets. // Assign targets.
@ -191,7 +191,7 @@ class ConsoleSupervisor
* NOTIF.CRON.CONFIGURED * NOTIF.CRON.CONFIGURED
*/ */
if ((bool) enterprise_installed() === true) { if (enterprise_installed()) {
$this->checkCronRunning(); $this->checkCronRunning();
} }
@ -254,7 +254,7 @@ class ConsoleSupervisor
$this->maintenanceOperations(); $this->maintenanceOperations();
if ($this->notificationsEnabled === false) { if ($this->enabled === false) {
// Notifications not enabled. // Notifications not enabled.
return; return;
} }
@ -512,13 +512,13 @@ class ConsoleSupervisor
* Update targets for given notification using object targets. * Update targets for given notification using object targets.
* *
* @param array $notification Current notification. * @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 * @return void
*/ */
public function updateTargets( public function updateTargets(
array $notification, array $notification,
bool $update=false bool $send_mails=true
) { ) {
$notification_id = $notification['id_mensaje']; $notification_id = $notification['id_mensaje'];
$blacklist = []; $blacklist = [];
@ -537,7 +537,7 @@ class ConsoleSupervisor
); );
$insertion_string .= ','; $insertion_string .= ',';
if ($update === false) { if ($send_mails === true) {
// Send mail. // Send mail.
if (isset($user['also_mail']) && $user['also_mail'] == 1) { if (isset($user['also_mail']) && $user['also_mail'] == 1) {
enterprise_hook( enterprise_hook(
@ -571,7 +571,7 @@ class ConsoleSupervisor
); );
$insertion_string .= ','; $insertion_string .= ',';
if ($update === false) { if ($send_mails === true) {
// Send mail. // Send mail.
if (isset($group['also_mail']) && $group['also_mail'] == 1) { if (isset($group['also_mail']) && $group['also_mail'] == 1) {
enterprise_hook( enterprise_hook(
@ -612,7 +612,7 @@ class ConsoleSupervisor
public function notify( public function notify(
array $data, array $data,
int $source_id=0, int $source_id=0,
int $max_age=86400 int $max_age=SECONDS_1DAY
) { ) {
// Uses 'check failed' logic. // Uses 'check failed' logic.
if (is_array($data) === false) { if (is_array($data) === false) {
@ -681,8 +681,8 @@ class ConsoleSupervisor
// NOTIF.SERVER.MASTER. // NOTIF.SERVER.MASTER.
// NOTIF.SERVER.STATUS.ID_SERVER. // NOTIF.SERVER.STATUS.ID_SERVER.
if (preg_match('/^NOTIF.SERVER/', $data['type']) === true) { if (preg_match('/^NOTIF.SERVER/', $data['type']) === true) {
// Component notifications require be inmediate. // Send notification once a day.
$max_age = 0; $max_age = SECONDS_1DAY;
} }
// Else ignored. // Else ignored.
@ -693,7 +693,9 @@ class ConsoleSupervisor
$prev = db_get_row( $prev = db_get_row(
'tmensajes', 'tmensajes',
'subtype', 'subtype',
$data['type'] $data['type'],
false,
false
); );
if ($prev !== false if ($prev !== false
@ -712,7 +714,7 @@ class ConsoleSupervisor
], ],
['id_mensaje' => $prev['id_mensaje']] ['id_mensaje' => $prev['id_mensaje']]
); );
$this->updateTargets($prev, true); $this->updateTargets($prev, false);
return; return;
} }
@ -963,9 +965,9 @@ class ConsoleSupervisor
$remote_config_dir = (string) io_safe_output($config['remote_config']); $remote_config_dir = (string) io_safe_output($config['remote_config']);
if ((bool) enterprise_installed() === true if (enterprise_installed()
&& isset($config['license_nms']) === true && isset($config['license_nms'])
&& (int) $config['license_nms'] !== 1 && $config['license_nms'] != 1
) { ) {
if (is_readable($remote_config_dir) !== true) { if (is_readable($remote_config_dir) !== true) {
$this->notify( $this->notify(
@ -1242,8 +1244,29 @@ class ConsoleSupervisor
$this->cleanNotifications('NOTIF.SERVER.STATUS%'); $this->cleanNotifications('NOTIF.SERVER.STATUS%');
return; return;
} else { } else {
// Clean notifications. Only show notif for down servers. // Clean notifications. Only show notif for down servers
$this->cleanNotifications('NOTIF.SERVER.STATUS%'); // 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) { foreach ($servers as $server) {