From 62172c19a212a49a1f56bec25b932f0f0a4071ef Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Thu, 31 Mar 2022 14:34:16 +0200 Subject: [PATCH] Notify in details popup when critical issues happened in discovery task scan --- .../wizards/DiscoveryTaskList.class.php | 53 +++++++++++-------- .../include/functions_messages.php | 26 +++++---- .../lib/PandoraFMS/DiscoveryServer.pm | 11 +++- 3 files changed, 55 insertions(+), 35 deletions(-) diff --git a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php index ba690e8ce6..90e43aa526 100644 --- a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php +++ b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php @@ -1192,7 +1192,7 @@ class DiscoveryTaskList extends HTML */ private function progressTaskGraph($task) { - $result .= '
'; + $result = '
'; $result .= '
'; $result .= ''._('Overall Progress').''; @@ -1317,6 +1317,9 @@ class DiscoveryTaskList extends HTML if (is_array($task['stats']) === false) { $task['stats'] = json_decode($task['summary'], true); + if (json_last_error() !== JSON_ERROR_NONE) { + return $task['summary']; + } } if (is_array($task['stats'])) { @@ -1379,31 +1382,35 @@ class DiscoveryTaskList extends HTML $table->data[$i++][1] .= ''; } else { // Content. - $table->data[$i][0] = ''.__('Hosts discovered').''; - $table->data[$i][1] = ''; - $table->data[$i][1] .= $task['stats']['summary']['discovered']; - $table->data[$i++][1] .= ''; - - $table->data[$i][0] = ''.__('Alive').''; - $table->data[$i][1] = ''; - $table->data[$i][1] .= $task['stats']['summary']['alive']; - $table->data[$i++][1] .= ''; - - $table->data[$i][0] = ''.__('Not alive').''; - $table->data[$i][1] = ''; - $table->data[$i][1] .= $task['stats']['summary']['not_alive']; - $table->data[$i++][1] .= ''; - - if ($task['type'] == DISCOVERY_HOSTDEVICES) { - $table->data[$i][0] = ''.__('Responding SNMP').''; - $table->data[$i][1] = ''; - $table->data[$i][1] .= $task['stats']['summary']['SNMP']; + if (is_array($task['stats']['summary']) === true) { + $table->data[$i][0] = ''.__('Hosts discovered').''; + $table->data[$i][1] = ''; + $table->data[$i][1] .= $task['stats']['summary']['discovered']; $table->data[$i++][1] .= ''; - $table->data[$i][0] = ''.__('Responding WMI').''; - $table->data[$i][1] = ''; - $table->data[$i][1] .= $task['stats']['summary']['WMI']; + $table->data[$i][0] = ''.__('Alive').''; + $table->data[$i][1] = ''; + $table->data[$i][1] .= $task['stats']['summary']['alive']; $table->data[$i++][1] .= ''; + + $table->data[$i][0] = ''.__('Not alive').''; + $table->data[$i][1] = ''; + $table->data[$i][1] .= $task['stats']['summary']['not_alive']; + $table->data[$i++][1] .= ''; + + if ($task['type'] == DISCOVERY_HOSTDEVICES) { + $table->data[$i][0] = ''.__('Responding SNMP').''; + $table->data[$i][1] = ''; + $table->data[$i][1] .= $task['stats']['summary']['SNMP']; + $table->data[$i++][1] .= ''; + + $table->data[$i][0] = ''.__('Responding WMI').''; + $table->data[$i][1] = ''; + $table->data[$i][1] .= $task['stats']['summary']['WMI']; + $table->data[$i++][1] .= ''; + } + } else { + $table->data[$i][0] = $task['stats']['summary']; } } diff --git a/pandora_console/include/functions_messages.php b/pandora_console/include/functions_messages.php index a8a0b009bf..b92073baee 100644 --- a/pandora_console/include/functions_messages.php +++ b/pandora_console/include/functions_messages.php @@ -228,13 +228,26 @@ function messages_process_read( $utimestamp = time(); } + $already_read = db_get_value_filter( + 'utimestamp_read', + 'tnotification_user', + [ + 'id_mensaje' => $message_id, + 'id_user' => $config['id_user'], + ] + ); + + if (empty($already_read) === false) { + // Already read. + return true; + } + $ret = db_process_sql_update( 'tnotification_user', ['utimestamp_read' => $utimestamp], [ - 'id_mensaje' => $message_id, - 'id_user' => $config['id_user'], - 'utimestamp_read' => null, + 'id_mensaje' => $message_id, + 'id_user' => $config['id_user'], ] ); @@ -585,13 +598,6 @@ function messages_get_overview_sent( 'tmensajes', $filter ); - - return db_get_all_rows_field_filter( - 'tmensajes', - 'id_usuario_origen', - $config['id_user'], - $order - ); } diff --git a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm index e9b7bc9240..fcc1c8ca47 100644 --- a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm +++ b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm @@ -1729,13 +1729,20 @@ sub PandoraFMS::Recon::Base::message($$$) { my ($self, $message, $verbosity) = @_; if ($verbosity <= 1) { + my $label = "[Discovery task " . $self->{'task_id'} . "]"; + if (ref($self->{'task_data'}) eq 'HASH' && defined($self->{'task_data'}{'name'})) { + $label = "[Discovery task " . $self->{'task_data'}{'name'} . "]"; + } + PandoraFMS::Core::send_console_notification( $self->{'pa_config'}, $self->{'parent'}->getDBH(), - "[Recon task " . $self->{'task_id'} . "]", + $label, $message, ['admin'] - ) + ); + + $self->{'summary'} = $message; } logger($self->{'pa_config'}, "[Recon task " . $self->{'task_id'} . "] $message", $verbosity);