Changed the agent name by its alias and fixed the exception reporting item

This commit is contained in:
Alejandro Gallardo Escobar 2017-02-23 12:59:24 +01:00
parent 289549a49f
commit 2f3053ebbd

View File

@ -1867,6 +1867,7 @@ function reporting_exception($report, $content, $type = 'dinamic',
$max = $min; $max = $min;
$avg = 0; $avg = 0;
$items = array();
$i = 0; $i = 0;
foreach ($exceptions as $exc) { foreach ($exceptions as $exc) {
@ -1881,9 +1882,9 @@ function reporting_exception($report, $content, $type = 'dinamic',
} }
$ag_name = modules_get_agentmodule_agent_name($exc['id_agent_module']); $ag_name = modules_get_agentmodule_agent_name($exc['id_agent_module']);
$ag_alias = modules_get_agentmodule_agent_alias($exc['id_agent_module']);
$mod_name = modules_get_agentmodule_name($exc['id_agent_module']); $mod_name = modules_get_agentmodule_name($exc['id_agent_module']);
$unit = db_get_value('unit', 'tagente_modulo', $unit = db_get_value('unit', 'tagente_modulo', 'id_agente_modulo', $exc['id_agent_module']);
'id_agente_modulo', $exc['id_agent_module']);
if ($content['period'] == 0) { if ($content['period'] == 0) {
$value = $value =
@ -1954,18 +1955,21 @@ function reporting_exception($report, $content, $type = 'dinamic',
break; break;
} }
$i++; $item = array();
$data_exceptions[] = $value; $item['value'] = $value;
$id_agent_module[] = $exc['id_agent_module']; $item['module_id'] = $exc['id_agent_module'];
$agent_name[] = $ag_name; $item['module'] = $mod_name;
$module_name[] = $mod_name; $item['agent'] = $ag_alias;
$units[] = $unit; $item['unit'] = $unit;
if ($exc['operation'] == 'avg') { if ($exc['operation'] == 'avg') {
$operation[] = "rate"; $item['operation'] = "rate";
} }
else { else {
$operation[] = $exc['operation']; $item['operation'] = $exc['operation'];
} }
$items[] = $item;
$i++;
} }
//Restore dbconnection //Restore dbconnection
if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) {
@ -2008,65 +2012,63 @@ function reporting_exception($report, $content, $type = 'dinamic',
else { else {
$avg = $avg / $i; $avg = $avg / $i;
// Sort the items
$sort_number = function ($a, $b, $sort = SORT_ASC) {
if ($a == $b) return 0;
else if ($a > $b) return ($sort === SORT_ASC) ? 1 : -1;
else return ($sort === SORT_ASC) ? -1 : 1;
};
$sort_string = function ($a, $b, $sort = SORT_ASC) {
if ($sort === SORT_ASC) return strcasecmp($a, $b);
else return strcasecmp($b, $a);
};
usort($items, function($a, $b) use ($order_uptodown, $sort_number, $sort_string) {
switch ($order_uptodown) { switch ($order_uptodown) {
//Order descending
case 1: case 1:
array_multisort($data_exceptions, SORT_DESC,
$agent_name, SORT_ASC, $module_name, SORT_ASC,
$id_agent_module, SORT_ASC);
break;
//Order ascending
case 2: case 2:
array_multisort($data_exceptions, SORT_ASC, if ($a['value'] == $b['value']) {
$agent_name, SORT_ASC, $module_name, SORT_ASC, if ($a['agent'] == $b['agent']) {
$id_agent_module, SORT_ASC); if ($a['module'] == $b['module']) {
break; return $sort_number($a['module_id'], $b['module_id']);
}
return $sort_string($a['module'], $b['module']);
}
return $sort_string($a['agent'], $b['agent']);
}
return $sort_number($a['value'], $b['value'], ($order_uptodown == 1) ? SORT_DESC : SORT_ASC);
//Order by agent name or without selection //Order by agent name or without selection
case 0: case 0:
case 3: case 3:
array_multisort($agent_name, SORT_ASC, if ($a['agent'] == $b['agent']) {
$data_exceptions, SORT_ASC, $module_name, if ($a['value'] == $b['value']) {
SORT_ASC, $id_agent_module, SORT_ASC); if ($a['module'] == $b['module']) {
break; return $sort_number($a['module_id'], $b['module_id']);
} }
return $sort_string($a['module'], $b['module']);
}
return $sort_number($a['value'], $b['value']);
}
return $sort_string($a['agent'], $b['agent']);
}
});
if ($order_uptodown == 1 || $order_uptodown == 2) {
$j = 0;
$data_pie_graph = array(); $data_pie_graph = array();
$data_hbar = array(); $data_hbar = array();
foreach ($data_exceptions as $dex) { foreach ($items as $key => $item) {
$data_hbar[$agent_name[$j]]['g'] = $dex; if ($show_graph == 1 || $show_graph == 2) {
$data_pie_graph[$agent_name[$j]] = $dex; // TODO: Find a better way to show the graphs
$data_hbar[$item['agent'] . ' - ' . $item['operation']]['g'] = $item['value'];
$data_pie_graph[$item['agent'] . ' - ' . $item['operation']] = $item['value'];
}
if ($show_graph == 0 || $show_graph == 1) { if ($show_graph == 0 || $show_graph == 1) {
$data = array(); $data = array();
$data['agent'] = $agent_name[$j]; $data['agent'] = $item['agent'];
$data['module'] = $module_name[$j]; $data['module'] = $item['module'];
$data['operation'] = __($operation[$j]); $data['operation'] = __($item['operation']);
$data['value'] = $dex; $data['value'] = $item['value'];
$data['formated_value'] = format_for_graph($dex, 2) . " " . $units[$j]; $data['formated_value'] = format_for_graph($item['value'], 2) . " " . $item['unit'];
$return['data'][] = $data; $return['data'][] = $data;
} }
$j++;
}
}
else if ($order_uptodown == 0 || $order_uptodown == 3) {
$j = 0;
$data_pie_graph = array();
$data_hbar = array();
foreach ($agent_name as $an) {
$data_hbar[$an]['g'] = $data_exceptions[$j];
$data_pie_graph[$an] = $data_exceptions[$j];
if ($show_graph == 0 || $show_graph == 1) {
$data = array();
$data['agent'] = $an;
$data['module'] = $module_name[$j];
$data['operation'] = __($operation[$j]);
$data['value'] = $data_exceptions[$j];
$data['formated_value'] = format_for_graph($data_exceptions[$j], 2) . " " . $units[$j];
$return['data'][] = $data;
}
$j++;
}
} }
if ($show_graph == 1 || $show_graph == 2) { if ($show_graph == 1 || $show_graph == 2) {