Clean only recovered servers

This commit is contained in:
fbsanchez 2020-11-26 11:28:31 +01:00
parent d18fffb0cb
commit 1121440943
1 changed files with 35 additions and 12 deletions

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,7 +104,7 @@ 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->enabled = false; $this->enabled = false;
@ -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(
@ -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;
} }
@ -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) {