Fixed problems with count agents and modules in group view. Tiquets: #3289, #3297

This commit is contained in:
m-lopez-f 2016-02-01 11:36:26 +01:00
parent a65346bef0
commit 64dd3e99ad
1 changed files with 126 additions and 94 deletions

View File

@ -105,6 +105,12 @@ function groupview_get_all_data ($id_user = false, $user_strict = false, $acltag
$list[$group['id_grupo']]['_monitors_unknown_'] = 0;
$list[$group['id_grupo']]['_monitors_not_init_'] = 0;
$list[$group['id_grupo']]['_monitors_ok_'] = 0;
$list[$group['id_grupo']]['_agents_not_init_'] = 0;
$list[$group['id_grupo']]['_agents_unknown_'] = 0;
$list[$group['id_grupo']]['_total_agents_'] = 0;
$list[$group['id_grupo']]["_monitor_checks_"] = 0;
$list[$group['id_grupo']]["_monitor_not_normal_"] = 0;
$list[$group['id_grupo']]['_monitors_alerts_fired_'] = 0;
}
if ($list_groups == false) {
$list_groups = array();
@ -138,7 +144,7 @@ function groupview_get_all_data ($id_user = false, $user_strict = false, $acltag
$list[$group['id_grupo']]["_monitor_checks_"] = $list[$group['id_grupo']]["_monitors_not_init_"] + $list[$group['id_grupo']]["_monitors_unknown_"] + $list[$group['id_grupo']]["_monitors_warning_"] + $list[$group['id_grupo']]["_monitors_critical_"] + $list[$group['id_grupo']]["_monitors_ok_"];
// Calculate not_normal monitors
$list[$group['id_grupo']]["_monitor_not_normal_"] = $list["_monitor_checks_"] - $list["_monitors_ok_"];
$list[$group['id_grupo']]["_monitor_not_normal_"] = $list[$group['id_grupo']]["_monitor_checks_"] - $list[$group['id_grupo']]["_monitors_ok_"];
$total_agents = $list[$group['id_grupo']]['_total_agents_'];
@ -235,52 +241,62 @@ function groupview_get_all_data ($id_user = false, $user_strict = false, $acltag
}
else {
foreach ($list_groups as $group) {
$group_agents = db_get_row_sql("SELECT SUM(warning_count) AS _monitors_warning_,
SUM(critical_count) AS _monitors_critical_,
SUM(normal_count) AS _monitors_ok_,
SUM(unknown_count) AS _monitors_unknown_,
SUM(notinit_count) AS _monitors_not_init_,
SUM(fired_count) AS _monitors_alerts_fired_,
COUNT(*) AS _total_agents_, id_grupo, intervalo,
ultimo_contacto, disabled
FROM tagente WHERE id_grupo = " . $group['id_grupo'] . " AND disabled = 0 GROUP BY id_grupo");
$list[$group['id_grupo']]['_monitors_critical_'] = (int)$group_agents['_monitors_critical_'];
$list[$group['id_grupo']]['_monitors_warning_'] = (int)$group_agents['_monitors_warning_'];
$list[$group['id_grupo']]['_monitors_unknown_'] = (int)$group_agents['_monitors_unknown_'];
$list[$group['id_grupo']]['_monitors_not_init_'] = (int)$group_agents['_monitors_not_init_'];
$list[$group['id_grupo']]['_monitors_ok_'] = (int)$group_agents['_monitors_ok_'];
$list[$group['id_grupo']]['_monitors_alerts_fired_'] = (int)$group_agents['_monitors_alerts_fired_'];
$list[$group['id_grupo']]['_total_agents_'] = (int)$group_agents['_total_agents_'];
$list[$group['id_grupo']]["_monitor_checks_"] = $list[$group['id_grupo']]["_monitors_not_init_"] + $list[$group['id_grupo']]["_monitors_unknown_"] + $list[$group['id_grupo']]["_monitors_warning_"] + $list[$group['id_grupo']]["_monitors_critical_"] + $list[$group['id_grupo']]["_monitors_ok_"];
// Calculate not_normal monitors
$list[$group['id_grupo']]["_monitor_not_normal_"] = $list["_monitor_checks_"] - $list["_monitors_ok_"];
$total_agents = $list[$group['id_grupo']]['_total_agents_'];
if (($group['id_grupo'] != 0) && ($total_agents > 0)) {
$agents = db_get_all_rows_sql("SELECT warning_count,
critical_count,
normal_count,
unknown_count,
notinit_count,
fired_count,
disabled
FROM tagente
WHERE id_grupo = " . $group['id_grupo'] );
foreach ($agents as $agent) {
if (($agent['critical_count'] == 0) && ($agent['warning_count'] == 0) && ($group_agents['disabled'] == 0) && ($agent['normal_count'] == 0)) {
if ($agent['unknown_count'] > 0) {
$list[$group['id_grupo']]['_agents_unknown_'] += 1;
}
}
if (($agent['critical_count'] == 0) && ($agent['warning_count'] == 0) && ($group_agents['disabled'] == 0) && ($agent['normal_count'] == 0) && ($agent['unknown_count'] == 0)) {
if ($agent['notinit_count'] > 0) {
$list[$group['id_grupo']]['_agents_not_init_'] += 1;
}
$agent_not_init = agents_get_agents(array (
'disabled' => 0,
'id_grupo' => $group['id_grupo'],
'status' => AGENT_STATUS_NOT_INIT),
array ('COUNT(*) as total'), 'AR', false);
$list[$group['id_grupo']]['_agents_not_init_'] = isset ($agent_not_init[0]['total']) ? $agent_not_init[0]['total'] : 0;
$agent_unknown = agents_get_agents(array (
'disabled' => 0,
'id_grupo' => $group['id_grupo'],
'status' => AGENT_STATUS_UNKNOWN),
array ('COUNT(*) as total'), 'AR', false);
$list[$group['id_grupo']]['_agents_unknown_'] = isset ($agent_unknown[0]['total']) ? $agent_unknown[0]['total'] : 0;
$agent_total = agents_get_agents(array (
'disabled' => 0,
'id_grupo' => $group['id_grupo']),
array ('COUNT(*) as total'), 'AR', false);
$list[$group['id_grupo']]['_total_agents_'] = isset ($agent_total[0]['total']) ? $agent_total[0]['total'] : 0;
$list[$group['id_grupo']]["_monitor_not_normal_"] = $list[$group['id_grupo']]["_monitor_checks_"] - $list[$group['id_grupo']]["_monitors_ok_"];
$list[$group['id_grupo']]["_monitor_not_normal_"] = $list[$group['id_grupo']]["_monitor_checks_"] - $list[$group['id_grupo']]["_monitors_ok_"];
$list[$group['id_grupo']]['_monitors_alerts_fired_'] = groupview_monitor_fired_alerts ($group['id_grupo'], $user_strict,$group['id_grupo']);
$result_list = db_get_all_rows_sql("SELECT COUNT(*) as contado, estado
FROM tagente_estado tae INNER JOIN tagente ta
ON tae.id_agente = ta.id_agente
AND ta.disabled = 0
AND ta.id_grupo = " . $group['id_grupo'] . "
INNER JOIN tagente_modulo tam
ON tae.id_agente_modulo = tam.id_agente_modulo
AND tam.disabled = 0
GROUP BY estado");
if ($result_list) {
foreach ($result_list as $result) {
switch ($result['estado']) {
case AGENT_MODULE_STATUS_CRITICAL_ALERT:
break;
case AGENT_MODULE_STATUS_CRITICAL_BAD:
$list[$group['id_grupo']]['_monitors_critical_'] += (int)$result['contado'];
break;
case AGENT_MODULE_STATUS_WARNING_ALERT:
break;
case AGENT_MODULE_STATUS_WARNING:
$list[$group['id_grupo']]['_monitors_warning_'] += (int)$result['contado'];
break;
case AGENT_MODULE_STATUS_UNKNOWN:
$list[$group['id_grupo']]['_monitors_unknown_'] += (int)$result['contado'];
break;
case AGENT_MODULE_STATUS_NO_DATA:
case AGENT_MODULE_STATUS_NOT_INIT:
$list[$group['id_grupo']]['_monitors_not_init_'] += (int)$result['contado'];
break;
case AGENT_MODULE_STATUS_NORMAL_ALERT:
break;
case AGENT_MODULE_STATUS_NORMAL:
$list[$group['id_grupo']]['_monitors_ok_'] += (int)$result['contado'];
break;
}
}
}
@ -639,6 +655,12 @@ function groupview_get_data ($id_user = false, $user_strict = false, $acltags, $
$list[$group['id_grupo']]['_monitors_unknown_'] = 0;
$list[$group['id_grupo']]['_monitors_not_init_'] = 0;
$list[$group['id_grupo']]['_monitors_ok_'] = 0;
$list[$group['id_grupo']]['_agents_not_init_'] = 0;
$list[$group['id_grupo']]['_agents_unknown_'] = 0;
$list[$group['id_grupo']]['_total_agents_'] = 0;
$list[$group['id_grupo']]["_monitor_checks_"] = 0;
$list[$group['id_grupo']]["_monitor_not_normal_"] = 0;
$list[$group['id_grupo']]['_monitors_alerts_fired_'] = 0;
}
if ($list_groups == false) {
@ -771,53 +793,62 @@ function groupview_get_data ($id_user = false, $user_strict = false, $acltags, $
if (!$user_strict) {
foreach ($list_groups as $group) {
$group_agents = db_get_row_sql("SELECT SUM(warning_count) AS _monitors_warning_,
SUM(critical_count) AS _monitors_critical_,
SUM(normal_count) AS _monitors_ok_,
SUM(unknown_count) AS _monitors_unknown_,
SUM(notinit_count) AS _monitors_not_init_,
SUM(fired_count) AS _monitors_alerts_fired_,
COUNT(*) AS _total_agents_, id_grupo, intervalo,
ultimo_contacto, disabled
FROM tagente WHERE id_grupo = " . $group['id_grupo'] . " AND disabled = 0 GROUP BY id_grupo");
$list[$group['id_grupo']]['_monitors_critical_'] = (int)$group_agents['_monitors_critical_'];
$list[$group['id_grupo']]['_monitors_warning_'] = (int)$group_agents['_monitors_warning_'];
$list[$group['id_grupo']]['_monitors_unknown_'] = (int)$group_agents['_monitors_unknown_'];
$list[$group['id_grupo']]['_monitors_not_init_'] = (int)$group_agents['_monitors_not_init_'];
$list[$group['id_grupo']]['_monitors_ok_'] = (int)$group_agents['_monitors_ok_'];
$list[$group['id_grupo']]['_monitors_alerts_fired_'] = (int)$group_agents['_monitors_alerts_fired_'];
$list[$group['id_grupo']]['_total_agents_'] = (int)$group_agents['_total_agents_'];
$list[$group['id_grupo']]["_monitor_checks_"] = $list[$group['id_grupo']]["_monitors_not_init_"] + $list[$group['id_grupo']]["_monitors_unknown_"] + $list[$group['id_grupo']]["_monitors_warning_"] + $list[$group['id_grupo']]["_monitors_critical_"] + $list[$group['id_grupo']]["_monitors_ok_"];
// Calculate not_normal monitors
$list[$group['id_grupo']]["_monitor_not_normal_"] = $list["_monitor_checks_"] - $list["_monitors_ok_"];
$list[$group['id_grupo']]["_iconImg_"] = html_print_image ("images/".$group['icon'].".png", true, array ("style" => 'vertical-align: middle;'));
$total_agents = $list[$group['id_grupo']]['_total_agents_'];
if (($group['id_grupo'] != 0) && ($total_agents > 0)) {
$agents = db_get_all_rows_sql("SELECT warning_count,
critical_count,
normal_count,
unknown_count,
notinit_count,
fired_count,
disabled
FROM tagente
WHERE id_grupo = " . $group['id_grupo'] );
foreach ($agents as $agent) {
if (($agent['critical_count'] == 0) && ($agent['warning_count'] == 0) && ($group_agents['disabled'] == 0) && ($agent['normal_count'] == 0)) {
if ($agent['unknown_count'] > 0) {
$list[$group['id_grupo']]['_agents_unknown_'] += 1;
}
}
if (($agent['critical_count'] == 0) && ($agent['warning_count'] == 0) && ($group_agents['disabled'] == 0) && ($agent['normal_count'] == 0) && ($agent['unknown_count'] == 0)) {
if ($agent['notinit_count'] > 0) {
$list[$group['id_grupo']]['_agents_not_init_'] += 1;
}
$agent_not_init = agents_get_agents(array (
'disabled' => 0,
'id_grupo' => $group['id_grupo'],
'status' => AGENT_STATUS_NOT_INIT),
array ('COUNT(*) as total'), 'AR', false);
$list[$group['id_grupo']]['_agents_not_init_'] = isset ($agent_not_init[0]['total']) ? $agent_not_init[0]['total'] : 0;
$agent_unknown = agents_get_agents(array (
'disabled' => 0,
'id_grupo' => $group['id_grupo'],
'status' => AGENT_STATUS_UNKNOWN),
array ('COUNT(*) as total'), 'AR', false);
$list[$group['id_grupo']]['_agents_unknown_'] = isset ($agent_unknown[0]['total']) ? $agent_unknown[0]['total'] : 0;
$agent_total = agents_get_agents(array (
'disabled' => 0,
'id_grupo' => $group['id_grupo']),
array ('COUNT(*) as total'), 'AR', false);
$list[$group['id_grupo']]['_total_agents_'] = isset ($agent_total[0]['total']) ? $agent_total[0]['total'] : 0;
$list[$group['id_grupo']]["_monitor_not_normal_"] = $list[$group['id_grupo']]["_monitor_checks_"] - $list[$group['id_grupo']]["_monitors_ok_"];
$list[$group['id_grupo']]["_monitor_not_normal_"] = $list[$group['id_grupo']]["_monitor_checks_"] - $list[$group['id_grupo']]["_monitors_ok_"];
$list[$group['id_grupo']]['_monitors_alerts_fired_'] = groupview_monitor_fired_alerts ($group['id_grupo'], $user_strict,$group['id_grupo']);
$result_list = db_get_all_rows_sql("SELECT COUNT(*) as contado, estado
FROM tagente_estado tae INNER JOIN tagente ta
ON tae.id_agente = ta.id_agente
AND ta.disabled = 0
AND ta.id_grupo = " . $group['id_grupo'] . "
INNER JOIN tagente_modulo tam
ON tae.id_agente_modulo = tam.id_agente_modulo
AND tam.disabled = 0
GROUP BY estado");
if ($result_list) {
foreach ($result_list as $result) {
switch ($result['estado']) {
case AGENT_MODULE_STATUS_CRITICAL_ALERT:
break;
case AGENT_MODULE_STATUS_CRITICAL_BAD:
$list[$group['id_grupo']]['_monitors_critical_'] += (int)$result['contado'];
break;
case AGENT_MODULE_STATUS_WARNING_ALERT:
break;
case AGENT_MODULE_STATUS_WARNING:
$list[$group['id_grupo']]['_monitors_warning_'] += (int)$result['contado'];
break;
case AGENT_MODULE_STATUS_UNKNOWN:
$list[$group['id_grupo']]['_monitors_unknown_'] += (int)$result['contado'];
break;
case AGENT_MODULE_STATUS_NO_DATA:
case AGENT_MODULE_STATUS_NOT_INIT:
$list[$group['id_grupo']]['_monitors_not_init_'] += (int)$result['contado'];
break;
case AGENT_MODULE_STATUS_NORMAL_ALERT:
break;
case AGENT_MODULE_STATUS_NORMAL:
$list[$group['id_grupo']]['_monitors_ok_'] += (int)$result['contado'];
break;
}
}
}
@ -871,6 +902,7 @@ function groupview_order_groups_for_parents ($view_groups) {
}
// Build the group hierarchy
foreach ($groups as $id => $group) {
$groups[$id]['have_parent'] = false;
if (!isset($groups[$id]['parent']))
continue;
$parent = $groups[$id]['parent'];