Merge branch 'ent-2153-vistas-en-las-que-no-se-ha-tenido-en-cuenta-los-grupos-secundarios-2' into 'develop'

Ent 2153 vistas en las que no se ha tenido en cuenta los grupos secundarios 2

See merge request artica/pandorafms!1750
This commit is contained in:
vgilc 2018-09-12 10:21:09 +02:00
commit 1bdfaed293
8 changed files with 367 additions and 314 deletions

View File

@ -155,23 +155,23 @@ class Tree {
return array(
'warning' => array(
'header' => "0 AS x_critical, SUM(total) AS x_warning, 0 AS x_normal, 0 AS x_unknown, 0 AS x_not_init, 0 AS x_alerts, 0 AS x_total, g",
'condition' => "AND ta.warning_count > 0 AND ta.critical_count = 0"
'condition' => "AND " . agents_get_status_clause(AGENT_STATUS_WARNING, $this->filter['show_not_init_agents'])
),
'critical' => array(
'header' => "SUM(total) AS x_critical, 0 AS x_warning, 0 AS x_normal, 0 AS x_unknown, 0 AS x_not_init, 0 AS x_alerts, 0 AS x_total, g",
'condition' => "AND ta.critical_count > 0"
'condition' => "AND " . agents_get_status_clause(AGENT_STATUS_CRITICAL, $this->filter['show_not_init_agents'])
),
'normal' => array(
'header' => "0 AS x_critical, 0 AS x_warning, SUM(total) AS x_normal, 0 AS x_unknown, 0 AS x_not_init, 0 AS x_alerts, 0 AS x_total, g",
'condition' => "AND ta.critical_count = 0 AND ta.warning_count = 0 AND ta.unknown_count = 0 AND ta.normal_count > 0"
'condition' => "AND " . agents_get_status_clause(AGENT_STATUS_NORMAL, $this->filter['show_not_init_agents'])
),
'unknown' => array(
'header' => "0 AS x_critical, 0 AS x_warning, 0 AS x_normal, SUM(total) AS x_unknown, 0 AS x_not_init, 0 AS x_alerts, 0 AS x_total, g",
'condition' => "AND ta.critical_count = 0 AND ta.warning_count = 0 AND ta.unknown_count > 0"
'condition' => "AND " . agents_get_status_clause(AGENT_STATUS_UNKNOWN, $this->filter['show_not_init_agents'])
),
'not_init' => array(
'header' => "0 AS x_critical, 0 AS x_warning, 0 AS x_normal, 0 AS x_unknown, SUM(total) AS x_not_init, 0 AS x_alerts, 0 AS x_total, g",
'condition' => $this->filter['show_not_init_agents'] ? "AND ta.total_count = ta.notinit_count" : " AND 1=0"
'condition' => "AND " . agents_get_status_clause(AGENT_STATUS_NOT_INIT, $this->filter['show_not_init_agents'])
),
'alerts' => array(
'header' => "0 AS x_critical, 0 AS x_warning, 0 AS x_normal, 0 AS x_unknown, 0 AS x_not_init, SUM(total) AS x_alerts, 0 AS x_total, g",
@ -179,7 +179,7 @@ class Tree {
),
'total' => array(
'header' => "0 AS x_critical, 0 AS x_warning, 0 AS x_normal, 0 AS x_unknown, 0 AS x_not_init, 0 AS x_alerts, SUM(total) AS x_total, g",
'condition' => $this->filter['show_not_init_agents'] ? "" : "AND ta.total_count <> ta.notinit_count"
'condition' => "AND " . agents_get_status_clause(AGENT_STATUS_ALL, $this->filter['show_not_init_agents'])
)
);
}
@ -232,43 +232,9 @@ class Tree {
? $state
: $this->filter['statusModule'];
$filter = array();
switch ($selected_status) {
case AGENT_MODULE_STATUS_CRITICAL_ALERT:
case AGENT_MODULE_STATUS_CRITICAL_BAD:
$filter[] = "(
tae.estado = ".AGENT_MODULE_STATUS_CRITICAL_ALERT."
OR tae.estado = ".AGENT_MODULE_STATUS_CRITICAL_BAD."
)";
break;
case AGENT_MODULE_STATUS_WARNING_ALERT:
case AGENT_MODULE_STATUS_WARNING:
$filter[] = "(
tae.estado = ".AGENT_MODULE_STATUS_WARNING_ALERT."
OR tae.estado = ".AGENT_MODULE_STATUS_WARNING."
)";
break;
case AGENT_MODULE_STATUS_UNKNOWN:
$filter[] = "tae.estado = ".AGENT_MODULE_STATUS_UNKNOWN." ";
break;
case AGENT_MODULE_STATUS_NO_DATA:
case AGENT_MODULE_STATUS_NOT_INIT:
$filter[] = "(
tae.estado = ".AGENT_MODULE_STATUS_NO_DATA."
OR tae.estado = ".AGENT_MODULE_STATUS_NOT_INIT."
)";
break;
case AGENT_MODULE_STATUS_NORMAL_ALERT:
case AGENT_MODULE_STATUS_NORMAL:
$filter[] = "(
tae.estado = ".AGENT_MODULE_STATUS_NORMAL_ALERT."
OR tae.estado = ".AGENT_MODULE_STATUS_NORMAL."
)";
break;
default:
$filter[] = "1=1";
break;
}
$filter = array(
modules_get_state_condition($selected_status)
);
if (!$this->filter['show_not_init_modules'] && $state === false) {
if (!empty($filter))
$filter[] = "(

View File

@ -966,12 +966,12 @@ function agents_get_group_agents (
$filter['order'] = 'alias';
if (is_metaconsole()) {
$table_name = 'tmetaconsole_agent LEFT JOIN tmetaconsole_agent_secondary_group ON ta.id_agente = tasg.id_agent';
$table_name = 'tmetaconsole_agent ta LEFT JOIN tmetaconsole_agent_secondary_group tasg ON ta.id_agente = tasg.id_agent';
$fields = array(
'id_tagente AS id_agente',
'ta.id_tagente AS id_agente',
'alias',
'id_tmetaconsole_setup AS id_server'
'ta.id_tmetaconsole_setup AS id_server'
);
}
else {
@ -2742,4 +2742,33 @@ function agents_check_access_agent ($id_agent, $access = "AR") {
// Return null otherwise
return null;
}
function agents_get_status_clause($state, $show_not_init = true) {
switch ($state) {
case AGENT_STATUS_CRITICAL:
return "(ta.critical_count > 0)";
case AGENT_STATUS_WARNING:
return "(ta.warning_count > 0 AND ta.critical_count = 0)";
case AGENT_STATUS_UNKNOWN:
return "(
ta.critical_count = 0 AND ta.warning_count = 0 AND ta.unknown_count > 0
)";
case AGENT_STATUS_NOT_INIT:
return $show_not_init
? "(ta.total_count = ta.notinit_count)"
: "1=0";
case AGENT_STATUS_NORMAL:
return "(
ta.critical_count = 0 AND ta.warning_count = 0
AND ta.unknown_count = 0 AND ta.normal_count > 0
)";
case AGENT_STATUS_ALL:
default:
return $show_not_init
? "1=1"
: "(ta.total_count <> ta.notinit_count)";
}
// If the state is not an expected state, return no condition
return "1=1";
}
?>

View File

@ -50,7 +50,10 @@ function alerts_get_alerts($id_group = 0, $free_search = "", $status = "all", $s
$id_groups = array_keys($groups);
$group_query = " AND t3.id_grupo IN (" . implode(',', $id_groups) . ") ";
$group_query = " AND (
t3.id_grupo IN (" . implode(',', $id_groups) . ")
OR tasg.id_group IN (" . implode(',', $id_groups) . ")
)";
}
else {
$group_query = "";
@ -1792,9 +1795,12 @@ function get_group_alerts($id_group, $filter = '', $options = false,
FROM tagente_modulo
WHERE delete_pending = 0
AND id_agente IN (SELECT id_agente
FROM tagente
FROM tagente ta
LEFT JOIN tagent_secondary_group tasg
ON ta.id_agente = tasg.id_agent
WHERE
id_grupo IN (' . implode(',', $id_group) . '))';
id_grupo IN (' . implode(',', $id_group) . ')
OR id_group IN (' . implode(',', $id_group) . '))';
}
}
@ -1861,6 +1867,8 @@ function get_group_alerts($id_group, $filter = '', $options = false,
ON talert_template_modules.id_agent_module = t2.id_agente_modulo
INNER JOIN tagente t3
ON t2.id_agente = t3.id_agente
LEFT JOIN tagent_secondary_group tasg
ON tasg.id_agent = t2.id_agente
INNER JOIN talert_templates t4
ON talert_template_modules.id_alert_template = t4.id
WHERE id_agent_module in (%s) %s %s %s",

View File

@ -1956,85 +1956,159 @@ function groups_get_not_init_monitors ($group, $agent_filter = array(), $module_
}
// Get alerts defined for a given group, except disabled
function groups_monitor_alerts ($group_array, $strict_user = false, $id_group_strict = false) {
// If there are not groups to query, we jump to nextone
if (empty ($group_array)) {
return 0;
}
else if (!is_array ($group_array)) {
$group_array = array($group_array);
}
$group_clause = implode (",", $group_array);
$group_clause = "(" . $group_clause . ")";
if ($strict_user) {
$sql = "SELECT COUNT(talert_template_modules.id)
FROM talert_template_modules, tagente_modulo, tagente_estado, tagente
WHERE tagente.id_grupo = $id_group_strict AND tagente_modulo.id_agente = tagente.id_agente
AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
AND tagente_modulo.disabled = 0 AND tagente.disabled = 0
AND talert_template_modules.disabled = 0
AND talert_template_modules.id_agent_module = tagente_modulo.id_agente_modulo";
$count = db_get_sql ($sql);
return $count;
} else {
//TODO REVIEW ORACLE AND POSTGRES
return db_get_sql ("SELECT COUNT(talert_template_modules.id)
FROM talert_template_modules, tagente_modulo, tagente_estado, tagente
WHERE tagente.id_grupo IN $group_clause AND tagente_modulo.id_agente = tagente.id_agente
AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
AND tagente_modulo.disabled = 0 AND tagente.disabled = 0
AND talert_template_modules.disabled = 0
AND talert_template_modules.id_agent_module = tagente_modulo.id_agente_modulo");
}
function groups_monitor_alerts ($group_array) {
$total = groups_monitor_alerts_total_counters($group_array);
return $total['total'];
}
// Get alert configured currently FIRED, except disabled
function groups_monitor_fired_alerts ($group_array) {
$total = groups_monitor_alerts_total_counters($group_array);
return $total['fired'];
}
function groups_monitor_fired_alerts ($group_array, $strict_user = false, $id_group_strict = false) {
function groups_monitor_alerts_total_counters ($group_array) {
// If there are not groups to query, we jump to nextone
$default_total = array('total' => 0, 'fired' => 0);
if (empty ($group_array)) {
return 0;
return $default_total;
}
else if (!is_array ($group_array)) {
$group_array = array($group_array);
}
$group_clause = implode (",", $group_array);
$group_clause = "(" . $group_clause . ")";
if ($strict_user) {
$sql = "SELECT COUNT(talert_template_modules.id)
FROM talert_template_modules, tagente_modulo, tagente_estado, tagente
WHERE tagente.id_grupo = $id_group_strict AND tagente_modulo.id_agente = tagente.id_agente
AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
AND tagente_modulo.disabled = 0 AND tagente.disabled = 0
AND talert_template_modules.disabled = 0
AND talert_template_modules.id_agent_module = tagente_modulo.id_agente_modulo
AND times_fired > 0 ";
$count = db_get_sql ($sql);
return $count;
} else {
//TODO REVIEW ORACLE AND POSTGRES
return db_get_sql ("SELECT COUNT(talert_template_modules.id)
FROM talert_template_modules, tagente_modulo, tagente_estado, tagente
WHERE tagente.id_grupo IN $group_clause AND tagente_modulo.id_agente = tagente.id_agente
AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
AND tagente_modulo.disabled = 0 AND tagente.disabled = 0
AND talert_template_modules.disabled = 0
AND talert_template_modules.id_agent_module = tagente_modulo.id_agente_modulo
AND times_fired > 0");
$group_clause = implode (",", $group_array);
$group_clause = "(tasg.id_group IN ($group_clause) OR ta.id_grupo IN ($group_clause))";
$alerts = db_get_row_sql ("SELECT
COUNT(tatm.id) AS total,
SUM(IF(tatm.times_fired > 0, 1, 0)) AS fired
FROM talert_template_modules tatm
INNER JOIN tagente_modulo tam
ON tatm.id_agent_module = tam.id_agente_modulo
INNER JOIN tagente ta
ON ta.id_agente = tam.id_agente
WHERE ta.id_agente IN (
SELECT ta.id_agente
FROM tagente ta
LEFT JOIN tagent_secondary_group tasg
ON ta.id_agente = tasg.id_agent
WHERE ta.disabled = 0
AND $group_clause
) AND tam.disabled = 0"
);
return ($alerts === false) ? $default_total : $alerts;
}
function groups_monitor_total_counters ($group_array, $search_in_testado = false) {
$default_total = array(
'ok' => 0, 'critical' => 0, 'warning' => 0,
'unknown' => 0, 'not_init' => 0, 'total' => 0
);
if (empty ($group_array)) {
return $default_total;
}
else if (!is_array ($group_array)) {
$group_array = array($group_array);
}
$group_clause = implode (",", $group_array);
$group_clause = "(tasg.id_group IN ($group_clause) OR ta.id_grupo IN ($group_clause))";
if ($search_in_testado) {
$condition_critical = modules_get_state_condition(AGENT_MODULE_STATUS_CRITICAL_ALERT);
$condition_warning = modules_get_state_condition(AGENT_MODULE_STATUS_WARNING_ALERT);
$condition_unknown = modules_get_state_condition(AGENT_MODULE_STATUS_UNKNOWN);
$condition_not_init = modules_get_state_condition(AGENT_MODULE_STATUS_NO_DATA);
$condition_normal = modules_get_state_condition(AGENT_MODULE_STATUS_NORMAL);
$sql =
"SELECT SUM(IF($condition_normal, 1, 0)) AS ok,
SUM(IF($condition_critical, 1, 0)) AS critical,
SUM(IF($condition_warning, 1, 0)) AS warning,
SUM(IF($condition_unknown, 1, 0)) AS unknown,
SUM(IF($condition_not_init, 1, 0)) AS not_init,
COUNT(tam.id_agente_modulo) AS total
FROM tagente ta
INNER JOIN tagente_modulo tam
ON ta.id_agente = tam.id_agente
INNER JOIN tagente_estado tae
ON tam.id_agente_modulo = tae.id_agente_modulo
WHERE ta.disabled = 0 AND tam.disabled = 0
AND ta.id_agente IN (
SELECT ta.id_agente FROM tagente ta
LEFT JOIN tagent_secondary_group tasg
ON ta.id_agente = tasg.id_agent
WHERE ta.disabled = 0
AND $group_clause
GROUP BY ta.id_agente
)
";
} else {
$sql =
"SELECT SUM(ta.normal_count) AS ok,
SUM(ta.critical_count) AS critical,
SUM(ta.warning_count) AS warning,
SUM(ta.unknown_count) AS unknown,
SUM(ta.notinit_count) AS not_init,
SUM(ta.total_count) AS total
FROM tagente ta
WHERE ta.disabled = 0
AND ta.id_agente IN (
SELECT ta.id_agente FROM tagente ta
LEFT JOIN tagent_secondary_group tasg
ON ta.id_agente = tasg.id_agent
WHERE ta.disabled = 0
AND $group_clause
GROUP BY ta.id_agente
)
";
}
$monitors = db_get_row_sql($sql);
return ($monitors === false) ? $default_total : $monitors;
}
function groups_agents_total_counters ($group_array) {
$default_total = array(
'ok' => 0, 'critical' => 0, 'warning' => 0,
'unknown' => 0, 'not_init' => 0, 'total' => 0
);
if (empty ($group_array)) {
return $default_total;
}
else if (!is_array ($group_array)) {
$group_array = array($group_array);
}
$group_clause = implode (",", $group_array);
$group_clause = "(tasg.id_group IN ($group_clause) OR ta.id_grupo IN ($group_clause))";
$condition_critical = agents_get_status_clause(AGENT_STATUS_CRITICAL);
$condition_warning = agents_get_status_clause(AGENT_STATUS_WARNING);
$condition_unknown = agents_get_status_clause(AGENT_STATUS_UNKNOWN);
$condition_not_init = agents_get_status_clause(AGENT_STATUS_NOT_INIT);
$condition_normal = agents_get_status_clause(AGENT_STATUS_NORMAL);
$sql =
"SELECT SUM(IF($condition_normal, 1, 0)) AS ok,
SUM(IF($condition_critical, 1, 0)) AS critical,
SUM(IF($condition_warning, 1, 0)) AS warning,
SUM(IF($condition_unknown, 1, 0)) AS unknown,
SUM(IF($condition_not_init, 1, 0)) AS not_init,
COUNT(ta.id_agente) AS total
FROM tagente ta
WHERE ta.disabled = 0
AND ta.id_agente IN (
SELECT ta.id_agente FROM tagente ta
LEFT JOIN tagent_secondary_group tasg
ON ta.id_agente = tasg.id_agent
WHERE ta.disabled = 0
AND $group_clause
GROUP BY ta.id_agente
)
";
$agents = db_get_row_sql($sql);
return ($agents === false) ? $default_total : $agents;
}
/**
@ -2771,7 +2845,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
$list[$i]['_monitors_warning_'] = (int) groups_get_warning_monitors ($id, $agent_filter, $module_filter, $user_strict, $acltags, $config["realtimestats"]);
$list[$i]['_monitors_unknown_'] = (int) groups_get_unknown_monitors ($id, $agent_filter, $module_filter, $user_strict, $acltags, $config["realtimestats"]);
$list[$i]['_monitors_not_init_'] = (int) groups_get_not_init_monitors ($id, $agent_filter, $module_filter, $user_strict, $acltags, $config["realtimestats"]);
$list[$i]['_monitors_alerts_fired_'] = groups_monitor_fired_alerts ($id, $user_strict, $id);
$list[$i]['_monitors_alerts_fired_'] = groups_monitor_fired_alerts ($id);
$list[$i]['_total_agents_'] = (int) groups_get_total_agents ($id, $agent_filter, $module_filter, $user_strict, $acltags, $config["realtimestats"]);
$list[$i]['_agents_unknown_'] = (int) groups_get_unknown_agents ($id, $agent_filter, $module_filter, $user_strict, $acltags, $config["realtimestats"]);
$list[$i]['_agents_not_init_'] = (int) groups_get_not_init_agents ($id, $agent_filter, $module_filter, $user_strict, $acltags, $config["realtimestats"]);
@ -2780,7 +2854,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
$list[$i]['_agents_ok_'] = (int) groups_get_normal_agents ($id, $agent_filter, $module_filter, $user_strict, $acltags, $config["realtimestats"]);
$list[$i]['_agents_warning_'] = (int) groups_get_warning_agents ($id, $agent_filter, $module_filter, $user_strict, $acltags, $config["realtimestats"]);
$list[$i]['_agents_critical_'] = (int) groups_get_critical_agents ($id, $agent_filter, $module_filter, $user_strict, $acltags, $config["realtimestats"]);
$list[$i]['_monitors_alerts_'] = groups_monitor_alerts ($id, $user_strict, $id);
$list[$i]['_monitors_alerts_'] = groups_monitor_alerts ($id);
// TODO
//~ $list[$i]["_total_checks_"]

View File

@ -2775,4 +2775,37 @@ function modules_get_counter_by_states($state) {
// to not show any data
return false;
}
?>
function modules_get_state_condition($state) {
switch ($state) {
case AGENT_MODULE_STATUS_CRITICAL_ALERT:
case AGENT_MODULE_STATUS_CRITICAL_BAD:
return "(
tae.estado = ".AGENT_MODULE_STATUS_CRITICAL_ALERT."
OR tae.estado = ".AGENT_MODULE_STATUS_CRITICAL_BAD."
)";
case AGENT_MODULE_STATUS_WARNING_ALERT:
case AGENT_MODULE_STATUS_WARNING:
return "(
tae.estado = ".AGENT_MODULE_STATUS_WARNING_ALERT."
OR tae.estado = ".AGENT_MODULE_STATUS_WARNING."
)";
case AGENT_MODULE_STATUS_UNKNOWN:
return "tae.estado = ".AGENT_MODULE_STATUS_UNKNOWN." ";
case AGENT_MODULE_STATUS_NO_DATA:
case AGENT_MODULE_STATUS_NOT_INIT:
return "(
tae.estado = ".AGENT_MODULE_STATUS_NO_DATA."
OR tae.estado = ".AGENT_MODULE_STATUS_NOT_INIT."
)";
case AGENT_MODULE_STATUS_NORMAL_ALERT:
case AGENT_MODULE_STATUS_NORMAL:
return "(
tae.estado = ".AGENT_MODULE_STATUS_NORMAL_ALERT."
OR tae.estado = ".AGENT_MODULE_STATUS_NORMAL."
)";
}
// If the state is not an expected state, return no condition
return "1=1";
}
?>

View File

@ -6998,54 +6998,41 @@ function reporting_get_group_stats ($id_group = 0, $access = 'AR') {
continue;
}
}
if (!empty($group_array)) {
$monitors_info = groups_monitor_total_counters($group_array, true);
// Get monitor NOT INIT, except disabled AND async modules
$data["monitor_not_init"] += (int) groups_get_not_init_monitors ($group_array, array(), array(), false, false, true);
// Get monitor OK, except disabled and non-init
$data["monitor_ok"] += (int) groups_get_normal_monitors ($group_array, array(), array(), false, false, true);
// Get monitor CRITICAL, except disabled and non-init
$data["monitor_critical"] += (int) groups_get_critical_monitors ($group_array, array(), array(), false, false, true);
// Get monitor WARNING, except disabled and non-init
$data["monitor_warning"] += (int) groups_get_warning_monitors ($group_array, array(), array(), false, false, true);
// Get monitor UNKNOWN, except disabled and non-init
$data["monitor_unknown"] += (int) groups_get_unknown_monitors ($group_array, array(), array(), false, false, true);
// Get alerts configured, except disabled
$data["monitor_alerts"] += groups_monitor_alerts ($group_array) ;
// Get alert configured currently FIRED, except disabled
$data["monitor_alerts_fired"] += groups_monitor_fired_alerts ($group_array);
// Calculate totals using partial counts from above
// Get TOTAL non-init modules, except disabled ones and async modules
$data["monitor_not_init"] += $monitors_info['not_init'];
$data["total_not_init"] += $data["monitor_not_init"];
// Get monitor OK, except disabled and non-init
$data["monitor_ok"] += $monitors_info['ok'];
// Get monitor CRITICAL, except disabled and non-init
$data["monitor_critical"] += $monitors_info['critical'];
// Get monitor WARNING, except disabled and non-init
$data["monitor_warning"] += $monitors_info['warning'];
// Get monitor UNKNOWN, except disabled and non-init
$data["monitor_unknown"] += $monitors_info['unknown'];
$data["monitor_checks"] += $monitors_info['total'];
// Get alerts configured, except disabled
$alerts_info = groups_monitor_alerts_total_counters ($group_array);
$data["monitor_alerts"] += $alerts_info['total'];
// Get alert configured currently FIRED, except disabled
$data["monitor_alerts_fired"] += $alerts_info['fired'];
$agents_info = groups_agents_total_counters($group_array);
// Get TOTAL agents in a group
$data["total_agents"] += (int) groups_get_total_agents ($group_array, array(), array(), false, false, true);
$data["total_agents"] += $agents_info['total'];
// Get Agents OK
$data["agent_ok"] += (int) groups_get_normal_agents ($group_array, array(), array(), false, false, true);
// Get Agents Warning
$data["agent_warning"] += (int) groups_get_warning_agents ($group_array, array(), array(), false, false, true);
$data["agent_ok"] += $agents_info['ok'];
// Get Agents Warning
$data["agent_warning"] += $agents_info['warning'];
// Get Agents Critical
$data["agent_critical"] += (int) groups_get_critical_agents ($group_array, array(), array(), false, false, true);
$data["agent_critical"] += $agents_info['critical'];
// Get Agents Unknown
$data["agent_unknown"] += (int) groups_get_unknown_agents ($group_array, array(), array(), false, false, true);
$data["agent_unknown"] += $agents_info['unknown'];
// Get Agents Not init
$data["agent_not_init"] += (int) groups_get_not_init_agents ($group_array, array(), array(), false, false, true);
// Get total count of monitors for this group, except disabled.
$data["monitor_checks"] += $data["monitor_not_init"] + $data["monitor_unknown"] + $data["monitor_warning"] + $data["monitor_critical"] + $data["monitor_ok"];
$data["agent_not_init"] += $agents_info['not_init'];
}
}
// Calculate not_normal monitors

View File

@ -187,77 +187,37 @@ if ($alert_validate) {
enterprise_hook('open_meta_frame');
if ($free_search != '') {
switch ($config["dbtype"]) {
case "mysql":
$whereAlertSimple = 'AND (' .
'id_alert_template IN (
SELECT id
FROM talert_templates
WHERE name LIKE "%' . $free_search . '%") OR ' .
'id_alert_template IN (
SELECT id
FROM talert_templates
WHERE id_alert_action IN (
SELECT id
FROM talert_actions
WHERE name LIKE "%' . $free_search . '%")) OR ' .
'talert_template_modules.id IN (
SELECT id_alert_template_module
FROM talert_template_module_actions
WHERE id_alert_action IN (
SELECT id
FROM talert_actions
WHERE name LIKE "%' . $free_search . '%")) OR ' .
'id_agent_module IN (
SELECT id_agente_modulo
FROM tagente_modulo
WHERE nombre LIKE "%' . $free_search . '%") OR ' .
'id_agent_module IN (
SELECT id_agente_modulo
FROM tagente_modulo
WHERE id_agente IN (
SELECT id_agente
FROM tagente
WHERE nombre LIKE "%' . $free_search . '%") OR alias LIKE "%' . $free_search . '%")' .
')';
break;
case "postgresql":
case "oracle":
$whereAlertSimple = 'AND (' .
'id_alert_template IN (
SELECT id
FROM talert_templates
WHERE name LIKE \'%' . $free_search . '%\') OR ' .
'id_alert_template IN (
SELECT id
FROM talert_templates
WHERE id_alert_action IN (
SELECT id
FROM talert_actions
WHERE name LIKE \'%' . $free_search . '%\')) OR ' .
'talert_template_modules.id IN (
SELECT id_alert_template_module
FROM talert_template_module_actions
WHERE id_alert_action IN (
SELECT id
FROM talert_actions
WHERE name LIKE \'%' . $free_search . '%\')) OR ' .
'id_agent_module IN (
SELECT id_agente_modulo
FROM tagente_modulo
WHERE nombre LIKE \'%' . $free_search . '%\') OR ' .
'id_agent_module IN (
SELECT id_agente_modulo
FROM tagente_modulo
WHERE id_agente IN (
SELECT id_agente
FROM tagente
WHERE nombre LIKE \'%' . $free_search . '%\' OR alias LIKE \'%' . $free_search . '%\'))' .
')';
break;
}
$whereAlertSimple = 'AND (' .
'id_alert_template IN (
SELECT id
FROM talert_templates
WHERE name LIKE "%' . $free_search . '%") OR ' .
'id_alert_template IN (
SELECT id
FROM talert_templates
WHERE id_alert_action IN (
SELECT id
FROM talert_actions
WHERE name LIKE "%' . $free_search . '%")) OR ' .
'talert_template_modules.id IN (
SELECT id_alert_template_module
FROM talert_template_module_actions
WHERE id_alert_action IN (
SELECT id
FROM talert_actions
WHERE name LIKE "%' . $free_search . '%")) OR ' .
'id_agent_module IN (
SELECT id_agente_modulo
FROM tagente_modulo
WHERE nombre LIKE "%' . $free_search . '%") OR ' .
'id_agent_module IN (
SELECT id_agente_modulo
FROM tagente_modulo
WHERE id_agente IN (
SELECT id_agente
FROM tagente
WHERE nombre LIKE "%' . $free_search . '%") OR alias LIKE "%' . $free_search . '%")' .
')';
}
else {
$whereAlertSimple = '';

View File

@ -4635,97 +4635,93 @@ Process groups statistics for statistics table
##########################################################################
sub pandora_group_statistics ($$) {
my ($pa_config, $dbh) = @_;
# Variable init
my $modules = 0;
my $normal = 0;
my $critical = 0;
my $warning = 0;
my $unknown = 0;
my $non_init = 0;
my $alerts = 0;
my $alerts_fired = 0;
my $agents = 0;
my $agents_unknown = 0;
my $utimestamp = 0;
my $group = 0;
my $is_meta = is_metaconsole($pa_config);
# Get all groups
my @groups = get_db_rows ($dbh, 'SELECT id_grupo FROM tgrupo');
my $table = is_metaconsole($pa_config) ? 'tmetaconsole_agent' : 'tagente';
my $sec_table = is_metaconsole($pa_config)
? 'tmetaconsole_agent_secondary_group'
: 'tagent_secondary_group';
logger($pa_config, "Updating no realtime group stats.", 10);
# For each valid group get the stats: Simple uh?
foreach my $group_row (@groups) {
my $total_alerts_condition = $is_meta
? "0"
: "COUNT(tatm.id)";
my $joins_alerts = $is_meta
? ""
: "LEFT JOIN tagente_modulo tam
ON tam.id_agente = ta.id_agente
INNER JOIN talert_template_modules tatm
ON tatm.id_agent_module = tam.id_agente_modulo";
my $agent_table = $is_meta
? "tmetaconsole_agent"
: "tagente";
my $agent_seconsary_table = $is_meta
? "tmetaconsole_agent_secondary_group"
: "tagent_secondary_group";
$group = $group_row->{'id_grupo'};
# NOTICE - Calculations done here MUST BE the same than used in PHP code to have
# the same criteria. PLEASE, double check any changes here and in functions_groups.php
$agents_unknown = get_db_value ($dbh, "SELECT COUNT(DISTINCT(id_agente))
FROM $table LEFT JOIN $sec_table ON id_agente=id_agent
WHERE disabled=0 AND critical_count=0 AND warning_count=0 AND unknown_count>0 AND (id_grupo=? OR id_group=?)", $group, $group);
$agents_unknown = 0 unless defined ($agents_unknown);
$agents = get_db_value ($dbh, "SELECT COUNT(DISTINCT(id_agente))
FROM $table LEFT JOIN $sec_table ON id_agente=id_agent
WHERE(id_grupo=$group OR id_group=$group) AND disabled=0");
$agents = 0 unless defined ($agents);
$modules = get_db_value ($dbh, "SELECT SUM(total_count) FROM
# Update the record.
db_do ($dbh, "REPLACE INTO tgroup_stat(
`id_group`, `modules`, `normal`, `critical`, `warning`, `unknown`,
`non-init`, `alerts`, `alerts_fired`, `agents`,
`agents_unknown`, `utimestamp`
)
SELECT
tg.id_grupo AS id_group,
IF (SUM(modules_total) IS NULL,0,SUM(modules_total)) AS modules,
IF (SUM(modules_ok) IS NULL,0,SUM(modules_ok)) AS normal,
IF (SUM(modules_critical) IS NULL,0,SUM(modules_critical)) AS critical,
IF (SUM(modules_warning) IS NULL,0,SUM(modules_warning)) AS warning,
IF (SUM(modules_unknown) IS NULL,0,SUM(modules_unknown)) AS unknown,
IF (SUM(modules_not_init) IS NULL,0,SUM(modules_not_init)) AS `non-init`,
IF (SUM(alerts_total) IS NULL,0,SUM(alerts_total)) AS alerts,
IF (SUM(alerts_fired) IS NULL,0,SUM(alerts_fired)) AS alerts_fired,
IF (SUM(agents_total) IS NULL,0,SUM(agents_total)) AS agents,
IF (SUM(agents_unknown) IS NULL,0,SUM(agents_unknown)) AS agents_unknown,
UNIX_TIMESTAMP() AS utimestamp
FROM
(
SELECT DISTINCT(id_agente), total_count
FROM $table LEFT JOIN $sec_table ON id_agente=id_agent
WHERE disabled=0 AND (id_grupo=? OR id_group=?)
) AS t1", $group, $group);
$modules = 0 unless defined ($modules);
SELECT SUM(ta.normal_count) AS modules_ok,
SUM(ta.critical_count) AS modules_critical,
SUM(ta.warning_count) AS modules_warning,
SUM(ta.unknown_count) AS modules_unknown,
SUM(ta.notinit_count) AS modules_not_init,
SUM(ta.total_count) AS modules_total,
SUM(ta.fired_count) AS alerts_fired,
$total_alerts_condition AS alerts_total,
SUM(IF(ta.critical_count > 0, 1, 0)) AS agents_critical,
SUM(IF(ta.critical_count = 0 AND ta.warning_count = 0 AND ta.unknown_count > 0, 1, 0)) AS agents_unknown,
SUM(IF(ta.total_count = ta.notinit_count, 1, 0)) AS agents_not_init,
COUNT(ta.id_agente) AS agents_total,
ta.id_grupo AS g
FROM $agent_table ta
$joins_alerts
WHERE ta.disabled = 0
GROUP BY g
$normal = get_db_value ($dbh, "SELECT COUNT(DISTINCT(id_agente))
FROM $table LEFT JOIN $sec_table ON id_agente=id_agent
WHERE disabled=0 AND critical_count=0 AND warning_count=0 AND unknown_count=0 AND normal_count>0 AND (id_grupo=? OR id_group=?)", $group, $group);
$normal = 0 unless defined ($normal);
UNION ALL
$critical = get_db_value ($dbh, "SELECT COUNT(DISTINCT(id_agente))
FROM $table LEFT JOIN $sec_table ON id_agente=id_agent
WHERE disabled=0 AND critical_count>0 AND (id_grupo=? OR id_group=?)", $group, $group);
$critical = 0 unless defined ($critical);
$warning = get_db_value ($dbh, "SELECT COUNT(DISTINCT(id_agente))
FROM $table LEFT JOIN $sec_table ON id_agente=id_agent
WHERE disabled=0 AND critical_count=0 AND warning_count>0 AND (id_grupo=? OR id_group=?)", $group, $group);
$warning = 0 unless defined ($warning);
$unknown = get_db_value ($dbh, "SELECT COUNT(DISTINCT(id_agente))
FROM $table LEFT JOIN $sec_table ON id_agente=id_agent
WHERE disabled=0 AND critical_count=0 AND warning_count=0 AND unknown_count>0 AND (id_grupo=? OR id_group=?)", $group, $group);
$unknown = 0 unless defined ($unknown);
$non_init = get_db_value ($dbh, "SELECT COUNT(DISTINCT(id_agente))
FROM $table LEFT JOIN $sec_table ON id_agente=id_agent
WHERE disabled=0 AND total_count=notinit_count AND (id_grupo=? OR id_group=?)", $group, $group);
$non_init = 0 unless defined ($non_init);
# Total alert count not available on the meta console.
if ($table eq 'tagente') {
$alerts = get_db_value ($dbh, "SELECT COUNT(talert_template_modules.id)
FROM talert_template_modules, tagente_modulo, tagente
WHERE tagente.id_grupo = $group AND tagente_modulo.id_agente = tagente.id_agente
AND tagente_modulo.disabled = 0 AND tagente.disabled = 0
AND talert_template_modules.disabled = 0
AND talert_template_modules.id_agent_module = tagente_modulo.id_agente_modulo");
}
$alerts = 0 unless defined ($alerts);
$alerts_fired = get_db_value ($dbh, "SELECT SUM(fired_count) FROM $table WHERE disabled=0 AND id_grupo=?", $group);
$alerts_fired = 0 unless defined ($alerts_fired);
# Update the record.
db_do ($dbh, "REPLACE INTO tgroup_stat (id_group, modules, normal, critical, warning, unknown, " . $PandoraFMS::DB::RDBMS_QUOTE . 'non-init' . $PandoraFMS::DB::RDBMS_QUOTE . ", alerts, alerts_fired, agents, agents_unknown, utimestamp) VALUES ($group, $modules, $normal, $critical, $warning, $unknown, $non_init, $alerts, $alerts_fired, $agents, $agents_unknown, UNIX_TIMESTAMP())");
}
SELECT SUM(ta.normal_count) AS modules_ok,
SUM(ta.critical_count) AS modules_critical,
SUM(ta.warning_count) AS modules_warning,
SUM(ta.unknown_count) AS modules_unknown,
SUM(ta.notinit_count) AS modules_not_init,
SUM(ta.total_count) AS modules_total,
SUM(ta.fired_count) AS alerts_fired,
$total_alerts_condition AS alerts_total,
SUM(IF(ta.critical_count > 0, 1, 0)) AS agents_critical,
SUM(IF(ta.critical_count = 0 AND ta.warning_count = 0 AND ta.unknown_count > 0, 1, 0)) AS agents_unknown,
SUM(IF(ta.total_count = ta.notinit_count, 1, 0)) AS agents_not_init,
COUNT(ta.id_agente) AS agents_total,
tasg.id_group AS g
FROM $agent_table ta
LEFT JOIN $agent_seconsary_table tasg
ON ta.id_agente = tasg.id_agent
$joins_alerts
WHERE ta.disabled = 0
GROUP BY g
) counters
RIGHT JOIN tgrupo tg
ON counters.g = tg.id_grupo
GROUP BY tg.id_grupo"
);
logger($pa_config, "No realtime group stats updated.", 6);
}