diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 7658f784eb..ae1ed79d54 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -1832,18 +1832,7 @@ sub pandora_execute_action ($$$$$$$$$;$$) { my @user_list = map {clean_blank($_)} split /,/, $field1; my @group_list = map {clean_blank($_)} split /,/, $field2; - my $notification = {}; - $notification->{'subject'} = safe_input($field3); - $notification->{'mensaje'} = safe_input($field4); - $notification->{'id_source'} = get_db_value($dbh, 'SELECT id FROM tnotification_source WHERE description = ?', safe_input('System status')); - - # Create message - my $notification_id = db_process_insert($dbh,'id_mensaje','tmensajes',$notification); - if (!$notification_id) { - logger($pa_config, "Failed action '" . $action->{'name'} . "' for alert '". $alert->{'name'} . "' agent '" . (defined($agent) ? $agent->{'alias'} : 'N/A') . "'.", 3); - } else { - notification_set_targets($pa_config, $dbh, $notification_id, \@user_list, \@group_list); - } + send_console_notification($pa_config, $dbh, $field3, $field4, \@user_list, \@group_list); } else { logger($pa_config, "Failed action '" . $action->{'name'} . "' for alert '". $alert->{'name'} . "' agent '" . (defined($agent) ? $agent->{'alias'} : 'N/A') . "' Empty targets. Ignored.", 3); } @@ -1860,6 +1849,40 @@ sub pandora_execute_action ($$$$$$$$$;$$) { } } +########################################################################## +=head2 C<< send_console_notification (I<$pa_config>, I<$dbh>, I<$subject>, I<$message>, I<$user_list>, I<$group_list>) >> + +Send message (with subject) to given userlist and/ or group list. + +=cut +########################################################################## +sub send_console_notification { + my ($pa_config, $dbh, $subject, $message, $user_list, $group_list) = @_; + + my $notification = {}; + + $notification->{'subject'} = safe_input($subject); + $notification->{'mensaje'} = safe_input($message); + $notification->{'id_source'} = get_db_value($dbh, + 'SELECT id FROM tnotification_source WHERE description = ?', + safe_input('System status') + ); + + # Create message + my $notification_id = db_process_insert($dbh, 'id_mensaje', 'tmensajes', $notification); + if (!$notification_id) { + logger($pa_config, "Cannot send notification '" . $subject . "'", 3); + } else { + notification_set_targets( + $pa_config, + $dbh, + $notification_id, + $user_list, + $group_list + ); + } +} + ########################################################################## =head2 C<< pandora_access_update (I<$pa_config>, I<$agent_id>, I<$dbh>) >> diff --git a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm index 55e52ac1e8..e3299cca05 100644 --- a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm +++ b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm @@ -251,6 +251,7 @@ sub data_consumer ($$) { } my $recon = new PandoraFMS::Recon::Base( + parent => $self, communities => \@communities, dbh => $dbh, group_id => $task->{'id_group'}, @@ -1727,6 +1728,16 @@ sub PandoraFMS::Recon::Base::delete_connections($) { sub PandoraFMS::Recon::Base::message($$$) { my ($self, $message, $verbosity) = @_; + if ($verbosity <= 1) { + PandoraFMS::Core::send_console_notification( + $self->{'pa_config'}, + $self->{'parent'}->getDBH(), + "[Recon task " . $self->{'task_id'} . "]", + $message, + ['admin'] + ) + } + logger($self->{'pa_config'}, "[Recon task " . $self->{'task_id'} . "] $message", $verbosity); }