Merge branch 'ent-3595-discovery-fase-2' of https://brutus.artica.lan:8081/artica/pandorafms into ent-3595-discovery-fase-2

Former-commit-id: 12579e897dc21339580e7b52f4de593714431c58
This commit is contained in:
alejandro-campos 2019-03-05 16:48:41 +01:00
commit 5c65f2541d
8 changed files with 103 additions and 105 deletions

View File

@ -373,20 +373,7 @@ function networkmap_generate_dot(
$agents = false;
} else if (!empty($ip_mask)) {
$agents = networkmap_get_new_nodes_from_ip_mask(
$ip_mask,
[
'id_grupo',
'nombre',
'id_os',
'id_parent',
'id_agente',
'normal_count',
'warning_count',
'critical_count',
'unknown_count',
'total_count',
'notinit_count',
]
$ip_mask
);
} else {
$agents = agents_get_agents(
@ -454,7 +441,6 @@ function networkmap_generate_dot(
// Get agent modules data
$modules = agents_get_modules($agent['id_agente'], '*', $filter, true, true);
if ($modules === false) {
$modules = [];
}
@ -1654,40 +1640,46 @@ function networkmap_get_new_nodes_from_ip_mask(
) {
$list_ip_masks = explode(',', $ip_mask);
$list_address = db_get_all_rows_in_table('taddress');
if (empty($address)) {
$address = [];
}
$agents = [];
foreach ($list_address as $address) {
foreach ($list_ip_masks as $ip_mask) {
if (networkmap_cidr_match($address['ip'], $ip_mask)) {
$id_agent = db_get_value_filter(
'id_agent',
'taddress_agent',
['id_a' => $address['id_a']]
);
foreach ($list_ip_masks as $subnet) {
$net = explode('/', $subnet);
// Orphan address. Ignore.
if (empty($id_agent)) {
continue;
}
$sql = sprintf(
'SELECT *
FROM `tagente`
INNER JOIN
(SELECT DISTINCT `id_agent` FROM
(SELECT `id_agente` AS "id_agent", `direccion` AS "ip"
FROM `tagente`
UNION
SELECT ag.`id_agent`, a.`ip`
FROM `taddress_agent` ag
INNER JOIN `taddress` a
ON ag.id_a=a.id_a
) t_tmp
WHERE (-1 << %d) & INET_ATON(t_tmp.ip) = INET_ATON("%s")
) t_res
ON t_res.`id_agent` = `tagente`.`id_agente`',
(32 - $net[1]),
$net[0]
);
if (empty($fields)) {
$target_agent = db_get_value_filter('id_agent', 'taddress_agent', ['id_a' => $address['id_a']]);
} else {
$target_agent = db_get_row('tagente', 'id_agente', $id_agent, $fields);
}
$subnet_agents = db_get_all_rows_sql($sql);
// Agent exists. Add to pool.
if ($target_agent !== false) {
$agents[$id_agent] = $target_agent;
}
}
if ($subnet_agents !== false) {
$agents = array_merge($agents, $subnet_agents);
}
}
$agents = array_reduce(
$agents,
function ($carry, $item) {
$carry[$item['id_agente']] = $item;
return $carry;
},
[]
);
return $agents;
}

View File

@ -593,41 +593,43 @@ function networkmap_db_node_to_js_node($node, &$count, &$count_item_holding_area
function get_status_color_networkmap($id, $color=true)
{
$status = agents_get_status($id);
// $status = agents_get_status($id);
$agent_data = db_get_row_sql('SELECT * FROM tagente WHERE id_agente = '.$id);
if ($agent_data === false) {
return COL_UNKNOWN;
}
$status = agents_get_status_from_counts($agent_data);
if (!$color) {
return $status;
}
// Set node status
switch ($status) {
case 0:
$status_color = COL_NORMAL;
// Normal monitor
break;
case 1:
$status_color = COL_CRITICAL;
// Critical monitor
break;
case 2:
$status_color = COL_WARNING;
// Warning monitor
break;
case 4:
$status_color = COL_ALERTFIRED;
// Alert fired
break;
default:
$status_color = COL_UNKNOWN;
// Unknown monitor
break;
if ($agent_data['fired_count'] > 0) {
return COL_ALERTFIRED;
}
return $status_color;
// Select node color by checking status.
switch ($status) {
case AGENT_MODULE_STATUS_NORMAL:
return COL_NORMAL;
case AGENT_MODULE_STATUS_NOT_INIT:
return COL_NOTINIT;
case AGENT_MODULE_STATUS_CRITICAL_BAD:
return COL_CRITICAL;
case AGENT_MODULE_STATUS_WARNING:
return COL_WARNING;
case AGENT_MODULE_STATUS_UNKNOWN:
default:
return COL_UNKNOWN;
}
return COL_UNKNOWN;
}
@ -2126,5 +2128,3 @@ function show_networkmap($id=0, $user_readonly=false, $nodes_and_relations=[], $
</div>
<?php
}

View File

@ -2571,11 +2571,9 @@ function reset_map_from_form(new_elements) {
type: "POST",
url: (action = "ajax.php"),
success: function(data) {
if (!data["error"]) {
window.location =
"index.php?sec=network&sec2=operation/agentes/pandora_networkmap&tab=view&id_networkmap=" +
networkmap_id;
}
window.location =
"index.php?sec=network&sec2=operation/agentes/pandora_networkmap&tab=view&id_networkmap=" +
networkmap_id;
}
});
}

View File

@ -107,61 +107,61 @@
background-position: 4px 2px;
}
.context-menu-item.icon-edit {
background-image: url(../../images/page_white_edit.png);
background-image: url(../../../images/page_white_edit.png);
}
.context-menu-item.icon-cut {
background-image: url(../../images/cut.png);
background-image: url(../../../images/cut.png);
}
.context-menu-item.icon-copy {
background-image: url(../../images/page_white_copy.png);
background-image: url(../../../images/page_white_copy.png);
}
.context-menu-item.icon-paste {
background-image: url(../../images/page_white_paste.png);
background-image: url(../../../images/page_white_paste.png);
}
.context-menu-item.icon-delete {
background-image: url(../../images/delete.png);
background-image: url(../../../images/delete.png);
}
.context-menu-item.icon-add {
background-image: url(../../images/page_white_add.png);
background-image: url(../../../images/page_white_add.png);
}
.context-menu-item.icon-quit {
background-image: url(../../images/door.png);
background-image: url(../../../images/door.png);
}
.context-menu-item.icon-refresh {
background-image: url(../../images/refresh.png);
background-image: url(../../../images/refresh.png);
}
.context-menu-item.icon-center {
background-image: url(../../images/set_center.png);
background-image: url(../../../images/set_center.png);
}
.context-menu-item.icon-details {
background-image: url(../../images/show_details.png);
background-image: url(../../../images/show_details.png);
}
.context-menu-item.icon-children {
background-image: url(../../images/children.png);
background-image: url(../../../images/children.png);
}
.context-menu-item.icon-cancel_set_parent {
background-image: url(../../images/link_delete.png);
background-image: url(../../../images/link_delete.png);
}
.context-menu-item.icon-set_parent {
background-image: url(../../images/father.png);
background-image: url(../../../images/father.png);
}
.context-menu-item.icon-add_node {
background-image: url(../../images/add.png);
background-image: url(../../../images/add.png);
}
.context-menu-item.icon-refresh_holding_area {
background-image: url(../../images/refresh_holding_area.png);
background-image: url(../../../images/refresh_holding_area.png);
}
.context-menu-item.icon-restart_map {
background-image: url(../../images/reset.png);
background-image: url(../../../images/reset.png);
}
.context-menu-item.icon-interface_link_children {
background-image: url(../../images/icono_link_hijo.png);
background-image: url(../../../images/icono_link_hijo.png);
}
.context-menu-item.icon-interface_link_parent {
background-image: url(../../images/icono_link_padre.png);
background-image: url(../../../images/icono_link_padre.png);
}
.context-menu-item.icon-interface_link_cancel {
background-image: url(../../images/link_abortar.png);
background-image: url(../../../images/link_abortar.png);
}
/* vertically align inside labels */

View File

@ -26,7 +26,7 @@ use lib '/usr/lib/perl5';
use PandoraFMS::Tools;
use PandoraFMS::DB;
use PandoraFMS::Core;
require Exporter;
our @ISA = ("Exporter");

View File

@ -3077,12 +3077,14 @@ Create a new entry in B<tagente> optionaly with position information
=cut
##########################################################################
sub pandora_create_agent ($$$$$$$$$$;$$$$$$$$$) {
sub pandora_create_agent ($$$$$$$$$$;$$$$$$$$$$) {
# If parameter event_id is not undef, then create an extended event
# related to it instead launch new event.
my ($pa_config, $server_name, $agent_name, $address,
$group_id, $parent_id, $os_id,
$description, $interval, $dbh, $timezone_offset,
$longitude, $latitude, $altitude, $position_description,
$custom_id, $url_address, $agent_mode, $alias) = @_;
$custom_id, $url_address, $agent_mode, $alias, $event_id) = @_;
logger ($pa_config, "Server '$server_name' creating agent '$agent_name' address '$address'.", 10);
@ -3125,7 +3127,11 @@ sub pandora_create_agent ($$$$$$$$$$;$$$$$$$$$) {
}
logger ($pa_config, "Server '$server_name' CREATED agent '$agent_name' address '$address'.", 10);
pandora_event ($pa_config, "Agent [" . safe_output($alias) . "] created by $server_name", $group_id, $agent_id, 2, 0, 0, 'new_agent', 0, $dbh);
if (!defined($event_id)) {
pandora_event ($pa_config, "Agent [" . safe_output($alias) . "] created by $server_name", $group_id, $agent_id, 2, 0, 0, 'new_agent', 0, $dbh);
} else {
pandora_extended_event($pa_config, $dbh, $event_id, "Agent [" . safe_output($alias) . "][#".$agent_id."] created by $server_name");
}
return $agent_id;
}

View File

@ -469,10 +469,12 @@ sub PandoraFMS::Recon::Base::create_agent($$) {
# Are we filtering hosts by TCP port?
return if ($self->{'recon_ports'} ne '' && $self->tcp_scan($device) == 0);
my $location = get_geoip_info($self->{'pa_config'}, $device);
$agent_id = pandora_create_agent($self->{'pa_config'}, $self->{'pa_config'}->{'servername'}, $host_name, $device,
$self->{'group_id'}, 0, $id_os,
'', 300, $self->{'dbh'}, undef,
$location->{'longitude'}, $location->{'latitude'}
$agent_id = pandora_create_agent(
$self->{'pa_config'}, $self->{'pa_config'}->{'servername'},
$host_name, $device, $self->{'group_id'}, 0, $id_os,
'', 300, $self->{'dbh'}, undef, $location->{'longitude'},
$location->{'latitude'}, undef, undef, undef, undef,
undef, undef, $self->{'main_event_id'}
);
return undef unless defined ($agent_id) and ($agent_id > 0);

View File

@ -1774,7 +1774,7 @@ sub api_call_url {
my $ua = LWP::UserAgent->new();
$ua->timeout($options->{lwp_timeout});
$ua->timeout($pa_config->{'tcp_timeout'});
# Enable environmental proxy settings
$ua->env_proxy;
# Enable in-memory cookie management