This commit is contained in:
fbsanchez 2020-03-19 18:33:04 +01:00
parent 32c6e7f30c
commit 17eae7d97f
4 changed files with 58 additions and 26 deletions

View File

@ -945,6 +945,14 @@ class DiscoveryTaskList extends HTML
$str = __('Executing custom queries...'); $str = __('Executing custom queries...');
break; break;
case STEP_MONITORING:
$str = __('Testing modules...');
break;
case STEP_PROCESSING:
$str = __('Processing results...');
break;
default: default:
$str = ''; $str = '';
break; break;
@ -1173,6 +1181,10 @@ class DiscoveryTaskList extends HTML
array_reduce( array_reduce(
$data['modules'], $data['modules'],
function ($carry, $item) use ($id, $agent_id) { function ($carry, $item) use ($id, $agent_id) {
if (empty($item['name'])) {
$item['name'] = $item['nombre'];
}
if ($item['name'] == 'Host Alive') { if ($item['name'] == 'Host Alive') {
return $carry; return $carry;
} }
@ -1291,20 +1303,19 @@ class DiscoveryTaskList extends HTML
// Modules. // Modules.
if (is_array($data['modules'])) { if (is_array($data['modules'])) {
$n_modules = count($data['modules']); $n_modules = count($data['modules']);
for ($i = 0; $i < $n_modules; $i++) { foreach ($data['modules'] as $module_name => $module) {
$module_name = $data['modules'][$i]['name'];
if (in_array($agent_name.'-'.$module_name, $ids)) { if (in_array($agent_name.'-'.$module_name, $ids)) {
if ($data['modules'][$i]['checked'] != 1) { if ($data['modules'][$module_name]['checked'] != 1) {
$summary[] = '<li class="added">'.$agent_name.' - '.$module_name.'</li>'; $summary[] = '<li class="added">'.$agent_name.' - '.$module_name.'</li>';
} }
$data['modules'][$i]['checked'] = 1; $data['modules'][$module_name]['checked'] = 1;
} else { } else {
if ($data['modules'][$i]['checked'] == 1) { if ($data['modules'][$module_name]['checked'] == 1) {
$summary[] = '<li class="removed">'.__('Removed').' '.$agent_name.' - '.$module_name.'</li>'; $summary[] = '<li class="removed">'.__('Removed').' '.$agent_name.' - '.$module_name.'</li>';
} }
$data['modules'][$i]['checked'] = 0; $data['modules'][$module_name]['checked'] = 0;
} }
} }
} }
@ -1338,7 +1349,6 @@ class DiscoveryTaskList extends HTML
], ],
['id_rt' => $id_task] ['id_rt' => $id_task]
); );
$out .= __('Summary'); $out .= __('Summary');
$out .= '<ul>'; $out .= '<ul>';
$out .= join('', $summary); $out .= join('', $summary);

View File

@ -527,6 +527,8 @@ define('STEP_SCANNING', 1);
define('STEP_AFT', 2); define('STEP_AFT', 2);
define('STEP_TRACEROUTE', 3); define('STEP_TRACEROUTE', 3);
define('STEP_GATEWAY', 4); define('STEP_GATEWAY', 4);
define('STEP_MONITORING', 5);
define('STEP_PROCESSING', 6);
define('STEP_STATISTICS', 1); define('STEP_STATISTICS', 1);
define('STEP_APP_SCAN', 2); define('STEP_APP_SCAN', 2);
define('STEP_CUSTOM_QUERIES', 3); define('STEP_CUSTOM_QUERIES', 3);

View File

