Merge branch 'ent-8735-vista-de-interfaces-referencia-mal-los-agentes' into 'develop'

Ent 8735 vista de interfaces referencia mal los agentes

See merge request artica/pandorafms!4800
This commit is contained in:
Daniel Rodriguez 2022-05-11 06:20:02 +00:00
commit 7168f1d848
3 changed files with 112 additions and 104 deletions

View File

@ -329,7 +329,7 @@ class AgentWizard extends HTML
} }
} }
if (count($this->datalist) === 1 && $this->targetIp === '') { if (empty($this->datalist) === false && count($this->datalist) === 1 && $this->targetIp === '') {
$this->targetIp = $this->datalist[0]; $this->targetIp = $this->datalist[0];
} }
} }

View File

@ -3236,8 +3236,8 @@ function agents_get_network_interfaces($agents=false, $agents_filter=false)
$ni_by_agents = []; $ni_by_agents = [];
foreach ($agents as $agent) { foreach ($agents as $agent) {
$agent_id = (isset($agent['id_agente'])) ? $agent['id_agente'] : $agent; $agent_id = (isset($agent['id_agente'])) ? $agent['id_agente'] : $agent;
$agent_group_id = (isset($agent['id_grupo']) === true) ? $agent['id_grupo'] : ''; $agent_group_id = (isset($agent['id_grupo']) === true) ? $agent['id_grupo'] : agents_get_agent_group($agent_id);
$agent_name = (isset($agent['alias']) === true) ? $agent['alias'] : ''; $agent_name = (isset($agent['alias']) === true) ? $agent['alias'] : agents_get_alias($agent_id);
$agent_interfaces = []; $agent_interfaces = [];
$accepted_module_types = []; $accepted_module_types = [];

View File

@ -552,14 +552,18 @@ function print_table(
$all_interfaces = []; $all_interfaces = [];
foreach ($data as $value) { foreach ($data as $key => $value) {
$agent_alias = agents_get_alias($value['name']); if (empty($value['name']) === false) {
$agent_alias = $value['name'];
} else {
$agent_alias = agents_get_alias($key);
}
foreach ($value['interfaces'] as $if_name => $interface) { foreach ($value['interfaces'] as $if_name => $interface) {
$interface['agent_id'] = $value['name']; $interface['agent_id'] = $key;
$interface['agent_alias'] = $agent_alias; $interface['agent_alias'] = $agent_alias;
$interface['if_name'] = $if_name; $interface['if_name'] = $if_name;
$all_interfaces[$if_name] = $interface; $all_interfaces[$key][$if_name] = $interface;
} }
} }
@ -569,117 +573,121 @@ function print_table(
) { ) {
$filtered_interfaces = $all_interfaces; $filtered_interfaces = $all_interfaces;
} else { } else {
// Filter interfaces array. foreach ($all_interfaces as $key => $value) {
$filtered_interfaces = array_filter( // Filter interfaces array.
$all_interfaces, $filtered_interfaces[$key] = array_filter(
function ($interface) use ($selected_interfaces) { $value,
return in_array( function ($interface) use ($selected_interfaces) {
$interface['status_module_id'], return in_array(
$selected_interfaces $interface['status_module_id'],
) === true; $selected_interfaces
} );
); }
);
}
} }
$data = []; $data = [];
foreach ($filtered_interfaces as $if_name => $agent_interfaces) { foreach ($filtered_interfaces as $interfaces) {
// Get usage modules. foreach ($interfaces as $if_name => $agent_interfaces) {
$usage_module_in = db_get_row( // Get usage modules.
'tagente_modulo', $usage_module_in = db_get_row(
'nombre', 'tagente_modulo',
$if_name.'_inUsage' 'nombre',
); $if_name.'_inUsage'
$usage_module_out = db_get_row( );
'tagente_modulo', $usage_module_out = db_get_row(
'nombre', 'tagente_modulo',
$if_name.'_outUsage' 'nombre',
); $if_name.'_outUsage'
);
$usage_module_id_in = $usage_module_in['id_agente_modulo']; $usage_module_id_in = $usage_module_in['id_agente_modulo'];
$usage_module_id_out = $usage_module_out['id_agente_modulo']; $usage_module_id_out = $usage_module_out['id_agente_modulo'];
$usage_module_description = $usage_module_in['descripcion']; $usage_module_description = $usage_module_in['descripcion'];
// Get usage modules data. // Get usage modules data.
$usage_module_data_in = modules_get_previous_data( $usage_module_data_in = modules_get_previous_data(
$usage_module_id_in, $usage_module_id_in,
time() time()
); );
$usage_module_data_out = modules_get_previous_data( $usage_module_data_out = modules_get_previous_data(
$usage_module_id_out, $usage_module_id_out,
time() time()
); );
// Extract ifSpeed from description of usage module. // Extract ifSpeed from description of usage module.
$if_speed_str = strstr($usage_module_description, 'Speed:'); $if_speed_str = strstr($usage_module_description, 'Speed:');
$if_speed_str = substr($if_speed_str, 0, -1); $if_speed_str = substr($if_speed_str, 0, -1);
$if_speed_str = explode(':', $if_speed_str)[1]; $if_speed_str = explode(':', $if_speed_str)[1];
$matches = []; $matches = [];
preg_match_all('/\d+/', $if_speed_str, $matches); preg_match_all('/\d+/', $if_speed_str, $matches);
$if_speed_value = $matches[0][0]; $if_speed_value = $matches[0][0];
// Transform ifSpeed unit. // Transform ifSpeed unit.
$divisor = 1000; $divisor = 1000;
$counter = 0; $counter = 0;
while ($if_speed_value >= $divisor) { while ($if_speed_value >= $divisor) {
if ($if_speed_value >= $divisor) { if ($if_speed_value >= $divisor) {
$if_speed_value = ($if_speed_value / $divisor); $if_speed_value = ($if_speed_value / $divisor);
}
$counter++;
} }
$counter++; $if_speed_unit = 'bps';
switch ($counter) {
case 1:
$if_speed_unit = 'Kbps';
break;
case 2:
$if_speed_unit = 'Mbps';
break;
case 3:
$if_speed_unit = 'Gbps';
break;
case 4:
$if_speed_unit = 'Tbps';
break;
default:
$if_speed_unit = 'bps';
break;
}
// Get in and out traffic.
$ifInOctets = modules_get_previous_data(
$agent_interfaces['traffic']['in'],
time()
);
$ifOutOctets = modules_get_previous_data(
$agent_interfaces['traffic']['out'],
time()
);
if ($sec === 'view') {
$table_data[$loop_index]['if_agent_name'] = '<a href="index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=main&id_agente='.$agent_interfaces['agent_id'].'">'.$agent_interfaces['agent_alias'].'</a>';
}
$table_data[$loop_index]['if_name'] = $agent_interfaces['if_name'];
$table_data[$loop_index]['if_status_image'] = $agent_interfaces['status_image'];
$table_data[$loop_index]['if_speed_data'] = ($if_speed_value === null) ? __('N/A') : $if_speed_value.' '.$if_speed_unit;
$table_data[$loop_index]['if_in_octets'] = ($ifInOctets['datos'] === null) ? __('N/A') : $ifInOctets['datos'];
$table_data[$loop_index]['if_out_octets'] = ($ifOutOctets['datos'] === null) ? __('N/A') : $ifOutOctets['datos'];
$table_data[$loop_index]['if_usage_module_data_in'] = ($usage_module_data_in['datos'] === null) ? __('N/A') : $usage_module_data_in['datos'];
$table_data[$loop_index]['if_usage_module_data_out'] = ($usage_module_data_out['datos'] === null) ? __('N/A') : $usage_module_data_out['datos'];
$table_data[$loop_index]['if_last_data'] = human_time_comparation($agent_interfaces['last_contact']);
$loop_index++;
} }
$if_speed_unit = 'bps';
switch ($counter) {
case 1:
$if_speed_unit = 'Kbps';
break;
case 2:
$if_speed_unit = 'Mbps';
break;
case 3:
$if_speed_unit = 'Gbps';
break;
case 4:
$if_speed_unit = 'Tbps';
break;
default:
$if_speed_unit = 'bps';
break;
}
// Get in and out traffic.
$ifInOctets = modules_get_previous_data(
$agent_interfaces['traffic']['in'],
time()
);
$ifOutOctets = modules_get_previous_data(
$agent_interfaces['traffic']['out'],
time()
);
if ($sec === 'view') {
$table_data[$loop_index]['if_agent_name'] = '<a href="index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=main&id_agente='.$agent_interfaces['agent_id'].'">'.$agent_interfaces['agent_alias'].'</a>';
}
$table_data[$loop_index]['if_name'] = $agent_interfaces['if_name'];
$table_data[$loop_index]['if_status_image'] = $agent_interfaces['status_image'];
$table_data[$loop_index]['if_speed_data'] = ($if_speed_value === null) ? __('N/A') : $if_speed_value.' '.$if_speed_unit;
$table_data[$loop_index]['if_in_octets'] = ($ifInOctets['datos'] === null) ? __('N/A') : $ifInOctets['datos'];
$table_data[$loop_index]['if_out_octets'] = ($ifOutOctets['datos'] === null) ? __('N/A') : $ifOutOctets['datos'];
$table_data[$loop_index]['if_usage_module_data_in'] = ($usage_module_data_in['datos'] === null) ? __('N/A') : $usage_module_data_in['datos'];
$table_data[$loop_index]['if_usage_module_data_out'] = ($usage_module_data_out['datos'] === null) ? __('N/A') : $usage_module_data_out['datos'];
$table_data[$loop_index]['if_last_data'] = human_time_comparation($agent_interfaces['last_contact']);
$loop_index++;
} }
// Sort array of previously processed table values. // Sort array of previously processed table values.