Merge branch 'ent-3431-discovery-host-devices' of brutus.artica.lan:artica/pandorafms into ent-3431-discovery-host-devices

Former-commit-id: 7b45b6f2d34e1592b9898dc94c826d138e2b6e63
This commit is contained in:
manuel 2019-02-19 08:59:41 +01:00
commit 8ac1642dea
6 changed files with 97 additions and 31 deletions

View File

@ -96,6 +96,10 @@ if (get_parameter('check_new_notifications', 0)) {
return; return;
} }
if (messages_get_count() == 0) {
return;
}
$messages = messages_get_overview( $messages = messages_get_overview(
'timestamp', 'timestamp',
'ASC', 'ASC',

View File

@ -315,6 +315,9 @@ class HostDevices extends Wizard
} }
$id_network_profile = get_parameter('id_network_profile', null); $id_network_profile = get_parameter('id_network_profile', null);
$autoconf_enabled = get_parameter_switch(
'autoconfiguration_enabled'
);
$snmp_enabled = get_parameter_switch('snmp_enabled'); $snmp_enabled = get_parameter_switch('snmp_enabled');
$os_detect = get_parameter_switch('os_detect'); $os_detect = get_parameter_switch('os_detect');
$parent_detection = get_parameter_switch('parent_detection'); $parent_detection = get_parameter_switch('parent_detection');
@ -339,6 +342,7 @@ class HostDevices extends Wizard
$this->task['snmp_community'] = $community; $this->task['snmp_community'] = $community;
} }
$this->task['autoconfiguration_enabled'] = $autoconf_enabled;
$this->task['id_network_profile'] = $id_network_profile; $this->task['id_network_profile'] = $id_network_profile;
$this->task['snmp_enabled'] = $snmp_enabled; $this->task['snmp_enabled'] = $snmp_enabled;
$this->task['os_detect'] = $os_detect; $this->task['os_detect'] = $os_detect;

View File