@ -40,9 +40,6 @@ use PandoraFMS::ProducerConsumerServer;
use PandoraFMS::GIS; use PandoraFMS::GIS;
use PandoraFMS::Recon::Base; use PandoraFMS::Recon::Base;
# Patched Nmap::Parser. See http://search.cpan.org/dist/Nmap-Parser/.
use PandoraFMS::NmapParser;
# Inherits from PandoraFMS::ProducerConsumerServer # Inherits from PandoraFMS::ProducerConsumerServer
our @ISA = qw(PandoraFMS::ProducerConsumerServer); our @ISA = qw(PandoraFMS::ProducerConsumerServer);
@ -62,7 +59,7 @@ use constant {
STEP_TRACEROUTE => 3, STEP_TRACEROUTE => 3,
STEP_GATEWAY => 4, STEP_GATEWAY => 4,
STEP_MONITORING => 5, STEP_MONITORING => 5,
STEP_APPLY => 6, STEP_PROCESSING => 6,
STEP_STATISTICS => 1, STEP_STATISTICS => 1,
STEP_APP_SCAN => 2, STEP_APP_SCAN => 2,
STEP_CUSTOM_QUERIES => 3, STEP_CUSTOM_QUERIES => 3,
@ -360,9 +357,14 @@ sub exec_recon_script ($$$) {
} }
my $ent_script = 0; my $ent_script = 0;
my $args = enterprise_hook('discovery_custom_recon_scripts',[$pa_config, $dbh, $task, $script]); my $args = enterprise_hook(
'discovery_custom_recon_scripts',
[$pa_config, $dbh, $task, $script]
);
if (!$args) { if (!$args) {
$args = "$task->{'id_rt'} $task->{'id_group'} $task->{'create_incident'} $macros_parameters"; $args = '"'.$task->{'id_rt'}.'" ';
$args .= '"'.$task->{'id_group'}.'" ';
$args .= $macros_parameters;
} else { } else {
$ent_script = 1; $ent_script = 1;
} }
@ -691,7 +693,16 @@ sub PandoraFMS::Recon::Base::report_scanned_agents($) {
my $agent_id = $data->{'agent'}{'agent_id'}; my $agent_id = $data->{'agent'}{'agent_id'};
my $agent_learning = 1; my $agent_learning = 1;
if (!defined($agent_id) || $agent_id == 0) { if (defined($agent_id) || $agent_id > 0) {
$agent_learning = get_db_value(
$self->{'dbh'},
'SELECT modo FROM tagente WHERE id_agente = ?',
$agent_id
);
}
if (!defined($agent_learning)) {
# Agent id does not exists or is invalid.
$agent_id = pandora_create_agent( $agent_id = pandora_create_agent(
$self->{'pa_config'}, $self->{'servername'}, $data->{'agent'}{'nombre'}, $self->{'pa_config'}, $self->{'servername'}, $data->{'agent'}{'nombre'},
$data->{'agent'}{'direccion'}, $self->{'task_data'}{'group_id'}, $parent_id, $data->{'agent'}{'direccion'}, $self->{'task_data'}{'group_id'}, $parent_id,
@ -702,13 +713,6 @@ sub PandoraFMS::Recon::Base::report_scanned_agents($) {
$data->{'agent'}{'agent_id'} = $agent_id; $data->{'agent'}{'agent_id'} = $agent_id;
$agent_learning = 1; $agent_learning = 1;
} else {
$agent_learning = get_db_value(
$self->{'dbh'},
'SELECT modo FROM tagente WHERE id_agente = ?',
$agent_id
);
} }
$self->call('message', "Agent id: ".$data->{'agent'}{'agent_id'}, 5); $self->call('message', "Agent id: ".$data->{'agent'}{'agent_id'}, 5);
@ -725,10 +729,24 @@ 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'};
if (!defined($agentmodule_id) || $agentmodule_id == 0) {
if (defined($agentmodule_id) && $agentmodule_id > 0) {
$agentmodule_id = get_db_value(
$self->{'dbh'},
'SELECT id_agente_modulo FROM tagente_modulo
WHERE id_agente_modulo = ? AND nombre = ?',
$agentmodule_id,
safe_input($module->{'name'})
);
}
if (!is_enabled($agentmodule_id)) {
# Create.
if (is_enabled($module->{'__module_component'})) { if (is_enabled($module->{'__module_component'})) {
# Module from network component. # Module from network component.
@ -809,7 +827,7 @@ sub PandoraFMS::Recon::Base::report_scanned_agents($) {
# #
my @hosts = keys %{$self->{'agents_found'}}; my @hosts = keys %{$self->{'agents_found'}};
$self->{'step'} = STEP_APPLY; $self->{'step'} = STEP_PROCESSING;
my ($progress, $step) = (90, 10.0 / scalar(@hosts)); # From 90% to 100%. my ($progress, $step) = (90, 10.0 / scalar(@hosts)); # From 90% to 100%.
foreach my $label (keys %{$self->{'agents_found'}}) { foreach my $label (keys %{$self->{'agents_found'}}) {
$self->call('update_progress', $progress); $self->call('update_progress', $progress);

View File

@ -23,7 +23,7 @@ use constant {
STEP_TRACEROUTE => 3, STEP_TRACEROUTE => 3,
STEP_GATEWAY => 4, STEP_GATEWAY => 4,
STEP_MONITORING => 5, STEP_MONITORING => 5,
STEP_APPLY => 6, STEP_PROCESSING => 6,
STEP_STATISTICS => 1, STEP_STATISTICS => 1,
STEP_APP_SCAN => 2, STEP_APP_SCAN => 2,
STEP_CUSTOM_QUERIES => 3, STEP_CUSTOM_QUERIES => 3,
@ -1884,6 +1884,7 @@ sub scan($) {
# Apply monitoring templates # Apply monitoring templates
$self->call('message', "[5/6] Applying monitoring.", 3); $self->call('message', "[5/6] Applying monitoring.", 3);
$self->{'step'} = STEP_MONITORING;
$self->call('apply_monitoring', $self); $self->call('apply_monitoring', $self);
# Print debug information on found devices. # Print debug information on found devices.
@ -1903,7 +1904,8 @@ sub scan($) {
} }
# Apply monitoring templates # Apply monitoring templates
$self->call('message', "[6/6] Process results.", 3); $self->call('message', "[6/6] Processing results.", 3);
$self->{'step'} = STEP_PROCESSING;
# Send agent information to Database (Discovery) or XML (satellite.). # Send agent information to Database (Discovery) or XML (satellite.).
$self->call('report_scanned_agents', $self->{'agents_found'}); $self->call('report_scanned_agents', $self->{'agents_found'});