minor fixes

This commit is contained in:
fbsanchez 2020-03-23 19:09:22 +01:00
parent c18d339730
commit 23c19856b8
3 changed files with 109 additions and 43 deletions

View File

@ -524,7 +524,9 @@ class DiscoveryTaskList extends HTML
} }
if ($task['direct_report'] == 1) { if ($task['direct_report'] == 1) {
if ($task['status'] <= 0) { if ($task['status'] <= 0
&& empty($task['summary']) === false
) {
$data[5] = __('Done'); $data[5] = __('Done');
} else if ($task['utimestamp'] == 0 } else if ($task['utimestamp'] == 0
&& empty($task['summary']) && empty($task['summary'])
@ -534,7 +536,9 @@ class DiscoveryTaskList extends HTML
$data[5] = __('Pending'); $data[5] = __('Pending');
} }
} else { } else {
if ($task['status'] <= 0 && $task['utimestamp'] > 0) { if ($task['status'] <= 0
&& empty($task['summary']) === false
) {
$data[5] = '<span class="link review" onclick="show_review('.$task['id_rt'].',\''.$task['name'].'\')">'; $data[5] = '<span class="link review" onclick="show_review('.$task['id_rt'].',\''.$task['name'].'\')">';
$data[5] .= __('Review'); $data[5] .= __('Review');
$data[5] .= '</span>'; $data[5] .= '</span>';
@ -1161,14 +1165,11 @@ class DiscoveryTaskList extends HTML
'checked' => $data['agent']['checked'], 'checked' => $data['agent']['checked'],
]; ];
$agent_id = $data['agent']['agent_id']; // Ensure agent_id really exists.
if (empty($agent_id)) { $agent_id = agents_get_agent_id($data['agent']['nombre'], true);
$agent_id = agents_get_agent_id($id, true);
}
if ($agent_id > 0) { if ($agent_id > 0) {
$tmp['disabled'] = 1; $tmp['disabled'] = 1;
$tmp['checked'] = 1;
$tmp['agent_id'] = $agent_id; $tmp['agent_id'] = $agent_id;
} }
@ -1189,6 +1190,10 @@ class DiscoveryTaskList extends HTML
return $carry; return $carry;
} }
if (empty($item['name'])) {
$item['name'] = $item['nombre'];
}
$tmp = [ $tmp = [
'name' => $item['name'], 'name' => $item['name'],
'id' => $id.'-'.$item['name'], 'id' => $id.'-'.$item['name'],
@ -1196,13 +1201,10 @@ class DiscoveryTaskList extends HTML
'checked' => $item['checked'], 'checked' => $item['checked'],
]; ];
$agentmodule_id = $item['agentmodule_id']; $agentmodule_id = $agentmodule_id = modules_get_agentmodule_id(
if (empty($agentmodule_id)) { io_safe_input($item['name']),
$agentmodule_id = modules_get_agentmodule_id( $agent_id
io_safe_input($item['name']), );
$agent_id
);
}
if ($agentmodule_id > 0) { if ($agentmodule_id > 0) {
$tmp['disabled'] = 1; $tmp['disabled'] = 1;
@ -1336,20 +1338,21 @@ class DiscoveryTaskList extends HTML
} }
} }
// Schedule execution.
db_process_sql_update(
'trecon_task',
[
'utimestamp' => 0,
'status' => 1,
'direct_report' => DISCOVERY_RESULTS,
],
['id_rt' => $id_task]
);
if (empty($summary)) { if (empty($summary)) {
$out .= __('No changes'); $out .= __('No changes. Re-Scheduled');
} else { } else {
// Schedule execution. $out .= __('Scheduled for creation');
db_process_sql_update(
'trecon_task',
[
'utimestamp' => 0,
'status' => 1,
'direct_report' => DISCOVERY_RESULTS,
],
['id_rt' => $id_task]
);
$out .= __('Summary');
$out .= '<ul>'; $out .= '<ul>';
$out .= join('', $summary); $out .= join('', $summary);
$out .= '</ul>'; $out .= '</ul>';

View File

@ -671,6 +671,7 @@ sub PandoraFMS::Recon::Base::report_scanned_agents($) {
$self->call('update_progress', $progress); $self->call('update_progress', $progress);
my $name = safe_output($row->{'label'}); my $name = safe_output($row->{'label'});
my $checked = 0;
my $data; my $data;
eval { eval {
local $SIG{__DIE__}; local $SIG{__DIE__};
@ -680,8 +681,28 @@ sub PandoraFMS::Recon::Base::report_scanned_agents($) {
$self->call('message', "ERROR JSON: $@", 3); $self->call('message', "ERROR JSON: $@", 3);
} }
# Agent could be 'not checked' unless all modules are selected.
if (ref($data->{'modules'}) eq 'HASH') {
my @map = map {
my $name = $_->{'name'};
$name = $_->{'nombre'} if is_empty($name);
if (is_enabled($_->{'checked'})
&& $name ne 'Host Alive'
) {
$name;
} else {}
} values %{$data->{'modules'}};
$checked = scalar @map;
}
$checked = $data->{'agent'}{'checked'}
if $checked < $data->{'agent'}{'checked'};
# Register target agent if enabled. # Register target agent if enabled.
if (is_enabled($data->{'agent'}{'checked'}) if (is_enabled($checked)
|| $force_creation || $force_creation
) { ) {
my $parent_id; my $parent_id;
@ -691,9 +712,9 @@ sub PandoraFMS::Recon::Base::report_scanned_agents($) {
# Agent creation. # Agent creation.
my $agent_id = $data->{'agent'}{'agent_id'}; my $agent_id = $data->{'agent'}{'agent_id'};
my $agent_learning = 1; my $agent_learning;
if (defined($agent_id) || $agent_id > 0) { if (defined($agent_id) && $agent_id > 0) {
$agent_learning = get_db_value( $agent_learning = get_db_value(
$self->{'dbh'}, $self->{'dbh'},
'SELECT modo FROM tagente WHERE id_agente = ?', 'SELECT modo FROM tagente WHERE id_agente = ?',
@ -703,17 +724,36 @@ sub PandoraFMS::Recon::Base::report_scanned_agents($) {
if (!defined($agent_learning)) { if (!defined($agent_learning)) {
# Agent id does not exists or is invalid. # Agent id does not exists or is invalid.
$agent_id = pandora_create_agent(
$self->{'pa_config'}, $self->{'servername'}, $data->{'agent'}{'nombre'}, # Check if has been created by another process.
$data->{'agent'}{'direccion'}, $self->{'task_data'}{'group_id'}, $parent_id, $agent_id = get_db_value(
$os_id, $data->{'agent'}->{'description'}, $self->{'dbh'},
$data->{'agent'}{'interval'}, $self->{'dbh'}, 'SELECT id_agente FROM tagente WHERE nombre = ?',
$data->{'agent'}{'timezone_offset'} safe_input($data->{'agent'}->{'name'})
); );
if (!defined($agent_id) || $agent_id <= 0) {
$agent_id = pandora_create_agent(
$self->{'pa_config'}, $self->{'servername'}, $data->{'agent'}{'nombre'},
$data->{'agent'}{'direccion'}, $self->{'task_data'}{'group_id'}, $parent_id,
$os_id, $data->{'agent'}->{'description'},
$data->{'agent'}{'interval'}, $self->{'dbh'},
$data->{'agent'}{'timezone_offset'}
);
$agent_learning = 1;
} else {
# Read from effective agent_id.
$agent_learning = get_db_value(
$self->{'dbh'},
'SELECT modo FROM tagente WHERE id_agente = ?',
$agent_id
);
}
$data->{'agent'}{'agent_id'} = $agent_id; $data->{'agent'}{'agent_id'} = $agent_id;
$agent_learning = 1;
} }
$self->call('message', "Agent id: ".$data->{'agent'}{'agent_id'}, 5); $self->call('message', "Agent id: ".$data->{'agent'}{'agent_id'}, 5);
# Create selected modules. # Create selected modules.
@ -721,6 +761,8 @@ sub PandoraFMS::Recon::Base::report_scanned_agents($) {
foreach my $i (keys %{$data->{'modules'}}) { foreach my $i (keys %{$data->{'modules'}}) {
my $module = $data->{'modules'}{$i}; my $module = $data->{'modules'}{$i};
$module->{'name'} = $module->{'nombre'} if is_empty($module->{'name'});
# Do not create any modules if the agent is not in learning mode. # Do not create any modules if the agent is not in learning mode.
next unless ($agent_learning == 1); next unless ($agent_learning == 1);
@ -729,8 +771,6 @@ sub PandoraFMS::Recon::Base::report_scanned_agents($) {
next unless (is_enabled($module->{'checked'}) || $force_creation); next unless (is_enabled($module->{'checked'}) || $force_creation);
} }
delete $module->{'checked'};
$self->call('message', "[$agent_id] Module: ".$module->{'name'}, 5); $self->call('message', "[$agent_id] Module: ".$module->{'name'}, 5);
my $agentmodule_id = $module->{'agentmodule_id'}; my $agentmodule_id = $module->{'agentmodule_id'};
@ -748,24 +788,42 @@ sub PandoraFMS::Recon::Base::report_scanned_agents($) {
if (!is_enabled($agentmodule_id)) { if (!is_enabled($agentmodule_id)) {
# Create. # Create.
# Delete unwanted fields.
delete $module->{'agentmodule_id'};
delete $module->{'checked'};
my $id_tipo_modulo = $module->{'id_tipo_modulo'};
$id_tipo_modulo = get_module_id($self->{'dbh'}, $module->{'type'})
if is_empty($id_tipo_modulo);
my $description = safe_output($module->{'description'});
$description = '' if is_empty($description);
if (is_enabled($module->{'__module_component'})) { if (is_enabled($module->{'__module_component'})) {
# Module from network component. # Module from network component.
delete $module->{'__module_component'}; delete $module->{'__module_component'};
$agentmodule_id = pandora_create_module_from_network_component( $agentmodule_id = pandora_create_module_from_network_component(
$self->{'pa_config'}, $self->{'pa_config'},
$module, # Send a copy, not original, because of 'deletes'
{
%{$module},
'name' => safe_input($module->{'name'}),
},
$agent_id, $agent_id,
$self->{'dbh'} $self->{'dbh'}
); );
# Restore.
$module->{'__module_component'} = 1;
} else { } else {
# Create module - Direct. # Create module - Direct.
$agentmodule_id = pandora_create_module_from_hash( $agentmodule_id = pandora_create_module_from_hash(
$self->{'pa_config'}, $self->{'pa_config'},
{ {
'id_tipo_modulo' => get_module_id($self->{'dbh'}, $module->{'type'}), 'id_tipo_modulo' => $id_tipo_modulo,
'id_modulo' => $module->{'id_modulo'}, 'id_modulo' => $module->{'id_modulo'},
'nombre' => safe_input($module->{'name'}), 'nombre' => safe_input($module->{'name'}),
'descripcion' => '', 'descripcion' => safe_input($description),
'id_agente' => $agent_id, 'id_agente' => $agent_id,
'ip_target' => $data->{'agent'}{'direccion'} 'ip_target' => $data->{'agent'}{'direccion'}
}, },
@ -773,6 +831,9 @@ sub PandoraFMS::Recon::Base::report_scanned_agents($) {
); );
} }
# Restore.
$module->{'checked'} = 1;
# Store. # Store.
$data->{'modules'}{$i}{'agentmodule_id'} = $agentmodule_id; $data->{'modules'}{$i}{'agentmodule_id'} = $agentmodule_id;

View File

@ -470,7 +470,9 @@ sub exec_network_module ($$$$) {
my $retries = $module->{'max_retries'}; my $retries = $module->{'max_retries'};
my $target_os = pandora_get_os($dbh, $module->{'custom_string_2'}); my $target_os = pandora_get_os($dbh, $module->{'custom_string_2'});
if ($module->{'custom_string_2'} eq "inherited" ) { if (defined($module->{'custom_string_2'})
&& $module->{'custom_string_2'} eq "inherited"
) {
$target_os = $agent_row->{'id_os'}; $target_os = $agent_row->{'id_os'};
} elsif (!defined($target_os) || "$target_os" eq '0') { } elsif (!defined($target_os) || "$target_os" eq '0') {
$target_os = $agent_row->{'id_os'}; $target_os = $agent_row->{'id_os'};