@ -356,42 +356,59 @@ function messages_get_count(
if (!empty($incl_read)) { if (!empty($incl_read)) {
// Do not filter. // Do not filter.
$read = ''; $read = ' 1=1 ';
} else { } else {
// Retrieve only unread messages. // Retrieve only unread messages.
$read = 'where t.read is null'; $read = ' t.read is null';
} }
if ($ignore_source === true) { if ($ignore_source === true) {
$source_select = '';
$source_sql = ''; $source_sql = '';
$source_extra = '';
} else { } else {
$source_sql = 'INNER JOIN tnotification_source ns $source_select = ',IF(ns.user_editable,nsu.enabled,ns.enabled) as enabled';
ON tm.id_source = ns.id
AND ns.enabled = 1'; // 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( $sql = sprintf(
'SELECT count(*) FROM ( 'SELECT count(*) as "n" FROM (
SELECT DISTINCT tm.*, utimestamp_read > 0 as "read" SELECT
FROM tmensajes tm tm.*,
%s utimestamp_read > 0 as "read"
LEFT JOIN tnotification_user nu %s
ON tm.id_mensaje=nu.id_mensaje FROM tmensajes tm
AND nu.id_user="%s" %s
LEFT JOIN (tnotification_group ng LEFT JOIN tnotification_user nu
INNER JOIN tusuario_perfil up ON tm.id_mensaje=nu.id_mensaje
ON ng.id_group=up.id_grupo AND nu.id_user="%s"
AND up.id_grupo=ng.id_group LEFT JOIN (tnotification_group ng
) ON tm.id_mensaje=ng.id_mensaje 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 WHERE utimestamp_erased is null
AND (nu.id_user="%s" OR up.id_usuario="%s" OR ng.id_group=0) AND (nu.id_user="%s" OR up.id_usuario="%s" OR ng.id_group=0)
) t ) t
%s', WHERE %s %s',
$source_select,
$source_sql, $source_sql,
$user, $user,
$user, $user,
$user, $user,
$read $read,
$source_extra
); );
return (int) db_get_sql($sql); return (int) db_get_sql($sql);
@ -478,7 +495,11 @@ function messages_get_overview(
if ($incl_source_info) { if ($incl_source_info) {
$source_fields = ', tns.*'; $source_fields = ', tns.*';
$source_join = 'INNER JOIN tnotification_source 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. // Using distinct because could be double assignment due group/user.

View File

@ -525,7 +525,7 @@ function notifications_build_user_enable_return($status, $enabled)
function notifications_get_user_label_status($source, $user, $label) function notifications_get_user_label_status($source, $user, $label)
{ {
// If not enabled, it cannot be modificable. // If not enabled, it cannot be modificable.
if (!$source['enabled'] || !$source[$label]) { if (!$source['enabled']) {
return notifications_build_user_enable_return(false, false); 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. // No group found, return no permissions.
$value = empty($common_groups) ? false : $source[$label]; $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]); $source_info = notifications_get_all_sources(['id' => $source]);
if (!isset($source_info[0]) if (!isset($source_info[0])
|| !$source_info[0]['enabled'] || !$source_info[0]['enabled']
|| !$source_info[0][$label]
|| !$source_info[0]['user_editable'] || !$source_info[0]['user_editable']
) { ) {
return false; return false;

View File

@ -179,6 +179,7 @@ our @EXPORT = qw(
pandora_evaluate_alert pandora_evaluate_alert
pandora_evaluate_snmp_alerts pandora_evaluate_snmp_alerts
pandora_event pandora_event
pandora_extended_event
pandora_execute_alert pandora_execute_alert
pandora_execute_action pandora_execute_action
pandora_exec_forced_alerts pandora_exec_forced_alerts
@ -3270,11 +3271,11 @@ sub pandora_event ($$$$$$$$$$;$$$$$$$$$$$) {
# Create the event # Create the event
logger($pa_config, "Generating event '$evento' for agent ID $id_agente module ID $id_agentmodule.", 10); 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); 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 # 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 # Add a header when the event file is created
my $header = undef; my $header = undef;
@ -3285,7 +3286,7 @@ sub pandora_event ($$$$$$$$$$;$$$$$$$$$$$) {
# Open the event file for writing # Open the event file for writing
if (! open (EVENT_FILE, '>>' . $pa_config->{'event_file'})) { if (! open (EVENT_FILE, '>>' . $pa_config->{'event_file'})) {
logger($pa_config, "Error opening event file " . $pa_config->{'event_file'} . ": $!", 10); logger($pa_config, "Error opening event file " . $pa_config->{'event_file'} . ": $!", 10);
return; return $event_id;
} }
# Resolve ids # 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"; 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); 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)
);
} }
########################################################################## ##########################################################################

View File

@ -163,6 +163,8 @@ sub data_consumer ($$) {
@auth_strings = split(/,/, safe_output($task->{'auth_strings'})); @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( my $recon = new PandoraFMS::Recon::Base(
communities => \@communities, communities => \@communities,
dbh => $dbh, dbh => $dbh,
@ -190,7 +192,8 @@ sub data_consumer ($$) {
vlan_cache_enabled => $task->{'vlan_enabled'}, vlan_cache_enabled => $task->{'vlan_enabled'},
wmi_enabled => $task->{'wmi_enabled'}, wmi_enabled => $task->{'wmi_enabled'},
auth_strings_array => \@auth_strings, auth_strings_array => \@auth_strings,
autoconfigure_agent => $task->{'autoconfiguration_enabled'} autoconfiguration_enabled => $task->{'autoconfiguration_enabled'},
main_event_id => $main_event,
%{$pa_config} %{$pa_config}
); );
@ -451,10 +454,18 @@ sub PandoraFMS::Recon::Base::create_agent($$) {
if (defined($self->{'autoconfiguration_enabled'}) && $self->{'autoconfiguration_enabled'} == 1) { 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); 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. # 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; $agent_learning = 1;
# Create network profile modules for the agent # Create network profile modules for the agent