diff --git a/pandora_console/godmode/setup/setup_notifications.php b/pandora_console/godmode/setup/setup_notifications.php index 28c336aa92..9ee95f78cc 100644 --- a/pandora_console/godmode/setup/setup_notifications.php +++ b/pandora_console/godmode/setup/setup_notifications.php @@ -96,6 +96,10 @@ if (get_parameter('check_new_notifications', 0)) { return; } + if (messages_get_count() == 0) { + return; + } + $messages = messages_get_overview( 'timestamp', 'ASC', diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index 2dd29d923c..8dcf6d9a1e 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -315,6 +315,9 @@ class HostDevices extends Wizard } $id_network_profile = get_parameter('id_network_profile', null); + $autoconf_enabled = get_parameter_switch( + 'autoconfiguration_enabled' + ); $snmp_enabled = get_parameter_switch('snmp_enabled'); $os_detect = get_parameter_switch('os_detect'); $parent_detection = get_parameter_switch('parent_detection'); @@ -339,6 +342,7 @@ class HostDevices extends Wizard $this->task['snmp_community'] = $community; } + $this->task['autoconfiguration_enabled'] = $autoconf_enabled; $this->task['id_network_profile'] = $id_network_profile; $this->task['snmp_enabled'] = $snmp_enabled; $this->task['os_detect'] = $os_detect; diff --git a/pandora_console/include/functions_messages.php b/pandora_console/include/functions_messages.php index a67bcb56e1..3fb907ab06 100644 --- a/pandora_console/include/functions_messages.php +++ b/pandora_console/include/functions_messages.php @@ -356,42 +356,59 @@ function messages_get_count( if (!empty($incl_read)) { // Do not filter. - $read = ''; + $read = ' 1=1 '; } else { // Retrieve only unread messages. - $read = 'where t.read is null'; + $read = ' t.read is null'; } if ($ignore_source === true) { + $source_select = ''; $source_sql = ''; + $source_extra = ''; } else { - $source_sql = 'INNER JOIN tnotification_source ns - ON tm.id_source = ns.id - AND ns.enabled = 1'; + $source_select = ',IF(ns.user_editable,nsu.enabled,ns.enabled) as enabled'; + + // Row in tnotification_source_user could exist or not. + $source_sql = sprintf( + 'INNER JOIN ( + tnotification_source ns + LEFT JOIN tnotification_source_user nsu + ON ns.id=nsu.id_source + AND nsu.id_user="test") + ON tm.id_source=ns.id', + $user + ); + $source_extra = 'AND (t.enabled=1 OR t.enabled is null)'; } $sql = sprintf( - 'SELECT count(*) FROM ( - SELECT DISTINCT tm.*, utimestamp_read > 0 as "read" - FROM tmensajes tm - %s - LEFT JOIN tnotification_user nu - ON tm.id_mensaje=nu.id_mensaje - AND nu.id_user="%s" - LEFT JOIN (tnotification_group ng - INNER JOIN tusuario_perfil up - ON ng.id_group=up.id_grupo - AND up.id_grupo=ng.id_group - ) ON tm.id_mensaje=ng.id_mensaje + 'SELECT count(*) as "n" FROM ( + SELECT + tm.*, + utimestamp_read > 0 as "read" + %s + FROM tmensajes tm + %s + LEFT JOIN tnotification_user nu + ON tm.id_mensaje=nu.id_mensaje + AND nu.id_user="%s" + LEFT JOIN (tnotification_group ng + INNER JOIN tusuario_perfil up + ON ng.id_group=up.id_grupo + AND up.id_grupo=ng.id_group) + ON tm.id_mensaje=ng.id_mensaje WHERE utimestamp_erased is null AND (nu.id_user="%s" OR up.id_usuario="%s" OR ng.id_group=0) - ) t - %s', + ) t + WHERE %s %s', + $source_select, $source_sql, $user, $user, $user, - $read + $read, + $source_extra ); return (int) db_get_sql($sql); @@ -478,7 +495,11 @@ function messages_get_overview( if ($incl_source_info) { $source_fields = ', tns.*'; $source_join = 'INNER JOIN tnotification_source tns - ON tns.id=tm.id_source'; + ON tns.id=tm.id_source + INNER JOIN tnotification_source_user nsu + ON nsu.id_source=tns.id + AND nsu.enabled = 1 + OR tns.enabled = 1'; } // Using distinct because could be double assignment due group/user. diff --git a/pandora_console/include/functions_notifications.php b/pandora_console/include/functions_notifications.php index 23b1a90e70..26dcc248c5 100644 --- a/pandora_console/include/functions_notifications.php +++ b/pandora_console/include/functions_notifications.php @@ -525,7 +525,7 @@ function notifications_build_user_enable_return($status, $enabled) function notifications_get_user_label_status($source, $user, $label) { // If not enabled, it cannot be modificable. - if (!$source['enabled'] || !$source[$label]) { + if (!$source['enabled']) { return notifications_build_user_enable_return(false, false); } @@ -551,7 +551,10 @@ function notifications_get_user_label_status($source, $user, $label) ); // No group found, return no permissions. $value = empty($common_groups) ? false : $source[$label]; - return notifications_build_user_enable_return($value, false); + return notifications_build_user_enable_return( + $value, + false + ); } @@ -570,7 +573,6 @@ function notifications_set_user_label_status($source, $user, $label, $value) $source_info = notifications_get_all_sources(['id' => $source]); if (!isset($source_info[0]) || !$source_info[0]['enabled'] - || !$source_info[0][$label] || !$source_info[0]['user_editable'] ) { return false; diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index ba9ddbeae8..84f16b5362 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -179,6 +179,7 @@ our @EXPORT = qw( pandora_evaluate_alert pandora_evaluate_snmp_alerts pandora_event + pandora_extended_event pandora_execute_alert pandora_execute_action pandora_exec_forced_alerts @@ -3270,11 +3271,11 @@ sub pandora_event ($$$$$$$$$$;$$$$$$$$$$$) { # Create the event logger($pa_config, "Generating event '$evento' for agent ID $id_agente module ID $id_agentmodule.", 10); - db_do ($dbh, 'INSERT INTO ' . $event_table . ' (id_agente, id_grupo, evento, timestamp, estado, utimestamp, event_type, id_agentmodule, id_alert_am, criticity, user_comment, tags, source, id_extra, id_usuario, critical_instructions, warning_instructions, unknown_instructions, ack_utimestamp, custom_data, data, module_status) + my $event_id = db_insert ($dbh, 'id_evento','INSERT INTO ' . $event_table . ' (id_agente, id_grupo, evento, timestamp, estado, utimestamp, event_type, id_agentmodule, id_alert_am, criticity, user_comment, tags, source, id_extra, id_usuario, critical_instructions, warning_instructions, unknown_instructions, ack_utimestamp, custom_data, data, module_status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $id_agente, $id_grupo, safe_input ($evento), $timestamp, $event_status, $utimestamp, $event_type, $id_agentmodule, $id_alert_am, $severity, $comment, $module_tags, $source, $id_extra, $user_name, $critical_instructions, $warning_instructions, $unknown_instructions, $ack_utimestamp, $custom_data, $module_data, $module_status); - + # Do not write to the event file - return if ($pa_config->{'event_file'} eq ''); + return $event_id if ($pa_config->{'event_file'} eq ''); # Add a header when the event file is created my $header = undef; @@ -3285,7 +3286,7 @@ sub pandora_event ($$$$$$$$$$;$$$$$$$$$$$) { # Open the event file for writing if (! open (EVENT_FILE, '>>' . $pa_config->{'event_file'})) { logger($pa_config, "Error opening event file " . $pa_config->{'event_file'} . ": $!", 10); - return; + return $event_id; } # Resolve ids @@ -3308,6 +3309,29 @@ sub pandora_event ($$$$$$$$$$;$$$$$$$$$$$) { print EVENT_FILE "$agent_name,".safe_output($group_name)."," . safe_output ($evento) . ",$timestamp,$event_status,$utimestamp,$event_type,".safe_output($module_name).",".safe_output($alert_name).",$severity,".safe_output($comment).",".safe_output($module_tags).",$source,$id_extra,$user_name,".safe_output($critical_instructions).",".safe_output($warning_instructions).",".safe_output($unknown_instructions).",$ack_utimestamp\n"; close (EVENT_FILE); + + return $event_id; +} + +########################################################################## +=head2 C<< pandora_extended_event (I<$pa_config>, I<$dbh>, I<$event_id>, I<$description>) >> + +Creates an extended event linked to an existing main event id. + +=cut +########################################################################## +sub pandora_extended_event($$$$) { + my ($pa_config, $dbh, $event_id, $description) = @_; + + return unless defined($event_id) && "$event_id" ne "" && $event_id > 0; + + return db_do( + $dbh, + 'INSERT INTO tevent_extended (id_evento, utimestamp, description) VALUES (?,?,?)', + $event_id, + time(), + safe_input($description) + ); } ########################################################################## diff --git a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm index b6423a8506..8911d353e3 100644 --- a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm +++ b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm @@ -163,6 +163,8 @@ sub data_consumer ($$) { @auth_strings = split(/,/, safe_output($task->{'auth_strings'})); } + my $main_event = pandora_event($pa_config, "[Discovery] Execution summary",$task->{'id_group'}, 0, 0, 0, 0, 'system', 0, $dbh); + my $recon = new PandoraFMS::Recon::Base( communities => \@communities, dbh => $dbh, @@ -190,7 +192,8 @@ sub data_consumer ($$) { vlan_cache_enabled => $task->{'vlan_enabled'}, wmi_enabled => $task->{'wmi_enabled'}, auth_strings_array => \@auth_strings, - autoconfigure_agent => $task->{'autoconfiguration_enabled'} + autoconfiguration_enabled => $task->{'autoconfiguration_enabled'}, + main_event_id => $main_event, %{$pa_config} ); @@ -451,10 +454,18 @@ sub PandoraFMS::Recon::Base::create_agent($$) { if (defined($self->{'autoconfiguration_enabled'}) && $self->{'autoconfiguration_enabled'} == 1) { my $agent_data = PandoraFMS::DB::get_db_single_row($self->{'dbh'}, 'SELECT * FROM tagente WHERE id_agente = ?', $agent_id); # Update agent configuration once, after create agent. - enterprise_hook('autoconfigure_agent', [$self->{'pa_config'}, $host_name, $agent_id, $agent_data, $self->{'dbh'}]); + enterprise_hook('autoconfigure_agent', [$self->{'pa_config'}, $host_name, $agent_id, $agent_data, $self->{'dbh'}, $agent_id]); + } + + if (defined($self->{'main_event_id'})) { + my $addresses_str = join(',', safe_output($self->get_addresses($device))); + pandora_extended_event( + $self->{'pa_config'}, $self->{'dbh'}, $self->{'main_event_id'}, + "[Discovery] New " . safe_output($self->get_device_type($device)) . " found " . $host_name . " (" . $addresses_str . ") Agent $agent_id." + ); + } - pandora_event($self->{'pa_config'}, "[RECON] New " . safe_output($self->get_device_type($device)) . " found (" . join(',', safe_output($self->get_addresses($device))) . ").", $self->{'group_id'}, $agent_id, 2, 0, 0, 'recon_host_detected', 0, $self->{'dbh'}); $agent_learning = 1; # Create network profile modules for the agent