mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-23 22:05:41 +02:00
Templates
This commit is contained in:
parent
6504fe49b5
commit
f58276ddbb
@ -10,7 +10,7 @@ CREATE TABLE `tdiscovery_tmp_agents` (
|
|||||||
`label` varchar(600) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',
|
`label` varchar(600) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',
|
||||||
`data` text,
|
`data` text,
|
||||||
`review_date` datetime DEFAULT NULL,
|
`review_date` datetime DEFAULT NULL,
|
||||||
`created` int(1) unsigned NOT NULL DEFAULT '0',
|
`created` datetime DEFAULT NULL,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `id_rt` (`id_rt`),
|
KEY `id_rt` (`id_rt`),
|
||||||
INDEX `label` (`label`),
|
INDEX `label` (`label`),
|
||||||
|
@ -1672,7 +1672,7 @@ CREATE TABLE `tdiscovery_tmp_agents` (
|
|||||||
`label` varchar(600) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',
|
`label` varchar(600) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',
|
||||||
`data` text,
|
`data` text,
|
||||||
`review_date` datetime DEFAULT NULL,
|
`review_date` datetime DEFAULT NULL,
|
||||||
`created` int(1) unsigned NOT NULL DEFAULT '0',
|
`created` datetime DEFAULT NULL,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `id_rt` (`id_rt`),
|
KEY `id_rt` (`id_rt`),
|
||||||
INDEX `label` (`label`),
|
INDEX `label` (`label`),
|
||||||
|
@ -289,7 +289,7 @@ class DiscoveryTaskList extends HTML
|
|||||||
[
|
[
|
||||||
'utimestamp' => 0,
|
'utimestamp' => 0,
|
||||||
'status' => 1,
|
'status' => 1,
|
||||||
'direct_report' => DISCOVERY_RESULTS,
|
'direct_report' => $direct_report,
|
||||||
],
|
],
|
||||||
['id_rt' => $id]
|
['id_rt' => $id]
|
||||||
);
|
);
|
||||||
@ -526,14 +526,22 @@ class DiscoveryTaskList extends HTML
|
|||||||
if ($task['direct_report'] == 1) {
|
if ($task['direct_report'] == 1) {
|
||||||
if ($task['status'] <= 0) {
|
if ($task['status'] <= 0) {
|
||||||
$data[5] = __('Done');
|
$data[5] = __('Done');
|
||||||
|
} else if ($task['utimestamp'] == 0
|
||||||
|
&& empty($task['summary'])
|
||||||
|
) {
|
||||||
|
$data[5] = __('Not started');
|
||||||
} else {
|
} else {
|
||||||
$data[5] = __('Pending');
|
$data[5] = __('Pending');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($task['status'] <= 0) {
|
if ($task['status'] <= 0 && $task['utimestamp'] > 0) {
|
||||||
$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>';
|
||||||
|
} else if ($task['utimestamp'] == 0
|
||||||
|
&& empty($task['summary'])
|
||||||
|
) {
|
||||||
|
$data[5] = __('Not started');
|
||||||
} else {
|
} else {
|
||||||
$data[5] = __('Searching');
|
$data[5] = __('Searching');
|
||||||
}
|
}
|
||||||
@ -1121,68 +1129,83 @@ class DiscoveryTaskList extends HTML
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$task_data = db_get_row('tdiscovery_tmp_agents', 'id_rt', $id_task);
|
$task_data = db_get_all_rows_filter(
|
||||||
|
'tdiscovery_tmp_agents',
|
||||||
|
['id_rt' => $id_task]
|
||||||
|
);
|
||||||
$task = db_get_row('trecon_task', 'id_rt', $id_task);
|
$task = db_get_row('trecon_task', 'id_rt', $id_task);
|
||||||
|
|
||||||
|
$simple_data = [];
|
||||||
if (is_array($task_data)) {
|
if (is_array($task_data)) {
|
||||||
$data = json_decode(base64_decode($task_data['data']), true);
|
foreach ($task_data as $agent) {
|
||||||
$simple_data = array_reduce(
|
$data = json_decode(base64_decode($agent['data']), true);
|
||||||
$data,
|
|
||||||
function ($carry, $item) {
|
|
||||||
$id = $item['agent']['nombre'];
|
|
||||||
|
|
||||||
$tmp = [
|
if (is_array($data) === false) {
|
||||||
'id' => $id,
|
continue;
|
||||||
'name' => $item['agent']['nombre'],
|
}
|
||||||
'checked' => $item['checked'],
|
|
||||||
];
|
|
||||||
|
|
||||||
if (empty($item['agent']['agent_id'])) {
|
$id = $data['agent']['nombre'];
|
||||||
$agent_id = agents_get_agent_id($id, true);
|
|
||||||
if ($agent_id > 0) {
|
|
||||||
$tmp['disabled'] = 1;
|
|
||||||
$tmp['checked'] = 1;
|
|
||||||
$tmp['agent_id'] = $agent_id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$carry[] = $tmp;
|
// Partial.
|
||||||
$childs = array_reduce(
|
$tmp = [
|
||||||
$item['modules'],
|
'id' => $id,
|
||||||
function ($c, $i) use ($id, $agent_id) {
|
'name' => $id,
|
||||||
$tmp = [
|
'checked' => $data['agent']['checked'],
|
||||||
'name' => $i['name'],
|
];
|
||||||
'id' => $id.'-'.$i['name'],
|
|
||||||
'pid' => $id,
|
$agent_id = $data['agent']['agent_id'];
|
||||||
'checked' => $i['checked'],
|
if (empty($agent_id)) {
|
||||||
];
|
$agent_id = agents_get_agent_id($id, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($agent_id > 0) {
|
||||||
|
$tmp['disabled'] = 1;
|
||||||
|
$tmp['checked'] = 1;
|
||||||
|
$tmp['agent_id'] = $agent_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store.
|
||||||
|
$simple_data[] = $tmp;
|
||||||
|
|
||||||
|
if (is_array($data['modules'])) {
|
||||||
|
$simple_data = array_merge(
|
||||||
|
$simple_data,
|
||||||
|
array_reduce(
|
||||||
|
$data['modules'],
|
||||||
|
function ($carry, $item) use ($id, $agent_id) {
|
||||||
|
if ($item['name'] == 'Host Alive') {
|
||||||
|
return $carry;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tmp = [
|
||||||
|
'name' => $item['name'],
|
||||||
|
'id' => $id.'-'.$item['name'],
|
||||||
|
'pid' => $id,
|
||||||
|
'checked' => $item['checked'],
|
||||||
|
];
|
||||||
|
|
||||||
|
$agentmodule_id = $item['agentmodule_id'];
|
||||||
|
if (empty($agentmodule_id)) {
|
||||||
|
$agentmodule_id = modules_get_agentmodule_id(
|
||||||
|
io_safe_input($item['name']),
|
||||||
|
$agent_id
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (empty($i['agentmodule_id'])) {
|
|
||||||
$agentmodule_id = modules_get_agentmodule_id(
|
|
||||||
io_safe_input($i['name']),
|
|
||||||
$agent_id
|
|
||||||
);
|
|
||||||
if ($agentmodule_id > 0) {
|
if ($agentmodule_id > 0) {
|
||||||
$tmp['disabled'] = 1;
|
$tmp['disabled'] = 1;
|
||||||
$tmp['checked'] = 1;
|
$tmp['checked'] = 1;
|
||||||
$tmp['module_id'] = $agentmodule_id;
|
$tmp['module_id'] = $agentmodule_id;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$c[] = $tmp;
|
$carry[] = $tmp;
|
||||||
return $c;
|
return $carry;
|
||||||
},
|
},
|
||||||
[]
|
[]
|
||||||
|
)
|
||||||
);
|
);
|
||||||
$carry = array_merge(
|
}
|
||||||
$carry,
|
}
|
||||||
$childs
|
|
||||||
);
|
|
||||||
|
|
||||||
return $carry;
|
|
||||||
},
|
|
||||||
[]
|
|
||||||
);
|
|
||||||
|
|
||||||
echo '<div>';
|
echo '<div>';
|
||||||
echo $this->progressTaskSummary($task);
|
echo $this->progressTaskSummary($task);
|
||||||
@ -1225,10 +1248,9 @@ class DiscoveryTaskList extends HTML
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$ids = [];
|
||||||
$selection = io_safe_output(get_parameter('tree-data-tree', ''));
|
$selection = io_safe_output(get_parameter('tree-data-tree', ''));
|
||||||
if (empty($selection)) {
|
if (empty($selection) === false) {
|
||||||
$ids = [];
|
|
||||||
} else {
|
|
||||||
$selection = json_decode($selection, true);
|
$selection = json_decode($selection, true);
|
||||||
$ids = array_reduce(
|
$ids = array_reduce(
|
||||||
$selection,
|
$selection,
|
||||||
@ -1239,57 +1261,73 @@ class DiscoveryTaskList extends HTML
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$task_data = db_get_row('tdiscovery_tmp_agents', 'id', $id_task);
|
$task_data = db_get_all_rows_filter(
|
||||||
|
'tdiscovery_tmp_agents',
|
||||||
if (is_array($task_data)) {
|
['id_rt' => $id_task]
|
||||||
$data = json_decode(base64_decode($task_data['data']), true);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
$summary = [];
|
$summary = [];
|
||||||
if (is_array($data)) {
|
if (is_array($ids)) {
|
||||||
foreach ($data as $agent_name => $row) {
|
foreach ($task_data as $row) {
|
||||||
if (in_array($agent_name, $ids)) {
|
$data = json_decode(base64_decode($row['data']), true);
|
||||||
$data[$agent_name]['checked'] = 1;
|
|
||||||
if ($data[$agent_name]['checked'] != 1) {
|
if (is_array($data)) {
|
||||||
$summary[] = '<li class="added">'.$agent_name.'</li>';
|
// Analize each agent.
|
||||||
}
|
$agent_name = $data['agent']['nombre'];
|
||||||
} else {
|
if (in_array($agent_name, $ids)) {
|
||||||
if ($data[$agent_name]['checked'] == 1) {
|
if ($data['agent']['checked'] != 1) {
|
||||||
$summary[] = '<li class="removed">'.__('Removed').' '.$agent_name.'</li>';
|
$summary[] = '<li class="added">'.$agent_name.'</li>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['agent']['checked'] = 1;
|
||||||
|
} else {
|
||||||
|
if ($data['agent']['checked'] == 1) {
|
||||||
|
$summary[] = '<li class="removed">'.__('Removed').' '.$agent_name.'</li>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['agent']['checked'] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$data[$agent_name]['checked'] = 0;
|
// Modules.
|
||||||
}
|
if (is_array($data['modules'])) {
|
||||||
|
$n_modules = count($data['modules']);
|
||||||
|
for ($i = 0; $i < $n_modules; $i++) {
|
||||||
|
$module_name = $data['modules'][$i]['name'];
|
||||||
|
if (in_array($agent_name.'-'.$module_name, $ids)) {
|
||||||
|
if ($data['modules'][$i]['checked'] != 1) {
|
||||||
|
$summary[] = '<li class="added">'.$agent_name.' - '.$module_name.'</li>';
|
||||||
|
}
|
||||||
|
|
||||||
if (is_array($row['modules'])) {
|
$data['modules'][$i]['checked'] = 1;
|
||||||
$n_modules = count($row['modules']);
|
} else {
|
||||||
for ($i = 0; $i < $n_modules; $i++) {
|
if ($data['modules'][$i]['checked'] == 1) {
|
||||||
$module_name = $row['modules'][$i]['name'];
|
$summary[] = '<li class="removed">'.__('Removed').' '.$agent_name.' - '.$module_name.'</li>';
|
||||||
if (in_array($agent_name.'-'.$module_name, $ids)) {
|
}
|
||||||
$data[$agent_name]['modules'][$i]['checked'] = 1;
|
|
||||||
if ($row['modules'][$i]['checked'] != 1) {
|
|
||||||
$summary[] = '<li class="added">'.$agent_name.' - '.$module_name.'</li>';
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if ($row['modules'][$i]['checked'] == 1) {
|
|
||||||
$summary[] = '<li class="removed">'.__('Removed').' '.$agent_name.' - '.$module_name.'</li>';
|
|
||||||
}
|
|
||||||
|
|
||||||
$data[$agent_name]['modules'][$i]['checked'] = 0;
|
$data['modules'][$i]['checked'] = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update data.
|
||||||
|
db_process_sql_update(
|
||||||
|
'tdiscovery_tmp_agents',
|
||||||
|
[
|
||||||
|
'data' => base64_encode(json_encode($data)),
|
||||||
|
'review_date' => date('Y-m-d H:i:s'),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id_rt' => $id_task,
|
||||||
|
'label' => $agent_name,
|
||||||
|
]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Update targets.
|
if (empty($summary)) {
|
||||||
db_process_sql_update(
|
$out .= __('No changes');
|
||||||
'tdiscovery_tmp_agents',
|
} else {
|
||||||
[
|
|
||||||
'data' => base64_encode(json_encode($data)),
|
|
||||||
],
|
|
||||||
['id_rt' => $id_task]
|
|
||||||
);
|
|
||||||
|
|
||||||
// Schedule execution.
|
// Schedule execution.
|
||||||
db_process_sql_update(
|
db_process_sql_update(
|
||||||
'trecon_task',
|
'trecon_task',
|
||||||
@ -1300,11 +1338,7 @@ class DiscoveryTaskList extends HTML
|
|||||||
],
|
],
|
||||||
['id_rt' => $id_task]
|
['id_rt' => $id_task]
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($summary)) {
|
|
||||||
$out .= __('No changes');
|
|
||||||
} else {
|
|
||||||
$out .= __('Summary');
|
$out .= __('Summary');
|
||||||
$out .= '<ul>';
|
$out .= '<ul>';
|
||||||
$out .= join('', $summary);
|
$out .= join('', $summary);
|
||||||
|
@ -1081,6 +1081,7 @@ var simTree_'.$target.';
|
|||||||
\'<input type="hidden" id="tree-data-'.$target.'" name="tree-data-'.$target.'">\'
|
\'<input type="hidden" id="tree-data-'.$target.'" name="tree-data-'.$target.'">\'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$("#tree-data-'.$target.'").val(JSON.stringify(simTree_'.$target.'.sels));
|
||||||
});
|
});
|
||||||
</script>';
|
</script>';
|
||||||
|
|
||||||
|
@ -819,7 +819,7 @@ CREATE TABLE `tdiscovery_tmp_agents` (
|
|||||||
`label` varchar(600) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',
|
`label` varchar(600) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',
|
||||||
`data` text,
|
`data` text,
|
||||||
`review_date` datetime DEFAULT NULL,
|
`review_date` datetime DEFAULT NULL,
|
||||||
`created` int(1) unsigned NOT NULL DEFAULT '0',
|
`created` datetime DEFAULT NULL,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `id_rt` (`id_rt`),
|
KEY `id_rt` (`id_rt`),
|
||||||
INDEX `label` (`label`),
|
INDEX `label` (`label`),
|
||||||
|
@ -3266,7 +3266,7 @@ sub pandora_create_agent ($$$$$$$$$$;$$$$$$$$$$) {
|
|||||||
$agent_mode = 1 unless defined($agent_mode);
|
$agent_mode = 1 unless defined($agent_mode);
|
||||||
$alias = $agent_name unless defined($alias);
|
$alias = $agent_name unless defined($alias);
|
||||||
|
|
||||||
$description = "Created by $server_name" unless ($description ne '');
|
$description = "Created by $server_name" unless (defined($description) && $description ne '');
|
||||||
my ($columns, $values) = db_insert_get_values ({ 'nombre' => safe_input($agent_name),
|
my ($columns, $values) = db_insert_get_values ({ 'nombre' => safe_input($agent_name),
|
||||||
'direccion' => $address,
|
'direccion' => $address,
|
||||||
'comentarios' => $description,
|
'comentarios' => $description,
|
||||||
|
@ -61,6 +61,8 @@ use constant {
|
|||||||
STEP_AFT => 2,
|
STEP_AFT => 2,
|
||||||
STEP_TRACEROUTE => 3,
|
STEP_TRACEROUTE => 3,
|
||||||
STEP_GATEWAY => 4,
|
STEP_GATEWAY => 4,
|
||||||
|
STEP_MONITORING => 5,
|
||||||
|
STEP_APPLY => 6,
|
||||||
STEP_STATISTICS => 1,
|
STEP_STATISTICS => 1,
|
||||||
STEP_APP_SCAN => 2,
|
STEP_APP_SCAN => 2,
|
||||||
STEP_CUSTOM_QUERIES => 3,
|
STEP_CUSTOM_QUERIES => 3,
|
||||||
@ -452,6 +454,14 @@ sub PandoraFMS::Recon::Base::create_network_profile_modules($$$) {
|
|||||||
# ICMP
|
# ICMP
|
||||||
#
|
#
|
||||||
|
|
||||||
|
use Data::Dumper;
|
||||||
|
$Data::Dumper::Sortkeys = 1;
|
||||||
|
|
||||||
|
print Dumper($device);
|
||||||
|
print Dumper($self->{'task_data'});
|
||||||
|
|
||||||
|
die();
|
||||||
|
|
||||||
return if empty($self->{'id_network_profile'});
|
return if empty($self->{'id_network_profile'});
|
||||||
|
|
||||||
my @templates = split /,/, $self->{'id_network_profile'};
|
my @templates = split /,/, $self->{'id_network_profile'};
|
||||||
@ -481,7 +491,12 @@ sub PandoraFMS::Recon::Base::create_network_profile_modules($$$) {
|
|||||||
$component->{'plugin_user'} = $self->{'snmp_auth_user'};
|
$component->{'plugin_user'} = $self->{'snmp_auth_user'};
|
||||||
$component->{'plugin_pass'} = $self->{'snmp_auth_pass'};
|
$component->{'plugin_pass'} = $self->{'snmp_auth_pass'};
|
||||||
|
|
||||||
pandora_create_module_from_network_component($self->{'pa_config'}, $component, $agent_id, $self->{'dbh'});
|
pandora_create_module_from_network_component(
|
||||||
|
$self->{'pa_config'},
|
||||||
|
$component,
|
||||||
|
$agent_id,
|
||||||
|
$self->{'dbh'}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -491,8 +506,19 @@ sub PandoraFMS::Recon::Base::create_network_profile_modules($$$) {
|
|||||||
sub PandoraFMS::Recon::Base::report_scanned_agents($) {
|
sub PandoraFMS::Recon::Base::report_scanned_agents($) {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
|
|
||||||
|
my $force_creation = 0;
|
||||||
|
|
||||||
|
if (defined($self->{'task_data'}{'direct_report'})
|
||||||
|
&& $self->{'task_data'}{'direct_report'} == DISCOVERY_STANDARD
|
||||||
|
) {
|
||||||
|
$force_creation = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Creation
|
||||||
|
#
|
||||||
if(defined($self->{'task_data'}{'direct_report'})
|
if(defined($self->{'task_data'}{'direct_report'})
|
||||||
&& $self->{'task_data'}{'direct_report'} == DISCOVERY_RESULTS
|
&& $self->{'task_data'}{'direct_report'} == DISCOVERY_RESULTS
|
||||||
) {
|
) {
|
||||||
# Load cache.
|
# Load cache.
|
||||||
my @rows = get_db_rows(
|
my @rows = get_db_rows(
|
||||||
@ -501,63 +527,214 @@ sub PandoraFMS::Recon::Base::report_scanned_agents($) {
|
|||||||
$self->{'task_data'}{'id_rt'}
|
$self->{'task_data'}{'id_rt'}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
my @agents;
|
||||||
|
|
||||||
|
my $progress = 0;
|
||||||
|
my $step = 100.00 / scalar @rows;
|
||||||
foreach my $row (@rows) {
|
foreach my $row (@rows) {
|
||||||
|
$progress += $step;
|
||||||
|
$self->call('update_progress', $progress);
|
||||||
|
|
||||||
my $name = safe_output($row->{'label'});
|
my $name = safe_output($row->{'label'});
|
||||||
my $data;
|
my $data;
|
||||||
eval {
|
eval {
|
||||||
|
local $SIG{__DIE__};
|
||||||
$data = decode_json(decode_base64($row->{'data'}));
|
$data = decode_json(decode_base64($row->{'data'}));
|
||||||
};
|
};
|
||||||
|
if ($@) {
|
||||||
|
$self->call('message', "ERROR JSON: $@", 3);
|
||||||
|
}
|
||||||
|
|
||||||
# Store.
|
# Register target agent if enabled.
|
||||||
$self->{'agents_found'}{$name} = $data;
|
if (is_enabled($data->{'agent'}{'checked'})
|
||||||
}
|
|| $force_creation
|
||||||
}
|
) {
|
||||||
|
my $parent_id;
|
||||||
|
my $os_id = $self->guess_os($data->{'agent'}{'direccion'});
|
||||||
|
|
||||||
foreach my $label (keys %{$self->{'agents_found'}}) {
|
$self->call('message', "Agent accepted: ".$data->{'agent'}{'nombre'}, 5);
|
||||||
if (!is_enabled($self->{'direct_report'})) {
|
|
||||||
# Store temporally. Wait user approval.
|
|
||||||
my $encoded;
|
|
||||||
eval {
|
|
||||||
local $SIG{__DIE__};
|
|
||||||
$encoded = encode_base64(encode_json($self->{'agents_found'}));
|
|
||||||
};
|
|
||||||
|
|
||||||
my $id = get_db_value(
|
# Agent creation.
|
||||||
$self->{'dbh'},
|
my $agent_id = $data->{'agent'}{'agent_id'};
|
||||||
'SELECT id FROM tdiscovery_tmp_agents WHERE id_rt = ? AND label = ?',
|
my $agent_learning = 1;
|
||||||
$self->{'task_data'}{'id_rt'},
|
|
||||||
safe_input($label)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (defined($id)) {
|
|
||||||
# Already defined.
|
|
||||||
$self->{'agents_found'}{$label}{'id'} = $id;
|
|
||||||
|
|
||||||
|
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'}
|
||||||
|
);
|
||||||
|
|
||||||
|
$data->{'agent'}{'agent_id'} = $agent_id;
|
||||||
|
$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);
|
||||||
|
|
||||||
|
# Create selected modules.
|
||||||
|
if(ref($data->{'modules'}) eq "ARRAY") {
|
||||||
|
for (my $i=0; $i < scalar @{$data->{'modules'}}; $i++) {
|
||||||
|
my $module = $data->{'modules'}[$i];
|
||||||
|
|
||||||
|
# Do not create any modules if the agent is not in learning mode.
|
||||||
|
next unless ($agent_learning == 1);
|
||||||
|
|
||||||
|
# Host alive is always being created.
|
||||||
|
if ($module->{'name'} ne 'Host Alive') {
|
||||||
|
next unless (is_enabled($module->{'checked'}) || $force_creation);
|
||||||
|
}
|
||||||
|
|
||||||
|
$self->call('message', "[$agent_id] Module: ".$module->{'name'}, 5);
|
||||||
|
|
||||||
|
my $agentmodule_id = $module->{'agentmodule_id'};
|
||||||
|
if (!defined($agentmodule_id) || $agentmodule_id == 0) {
|
||||||
|
# Create module.
|
||||||
|
$agentmodule_id = pandora_create_module_from_hash(
|
||||||
|
$self->{'pa_config'},
|
||||||
|
{
|
||||||
|
'id_tipo_modulo' => get_module_id($self->{'dbh'}, $module->{'type'}),
|
||||||
|
'id_modulo' => $module->{'id_modulo'},
|
||||||
|
'nombre' => safe_input($module->{'name'}),
|
||||||
|
'descripcion' => '',
|
||||||
|
'id_agente' => $agent_id,
|
||||||
|
'ip_target' => $data->{'agent'}{'direccion'}
|
||||||
|
},
|
||||||
|
$self->{'dbh'}
|
||||||
|
);
|
||||||
|
|
||||||
|
# Store.
|
||||||
|
$data->{'modules'}[$i]{'agentmodule_id'} = $agentmodule_id;
|
||||||
|
|
||||||
|
$self->call(
|
||||||
|
'message',
|
||||||
|
"[$agent_id] Module: ".$module->{'name'}." ID: $agentmodule_id",
|
||||||
|
5
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
my $encoded;
|
||||||
|
eval {
|
||||||
|
local $SIG{__DIE__};
|
||||||
|
$encoded = encode_base64(
|
||||||
|
encode_json($data)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
# Update.
|
||||||
db_do(
|
db_do(
|
||||||
$self->{'dbh'},
|
$self->{'dbh'},
|
||||||
'UPDATE tdiscovery_tmp_agents SET `data` = ? '
|
'UPDATE tdiscovery_tmp_agents SET `data` = ? '
|
||||||
.'WHERE `id_rt` = ? AND `label` = ?',
|
.'WHERE `id_rt` = ? AND `label` = ?',
|
||||||
$encoded,
|
$encoded,
|
||||||
$self->{'task_data'}{'id_rt'},
|
$self->{'task_data'}{'id_rt'},
|
||||||
safe_input($label)
|
$name
|
||||||
);
|
);
|
||||||
next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Insert.
|
|
||||||
$self->{'agents_found'}{$label}{'id'} = db_insert(
|
|
||||||
$self->{'dbh'},
|
|
||||||
'id',
|
|
||||||
'INSERT INTO tdiscovery_tmp_agents (`id_rt`,`label`,`data`,`created`) '
|
|
||||||
.'VALUES (?, ?, ?, now())',
|
|
||||||
$self->{'task_data'}{'id_rt'},
|
|
||||||
safe_input($label),
|
|
||||||
$encoded
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
# Create agents.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Data creation finished.
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Cleanup previous results.
|
||||||
|
#
|
||||||
|
db_do(
|
||||||
|
$self->{'dbh'},
|
||||||
|
'DELETE FROM tdiscovery_tmp_agents '
|
||||||
|
.'WHERE `id_rt` = ?',
|
||||||
|
$self->{'task_data'}{'id_rt'}
|
||||||
|
);
|
||||||
|
|
||||||
|
#
|
||||||
|
# Store and review.
|
||||||
|
#
|
||||||
|
|
||||||
|
my @hosts = keys %{$self->{'agents_found'}};
|
||||||
|
$self->{'step'} = STEP_APPLY;
|
||||||
|
my ($progress, $step) = (90, 10.0 / scalar(@hosts)); # From 90% to 100%.
|
||||||
|
foreach my $label (keys %{$self->{'agents_found'}}) {
|
||||||
|
$self->call('update_progress', $progress);
|
||||||
|
$progress += $step;
|
||||||
|
# Store temporally. Wait user approval.
|
||||||
|
my $encoded;
|
||||||
|
eval {
|
||||||
|
local $SIG{__DIE__};
|
||||||
|
$encoded = encode_base64(
|
||||||
|
encode_json($self->{'agents_found'}->{$label})
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
my $id = get_db_value(
|
||||||
|
$self->{'dbh'},
|
||||||
|
'SELECT id FROM tdiscovery_tmp_agents WHERE id_rt = ? AND label = ?',
|
||||||
|
$self->{'task_data'}{'id_rt'},
|
||||||
|
safe_input($label)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (defined($id)) {
|
||||||
|
# Already defined.
|
||||||
|
$self->{'agents_found'}{$label}{'id'} = $id;
|
||||||
|
|
||||||
|
db_do(
|
||||||
|
$self->{'dbh'},
|
||||||
|
'UPDATE tdiscovery_tmp_agents SET `data` = ? '
|
||||||
|
.'WHERE `id_rt` = ? AND `label` = ?',
|
||||||
|
$encoded,
|
||||||
|
$self->{'task_data'}{'id_rt'},
|
||||||
|
safe_input($label)
|
||||||
|
);
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Insert.
|
||||||
|
$self->{'agents_found'}{$label}{'id'} = db_insert(
|
||||||
|
$self->{'dbh'},
|
||||||
|
'id',
|
||||||
|
'INSERT INTO tdiscovery_tmp_agents (`id_rt`,`label`,`data`,`created`) '
|
||||||
|
.'VALUES (?, ?, ?, now())',
|
||||||
|
$self->{'task_data'}{'id_rt'},
|
||||||
|
safe_input($label),
|
||||||
|
$encoded
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Apply monitoring templates selected to detected agents.
|
||||||
|
################################################################################
|
||||||
|
sub PandoraFMS::Recon::Base::apply_monitoring($) {
|
||||||
|
my ($self) = @_;
|
||||||
|
|
||||||
|
my @hosts = keys %{$self->{'agents_found'}};
|
||||||
|
|
||||||
|
$self->{'step'} = STEP_MONITORING;
|
||||||
|
# From 80% to 90%.
|
||||||
|
my ($progress, $step) = (80, 10.0 / scalar(@hosts));
|
||||||
|
|
||||||
|
use Data::Dumper;
|
||||||
|
print Dumper($self->{'task_data'});
|
||||||
|
|
||||||
|
foreach my $label (keys %{$self->{'agents_found'}}) {
|
||||||
|
$self->call('update_progress', $progress);
|
||||||
|
$progress += $step;
|
||||||
|
print ">> $label\n";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
|
@ -22,6 +22,8 @@ use constant {
|
|||||||
STEP_AFT => 2,
|
STEP_AFT => 2,
|
||||||
STEP_TRACEROUTE => 3,
|
STEP_TRACEROUTE => 3,
|
||||||
STEP_GATEWAY => 4,
|
STEP_GATEWAY => 4,
|
||||||
|
STEP_MONITORING => 5,
|
||||||
|
STEP_APPLY => 6,
|
||||||
STEP_STATISTICS => 1,
|
STEP_STATISTICS => 1,
|
||||||
STEP_APP_SCAN => 2,
|
STEP_APP_SCAN => 2,
|
||||||
STEP_CUSTOM_QUERIES => 3,
|
STEP_CUSTOM_QUERIES => 3,
|
||||||
@ -408,7 +410,7 @@ sub icmp_discovery($$) {
|
|||||||
'ip_target' => $addr,
|
'ip_target' => $addr,
|
||||||
'name' => "Host Alive",
|
'name' => "Host Alive",
|
||||||
'description' => '',
|
'description' => '',
|
||||||
'type' => 'generic_data',
|
'type' => 'remote_icmp_proc',
|
||||||
'id_modulo' => 2,
|
'id_modulo' => 2,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -1389,7 +1391,7 @@ sub scan_subnet($) {
|
|||||||
my $host_block_size = $self->{'block_size'};
|
my $host_block_size = $self->{'block_size'};
|
||||||
|
|
||||||
# The first 50% of the recon task approx.
|
# The first 50% of the recon task approx.
|
||||||
my $step = 40.0 / scalar(@subnets) / (($total_hosts / $host_block_size)+1);
|
my $step = 25.0 / scalar(@subnets) / (($total_hosts / $host_block_size)+1);
|
||||||
my $subnet_step = 50.0 / (($total_hosts / $host_block_size)+1);
|
my $subnet_step = 50.0 / (($total_hosts / $host_block_size)+1);
|
||||||
|
|
||||||
for (my $block_index=0;
|
for (my $block_index=0;
|
||||||
@ -1438,7 +1440,7 @@ sub scan_subnet($) {
|
|||||||
$self->call('update_progress', ceil($progress));
|
$self->call('update_progress', ceil($progress));
|
||||||
|
|
||||||
$total_hosts = scalar keys %hosts_alive;
|
$total_hosts = scalar keys %hosts_alive;
|
||||||
$step = 40.0 / scalar(@subnets) / $total_hosts;
|
$step = 25.0 / scalar(@subnets) / $total_hosts;
|
||||||
$subnet_step = 50.0 / $total_hosts;
|
$subnet_step = 50.0 / $total_hosts;
|
||||||
foreach my $addr (keys %hosts_alive) {
|
foreach my $addr (keys %hosts_alive) {
|
||||||
# Increase self summary.alive hosts.
|
# Increase self summary.alive hosts.
|
||||||
@ -1807,18 +1809,21 @@ sub scan($) {
|
|||||||
return $self->deploy_scan();
|
return $self->deploy_scan();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# XXX
|
|
||||||
print "Metodo: ".$self->{'task_data'}{'direct_report'}."\n";
|
|
||||||
|
|
||||||
if(defined($self->{'task_data'}{'direct_report'})
|
if(defined($self->{'task_data'}{'direct_report'})
|
||||||
&& $self->{'task_data'}{'direct_report'} == DISCOVERY_RESULTS
|
&& $self->{'task_data'}{'direct_report'} == DISCOVERY_RESULTS
|
||||||
) {
|
) {
|
||||||
# Use Cached results.
|
# Use Cached results.
|
||||||
return $self->call('report_scanned_agents');
|
$self->call('report_scanned_agents');
|
||||||
|
|
||||||
|
# Done!
|
||||||
|
$self->{'step'} = '';
|
||||||
|
$self->call('update_progress', -1);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Find devices.
|
# Find devices.
|
||||||
$self->call('message', "[1/4] Scanning the network...", 3);
|
$self->call('message', "[1/6] Scanning the network...", 3);
|
||||||
$self->{'step'} = STEP_SCANNING;
|
$self->{'step'} = STEP_SCANNING;
|
||||||
$self->call('update_progress', $progress);
|
$self->call('update_progress', $progress);
|
||||||
|
|
||||||
@ -1834,9 +1839,9 @@ sub scan($) {
|
|||||||
$self->call('delete_connections');
|
$self->call('delete_connections');
|
||||||
|
|
||||||
# Connectivity from address forwarding tables.
|
# Connectivity from address forwarding tables.
|
||||||
$self->call('message', "[2/4] Finding address forwarding table connectivity...", 3);
|
$self->call('message', "[2/6] Finding address forwarding table connectivity...", 3);
|
||||||
$self->{'step'} = STEP_AFT;
|
$self->{'step'} = STEP_AFT;
|
||||||
($progress, $step) = (80, 8.0 / scalar(@hosts)); # From 50% to 70%.
|
($progress, $step) = (50, 10.0 / scalar(@hosts)); # From 50% to 60%.
|
||||||
for (my $i = 0; defined($hosts[$i]); $i++) {
|
for (my $i = 0; defined($hosts[$i]); $i++) {
|
||||||
$self->call('update_progress', $progress);
|
$self->call('update_progress', $progress);
|
||||||
$progress += $step;
|
$progress += $step;
|
||||||
@ -1844,9 +1849,9 @@ sub scan($) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Connect hosts that are still unconnected using traceroute.
|
# Connect hosts that are still unconnected using traceroute.
|
||||||
$self->call('message', "[3/4] Finding traceroute connectivity.", 3);
|
$self->call('message', "[3/6] Finding traceroute connectivity.", 3);
|
||||||
$self->{'step'} = STEP_TRACEROUTE;
|
$self->{'step'} = STEP_TRACEROUTE;
|
||||||
($progress, $step) = (88, 8.0 / scalar(@hosts)); # From 70% to 90%.
|
($progress, $step) = (60, 10.0 / scalar(@hosts)); # From 60% to 70%.
|
||||||
foreach my $host (@hosts) {
|
foreach my $host (@hosts) {
|
||||||
$self->call('update_progress', $progress);
|
$self->call('update_progress', $progress);
|
||||||
$progress += $step;
|
$progress += $step;
|
||||||
@ -1855,9 +1860,9 @@ sub scan($) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Connect hosts that are still unconnected using known gateways.
|
# Connect hosts that are still unconnected using known gateways.
|
||||||
$self->call('message', "[4/4] Finding host to gateway connectivity.", 3);
|
$self->call('message', "[4/6] Finding host to gateway connectivity.", 3);
|
||||||
$self->{'step'} = STEP_GATEWAY;
|
$self->{'step'} = STEP_GATEWAY;
|
||||||
($progress, $step) = (94, 6.0 / scalar(@hosts)); # From 70% to 90%.
|
($progress, $step) = (70, 10.0 / scalar(@hosts)); # From 70% to 80%.
|
||||||
$self->get_routes(); # Update the route cache.
|
$self->get_routes(); # Update the route cache.
|
||||||
foreach my $host (@hosts) {
|
foreach my $host (@hosts) {
|
||||||
$self->call('update_progress', $progress);
|
$self->call('update_progress', $progress);
|
||||||
@ -1867,9 +1872,9 @@ sub scan($) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Done!
|
# Apply monitoring templates
|
||||||
$self->{'step'} = '';
|
$self->call('message', "[5/6] Applying monitoring.", 3);
|
||||||
$self->call('update_progress', -1);
|
$self->call('apply_monitoring', $self);
|
||||||
|
|
||||||
# Print debug information on found devices.
|
# Print debug information on found devices.
|
||||||
$self->call('message', "[Summary]", 3);
|
$self->call('message', "[Summary]", 3);
|
||||||
@ -1887,9 +1892,15 @@ sub scan($) {
|
|||||||
$self->call('message', $dev_info, 3);
|
$self->call('message', $dev_info, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Apply monitoring templates
|
||||||
|
$self->call('message', "[6/6] Process results.", 3);
|
||||||
# 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'});
|
||||||
|
|
||||||
|
# Done!
|
||||||
|
$self->{'step'} = '';
|
||||||
|
$self->call('update_progress', -1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
|
Loading…
x
Reference in New Issue
Block a user