Now the interface information don't show duplicated interfaces

This commit is contained in:
Alejandro Gallardo Escobar 2014-09-25 16:02:21 +02:00
parent 923d2b686e
commit 8ed3aee0b7
1 changed files with 113 additions and 97 deletions

View File

@ -377,11 +377,33 @@ $columns = array(
);
$filter = array(
"id_agente" => $id_agente,
"id_tipo_modulo" => (int)db_get_value("id_tipo", "ttipo_modulo", "nombre", "remote_snmp_proc")
"id_tipo_modulo" => (int)db_get_value("id_tipo", "ttipo_modulo", "nombre", "remote_snmp_proc"),
"disabled" => 0
);
$modules = agents_get_modules($id_agente, $columns, $filter);
$modules = agents_get_modules($id_agente, $columns, $filter, true, false);
$interfaces = array();
if (!empty($modules)) {
foreach ($modules as $key => $module) {
// Trying to get the interface name from the module name
if (preg_match ("/_(.+)$/", (string)$module['nombre'], $matches)) {
if ($matches[1]) {
$interface_name = $matches[1];
$interface_name_escaped = str_replace("/", "\/", $interface_name);
if (!isset($interfaces[$interface_name])
|| (isset($interfaces[$interface_name])
&& preg_match ("/^ifOperStatus_$interface_name_escaped$/i", (string)$module['nombre'], $matches))) {
$interfaces[$interface_name] = $module;
}
}
}
}
unset($modules);
if (!empty($interfaces)) {
$table_interface = new stdClass();
$table_interface->id = 'agent_interface_info';
$table_interface->class = 'databox';
@ -400,12 +422,8 @@ if (! empty($modules)) {
$table_interface->head_colspan[0] = 5;
$table_interface->data = array();
foreach ($modules as $key => $module) {
// Trying to get the interface name from the module name
if (preg_match ("/_(.+)$/", (string)$module['nombre'], $matches)) {
if ($matches[1]) {
$interface_name = $matches[1];
foreach ($interfaces as $interface_name => $module) {
$interface_name_escaped = str_replace("/", "\/", $interface_name);
$module_id = $module['id_agente_modulo'];
$db_status = modules_get_agentmodule_status($module_id);
@ -422,11 +440,11 @@ if (! empty($modules)) {
$ip_target = $matches[0];
}
}
$description = "--";
$mac = "--";
// Trying to get something like a mac from the description
if (preg_match ("/([0-9a-f]{1,2}[\.:-]){5}([0-9a-f]{1,2})/i", (string)$module['descripcion'], $matches)) {
if ($matches[0]) {
$description = $matches[0];
$mac = $matches[0];
}
}
@ -440,7 +458,7 @@ if (! empty($modules)) {
$interface_traffic_modules_aux = array('in' => '', 'out' => '');
foreach ($interface_traffic_modules as $interface_traffic_module) {
$interface_name_escaped = str_replace("/", "\/", $interface_name);
if (preg_match ("/if(.+)Octets_$interface_name_escaped$/i", $interface_traffic_module['nombre'], $matches)) {
if (preg_match ("/^if(.+)Octets_$interface_name_escaped$/i", $interface_traffic_module['nombre'], $matches)) {
if (strtolower($matches[1]) == 'in') {
$interface_traffic_modules_aux['in'] = $interface_traffic_module['id_agente_modulo'];
}
@ -482,12 +500,10 @@ if (! empty($modules)) {
$data['interface_status'] = $status;
$data['interface_graph'] = $graph_link;
$data['interface_ip'] = $ip_target;
$data['interface_mac'] = $description;
$data['interface_mac'] = $mac;
$table_interface->data[] = $data;
}
}
}
unset($modules);
// This javascript piece of code is used to make expandible the body of the table
?>