Fixes on the agent and monitor counter functions

This commit is contained in:
Alejandro Gallardo Escobar 2015-03-12 15:05:54 +01:00
parent 28c9f19320
commit b84bef8547
2 changed files with 135 additions and 61 deletions

View File

@ -1206,6 +1206,7 @@ function groups_get_agents_counter ($group, $agent_filter = array(), $module_fil
$module_name_filter = "";
$module_status_filter = "";
$module_status_array = array();
if (!empty($module_filter)) {
// IMPORTANT: The module filters will force the realtime search
$realtime = true;
@ -1222,48 +1223,47 @@ function groups_get_agents_counter ($group, $agent_filter = array(), $module_fil
else
$module_status = array($module_status);
$status_array = "";
foreach ($module_status as $status) {
switch ($status) {
case AGENT_MODULE_STATUS_ALL:
$status_array[] = AGENT_MODULE_STATUS_CRITICAL_ALERT;
$status_array[] = AGENT_MODULE_STATUS_CRITICAL_BAD;
$status_array[] = AGENT_MODULE_STATUS_WARNING_ALERT;
$status_array[] = AGENT_MODULE_STATUS_WARNING;
$status_array[] = AGENT_MODULE_STATUS_UNKNOWN;
$status_array[] = AGENT_MODULE_STATUS_NO_DATA;
$status_array[] = AGENT_MODULE_STATUS_NOT_INIT;
$status_array[] = AGENT_MODULE_STATUS_NORMAL_ALERT;
$status_array[] = AGENT_MODULE_STATUS_NORMAL;
$module_status_array[] = AGENT_MODULE_STATUS_CRITICAL_ALERT;
$module_status_array[] = AGENT_MODULE_STATUS_CRITICAL_BAD;
$module_status_array[] = AGENT_MODULE_STATUS_WARNING_ALERT;
$module_status_array[] = AGENT_MODULE_STATUS_WARNING;
$module_status_array[] = AGENT_MODULE_STATUS_UNKNOWN;
$module_status_array[] = AGENT_MODULE_STATUS_NO_DATA;
$module_status_array[] = AGENT_MODULE_STATUS_NOT_INIT;
$module_status_array[] = AGENT_MODULE_STATUS_NORMAL_ALERT;
$module_status_array[] = AGENT_MODULE_STATUS_NORMAL;
break;
case AGENT_MODULE_STATUS_CRITICAL_ALERT:
case AGENT_MODULE_STATUS_CRITICAL_BAD:
$status_array[] = AGENT_MODULE_STATUS_CRITICAL_ALERT;
$status_array[] = AGENT_MODULE_STATUS_CRITICAL_BAD;
$module_status_array[] = AGENT_MODULE_STATUS_CRITICAL_ALERT;
$module_status_array[] = AGENT_MODULE_STATUS_CRITICAL_BAD;
break;
case AGENT_MODULE_STATUS_WARNING_ALERT:
case AGENT_MODULE_STATUS_WARNING:
$status_array[] = AGENT_MODULE_STATUS_WARNING_ALERT;
$status_array[] = AGENT_MODULE_STATUS_WARNING;
$module_status_array[] = AGENT_MODULE_STATUS_WARNING_ALERT;
$module_status_array[] = AGENT_MODULE_STATUS_WARNING;
break;
case AGENT_MODULE_STATUS_UNKNOWN:
$status_array[] = AGENT_MODULE_STATUS_UNKNOWN;
$module_status_array[] = AGENT_MODULE_STATUS_UNKNOWN;
break;
case AGENT_MODULE_STATUS_NO_DATA:
case AGENT_MODULE_STATUS_NOT_INIT:
$status_array[] = AGENT_MODULE_STATUS_NO_DATA;
$status_array[] = AGENT_MODULE_STATUS_NOT_INIT;
$module_status_array[] = AGENT_MODULE_STATUS_NO_DATA;
$module_status_array[] = AGENT_MODULE_STATUS_NOT_INIT;
break;
case AGENT_MODULE_STATUS_NORMAL_ALERT:
case AGENT_MODULE_STATUS_NORMAL:
$status_array[] = AGENT_MODULE_STATUS_NORMAL_ALERT;
$status_array[] = AGENT_MODULE_STATUS_NORMAL;
$module_status_array[] = AGENT_MODULE_STATUS_NORMAL_ALERT;
$module_status_array[] = AGENT_MODULE_STATUS_NORMAL;
break;
}
}
if (!empty($status_array)) {
$status_array = array_unique($status_array);
$status_str = implode(",", $status_array);
if (!empty($module_status_array)) {
$module_status_array = array_unique($module_status_array);
$status_str = implode(",", $module_status_array);
$module_status_filter = "INNER JOIN tagente_estado AS tae
ON tam.id_agente_modulo = tae.id_agente_modulo
@ -1296,12 +1296,48 @@ function groups_get_agents_counter ($group, $agent_filter = array(), $module_fil
foreach ($agents as $agent) {
$agent_filter["id"] = $agent["id"];
$total = (int) groups_get_total_monitors ($group, $agent_filter, $module_filter, $strict_user, $groups_and_tags, $realtime);
$critical = (int) groups_get_critical_monitors ($group, $agent_filter, $module_filter, $strict_user, $groups_and_tags, $realtime);
$warning = (int) groups_get_warning_monitors ($group, $agent_filter, $module_filter, $strict_user, $groups_and_tags, $realtime);
$unknown = (int) groups_get_unknown_monitors ($group, $agent_filter, $module_filter, $strict_user, $groups_and_tags, $realtime);
$not_init = (int) groups_get_not_init_monitors ($group, $agent_filter, $module_filter, $strict_user, $groups_and_tags, $realtime);
$normal = (int) groups_get_normal_monitors ($group, $agent_filter, $module_filter, $strict_user, $groups_and_tags, $realtime);
$total = 0;
$critical = 0;
$warning = 0;
$unknown = 0;
$not_init = 0;
$normal = 0;
if (empty($module_status_array)) {
$total = (int) groups_get_total_monitors ($group, $agent_filter, $module_filter, $strict_user, $groups_and_tags, $realtime);
$critical = (int) groups_get_critical_monitors ($group, $agent_filter, $module_filter, $strict_user, $groups_and_tags, $realtime);
$warning = (int) groups_get_warning_monitors ($group, $agent_filter, $module_filter, $strict_user, $groups_and_tags, $realtime);
$unknown = (int) groups_get_unknown_monitors ($group, $agent_filter, $module_filter, $strict_user, $groups_and_tags, $realtime);
$not_init = (int) groups_get_not_init_monitors ($group, $agent_filter, $module_filter, $strict_user, $groups_and_tags, $realtime);
$normal = (int) groups_get_normal_monitors ($group, $agent_filter, $module_filter, $strict_user, $groups_and_tags, $realtime);
}
else {
foreach ($module_status_array as $status) {
switch ($status) {
case AGENT_MODULE_STATUS_CRITICAL_ALERT:
case AGENT_MODULE_STATUS_CRITICAL_BAD:
$critical = (int) groups_get_critical_monitors ($group, $agent_filter, $module_filter, $strict_user, $groups_and_tags, $realtime);
break;
case AGENT_MODULE_STATUS_WARNING_ALERT:
case AGENT_MODULE_STATUS_WARNING:
$warning = (int) groups_get_warning_monitors ($group, $agent_filter, $module_filter, $strict_user, $groups_and_tags, $realtime);
break;
case AGENT_MODULE_STATUS_UNKNOWN:
$unknown = (int) groups_get_unknown_monitors ($group, $agent_filter, $module_filter, $strict_user, $groups_and_tags, $realtime);
break;
case AGENT_MODULE_STATUS_NO_DATA:
case AGENT_MODULE_STATUS_NOT_INIT:
$not_init = (int) groups_get_not_init_monitors ($group, $agent_filter, $module_filter, $strict_user, $groups_and_tags, $realtime);
break;
case AGENT_MODULE_STATUS_NORMAL_ALERT:
case AGENT_MODULE_STATUS_NORMAL:
$normal = (int) groups_get_normal_monitors ($group, $agent_filter, $module_filter, $strict_user, $groups_and_tags, $realtime);
break;
}
}
$total = $critical + $warning + $unknown + $not_init + $normal;
}
if (!is_array($agent_status)) {
switch ($agent_status) {
@ -1722,22 +1758,22 @@ function groups_get_monitors_counter ($group, $agent_filter = array(), $module_f
switch ($status) {
case AGENT_MODULE_STATUS_CRITICAL_ALERT:
case AGENT_MODULE_STATUS_CRITICAL_BAD:
$status_columns_array = 'ta.critical_count';
$status_columns_array[] = 'ta.critical_count';
break;
case AGENT_MODULE_STATUS_WARNING_ALERT:
case AGENT_MODULE_STATUS_WARNING:
$status_columns_array = 'ta.warning_count';
$status_columns_array[] = 'ta.warning_count';
break;
case AGENT_MODULE_STATUS_UNKNOWN:
$status_columns_array = 'ta.unknown_count';
$status_columns_array[] = 'ta.unknown_count';
break;
case AGENT_MODULE_STATUS_NO_DATA:
case AGENT_MODULE_STATUS_NOT_INIT:
$status_columns_array = 'ta.notinit_count';
$status_columns_array[] = 'ta.notinit_count';
break;
case AGENT_MODULE_STATUS_NORMAL_ALERT:
case AGENT_MODULE_STATUS_NORMAL:
$status_columns_array = 'ta.normal_count';
$status_columns_array[] = 'ta.normal_count';
break;
default:
// The type doesn't exist

View File

@ -1327,6 +1327,7 @@ function tags_get_agents_counter ($id_tag, $groups_and_tags = array(), $agent_fi
$module_name_filter = "";
$module_status_filter = "";
$module_status_array = array();
if (!empty($module_filter)) {
// IMPORTANT: The module filters will force the realtime search
$realtime = true;
@ -1343,48 +1344,47 @@ function tags_get_agents_counter ($id_tag, $groups_and_tags = array(), $agent_fi
else
$module_status = array($module_status);
$status_array = "";
foreach ($module_status as $status) {
switch ($status) {
case AGENT_MODULE_STATUS_ALL:
$status_array[] = AGENT_MODULE_STATUS_CRITICAL_ALERT;
$status_array[] = AGENT_MODULE_STATUS_CRITICAL_BAD;
$status_array[] = AGENT_MODULE_STATUS_WARNING_ALERT;
$status_array[] = AGENT_MODULE_STATUS_WARNING;
$status_array[] = AGENT_MODULE_STATUS_UNKNOWN;
$status_array[] = AGENT_MODULE_STATUS_NO_DATA;
$status_array[] = AGENT_MODULE_STATUS_NOT_INIT;
$status_array[] = AGENT_MODULE_STATUS_NORMAL_ALERT;
$status_array[] = AGENT_MODULE_STATUS_NORMAL;
$module_status_array[] = AGENT_MODULE_STATUS_CRITICAL_ALERT;
$module_status_array[] = AGENT_MODULE_STATUS_CRITICAL_BAD;
$module_status_array[] = AGENT_MODULE_STATUS_WARNING_ALERT;
$module_status_array[] = AGENT_MODULE_STATUS_WARNING;
$module_status_array[] = AGENT_MODULE_STATUS_UNKNOWN;
$module_status_array[] = AGENT_MODULE_STATUS_NO_DATA;
$module_status_array[] = AGENT_MODULE_STATUS_NOT_INIT;
$module_status_array[] = AGENT_MODULE_STATUS_NORMAL_ALERT;
$module_status_array[] = AGENT_MODULE_STATUS_NORMAL;
break;
case AGENT_MODULE_STATUS_CRITICAL_ALERT:
case AGENT_MODULE_STATUS_CRITICAL_BAD:
$status_array[] = AGENT_MODULE_STATUS_CRITICAL_ALERT;
$status_array[] = AGENT_MODULE_STATUS_CRITICAL_BAD;
$module_status_array[] = AGENT_MODULE_STATUS_CRITICAL_ALERT;
$module_status_array[] = AGENT_MODULE_STATUS_CRITICAL_BAD;
break;
case AGENT_MODULE_STATUS_WARNING_ALERT:
case AGENT_MODULE_STATUS_WARNING:
$status_array[] = AGENT_MODULE_STATUS_WARNING_ALERT;
$status_array[] = AGENT_MODULE_STATUS_WARNING;
$module_status_array[] = AGENT_MODULE_STATUS_WARNING_ALERT;
$module_status_array[] = AGENT_MODULE_STATUS_WARNING;
break;
case AGENT_MODULE_STATUS_UNKNOWN:
$status_array[] = AGENT_MODULE_STATUS_UNKNOWN;
$module_status_array[] = AGENT_MODULE_STATUS_UNKNOWN;
break;
case AGENT_MODULE_STATUS_NO_DATA:
case AGENT_MODULE_STATUS_NOT_INIT:
$status_array[] = AGENT_MODULE_STATUS_NO_DATA;
$status_array[] = AGENT_MODULE_STATUS_NOT_INIT;
$module_status_array[] = AGENT_MODULE_STATUS_NO_DATA;
$module_status_array[] = AGENT_MODULE_STATUS_NOT_INIT;
break;
case AGENT_MODULE_STATUS_NORMAL_ALERT:
case AGENT_MODULE_STATUS_NORMAL:
$status_array[] = AGENT_MODULE_STATUS_NORMAL_ALERT;
$status_array[] = AGENT_MODULE_STATUS_NORMAL;
$module_status_array[] = AGENT_MODULE_STATUS_NORMAL_ALERT;
$module_status_array[] = AGENT_MODULE_STATUS_NORMAL;
break;
}
}
if (!empty($status_array)) {
$status_array = array_unique($status_array);
$status_str = implode(",", $status_array);
if (!empty($module_status_array)) {
$module_status_array = array_unique($module_status_array);
$status_str = implode(",", $module_status_array);
$module_status_filter = "INNER JOIN tagente_estado AS tae
ON tam.id_agente_modulo = tae.id_agente_modulo
@ -1418,12 +1418,50 @@ function tags_get_agents_counter ($id_tag, $groups_and_tags = array(), $agent_fi
foreach ($agents as $agent) {
$agent_filter["id"] = $agent["id"];
$total = (int) tags_get_total_monitors ($id_tag, $groups_and_tags, $agent_filter, $module_filter);
$critical = (int) tags_get_critical_monitors ($id_tag, $groups_and_tags, $agent_filter, $module_filter);
$warning = (int) tags_get_warning_monitors ($id_tag, $groups_and_tags, $agent_filter, $module_filter);
$unknown = (int) tags_get_unknown_monitors ($id_tag, $groups_and_tags, $agent_filter, $module_filter);
$not_init = (int) tags_get_not_init_monitors ($id_tag, $groups_and_tags, $agent_filter, $module_filter);
$normal = (int) tags_get_normal_monitors ($id_tag, $groups_and_tags, $agent_filter, $module_filter);
$total = 0;
$critical = 0;
$warning = 0;
$unknown = 0;
$not_init = 0;
$normal = 0;
// Without module filter
if (empty($module_status_array)) {
$total = (int) tags_get_total_monitors ($id_tag, $groups_and_tags, $agent_filter, $module_filter);
$critical = (int) tags_get_critical_monitors ($id_tag, $groups_and_tags, $agent_filter, $module_filter);
$warning = (int) tags_get_warning_monitors ($id_tag, $groups_and_tags, $agent_filter, $module_filter);
$unknown = (int) tags_get_unknown_monitors ($id_tag, $groups_and_tags, $agent_filter, $module_filter);
$not_init = (int) tags_get_not_init_monitors ($id_tag, $groups_and_tags, $agent_filter, $module_filter);
$normal = (int) tags_get_normal_monitors ($id_tag, $groups_and_tags, $agent_filter, $module_filter);
}
// With module filter
else {
foreach ($module_status_array as $status) {
switch ($status) {
case AGENT_MODULE_STATUS_CRITICAL_ALERT:
case AGENT_MODULE_STATUS_CRITICAL_BAD:
$critical = (int) tags_get_critical_monitors ($id_tag, $groups_and_tags, $agent_filter, $module_filter);
break;
case AGENT_MODULE_STATUS_WARNING_ALERT:
case AGENT_MODULE_STATUS_WARNING:
$warning = (int) tags_get_warning_monitors ($id_tag, $groups_and_tags, $agent_filter, $module_filter);
break;
case AGENT_MODULE_STATUS_UNKNOWN:
$unknown = (int) tags_get_unknown_monitors ($id_tag, $groups_and_tags, $agent_filter, $module_filter);
break;
case AGENT_MODULE_STATUS_NO_DATA:
case AGENT_MODULE_STATUS_NOT_INIT:
$not_init = (int) tags_get_not_init_monitors ($id_tag, $groups_and_tags, $agent_filter, $module_filter);
break;
case AGENT_MODULE_STATUS_NORMAL_ALERT:
case AGENT_MODULE_STATUS_NORMAL:
$normal = (int) tags_get_normal_monitors ($id_tag, $groups_and_tags, $agent_filter, $module_filter);
break;
}
}
$total = $critical + $warning + $unknown + $not_init + $normal;
}
if (!is_array($agent_status)) {
switch ($agent_status) {