[Secondary groups] Group report and adapted group_stat table to secondary groups

This commit is contained in:
fermin831 2018-08-21 13:34:52 +02:00
parent 399c9c2d58
commit 0a70284eaa
3 changed files with 98 additions and 127 deletions

View File

@ -1206,19 +1206,7 @@ function groups_get_agents_counter ($group, $agent_filter = array(), $module_fil
$groups_clause = "AND ta.id_grupo IN ($group_str)";
$tags_clause = "";
if ($strict_user && !empty($groups_and_tags)) {
foreach ($groups as $group_id) {
if (isset($groups_and_tags[$group_id]) && !empty($groups_and_tags[$group_id])) {
$tags_str = $groups_and_tags[$group_id];
$tags_clause .= " AND (ta.grupo <> $group_id
OR (ta.grupo = $group_id
AND tam.id_agente_modulo NOT IN (SELECT id_agente_modulo
FROM ttag_module
WHERE id_tag NOT IN ($tags_str) )))";
}
}
}
$agent_name_filter = "";
$agent_status = AGENT_STATUS_ALL;
if (!empty($agent_filter)) {
@ -1662,22 +1650,10 @@ function groups_get_monitors_counter ($group, $agent_filter = array(), $module_f
}
$group_str = implode (",", $groups);
$groups_clause = "AND ta.id_grupo IN ($group_str)";
$groups_clause = "AND (ta.id_grupo IN ($group_str) OR tasg.id_group IN ($group_str))";
$tags_clause = "";
if ($strict_user && !empty($groups_and_tags)) {
foreach ($groups as $group_id) {
if (isset($groups_and_tags[$group_id]) && !empty($groups_and_tags[$group_id])) {
$tags_str = $groups_and_tags[$group_id];
$tags_clause .= " AND (ta.grupo <> $group_id
OR (ta.grupo = $group_id
AND tam.id_agente_modulo NOT IN (SELECT id_agente_modulo
FROM ttag_module
WHERE id_tag NOT IN ($tags_str) )))";
}
}
}
$agent_name_filter = "";
$agents_clause = "";
if (!empty($agent_filter)) {
@ -1775,36 +1751,38 @@ function groups_get_monitors_counter ($group, $agent_filter = array(), $module_f
$modules_clause
INNER JOIN tagente ta
ON tam.id_agente = ta.id_agente
LEFT JOIN tagent_secondary_group tasg
ON ta.id_agente = tasg.id_agent
AND ta.disabled = 0
$agent_name_filter
$agents_clause
$groups_clause
WHERE tam.disabled = 0
$module_name_filter
$groups_clause
$tags_clause";
}
else {
$status_columns_array = array();
foreach ($module_status_array as $status) {
foreach ($status_array as $status) {
switch ($status) {
case AGENT_MODULE_STATUS_CRITICAL_ALERT:
case AGENT_MODULE_STATUS_CRITICAL_BAD:
$status_columns_array[] = 'ta.critical_count';
$status_columns_array['critical'] = 'critical_count';
break;
case AGENT_MODULE_STATUS_WARNING_ALERT:
case AGENT_MODULE_STATUS_WARNING:
$status_columns_array[] = 'ta.warning_count';
$status_columns_array['warn'] = 'warning_count';
break;
case AGENT_MODULE_STATUS_UNKNOWN:
$status_columns_array[] = 'ta.unknown_count';
$status_columns_array['unk'] = 'unknown_count';
break;
case AGENT_MODULE_STATUS_NO_DATA:
case AGENT_MODULE_STATUS_NOT_INIT:
$status_columns_array[] = 'ta.notinit_count';
$status_columns_array['notinit'] = 'notinit_count';
break;
case AGENT_MODULE_STATUS_NORMAL_ALERT:
case AGENT_MODULE_STATUS_NORMAL:
$status_columns_array[] = 'ta.normal_count';
$status_columns_array['normal'] = 'normal_count';
break;
default:
// The type doesn't exist
@ -1816,13 +1794,16 @@ function groups_get_monitors_counter ($group, $agent_filter = array(), $module_f
$status_columns_str = implode(",", $status_columns_array);
$sql = "SELECT SUM($status_columns_str)
FROM tagente ta
$sql = "SELECT SUM($status_columns_str) FROM
(SELECT DISTINCT(ta.id_agente), $status_columns_str
FROM tagente ta LEFT JOIN tagent_secondary_group tasg
ON ta.id_agente = tasg.id_agent
WHERE ta.disabled = 0
$agent_name_filter
$agents_clause
$groups_clause
$tags_clause";
$tags_clause
) AS t1";
}
$count = (int) db_get_sql ($sql);

View File

@ -6970,89 +6970,57 @@ function reporting_get_group_stats ($id_group = 0, $access = 'AR') {
}
if (!empty($group_array)) {
// FOR THE FUTURE: Split the groups into groups with tags restrictions and groups without it
// To calculate in the light way the non tag restricted and in the heavy way the others
/*
$group_restricted_data = tags_get_acl_tags($config['id_user'], $group_array, $access, 'data');
$tags_restricted_groups = array_keys($group_restricted_data);
// 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);
$no_tags_restricted_groups = $group_array;
foreach ($no_tags_restricted_groups as $k => $v) {
if (in_array($v, $tags_restricted_groups)) {
unset($no_tags_restricted_groups[$k]);
}
}
*/
// Get monitor OK, except disabled and non-init
$data["monitor_ok"] += (int) groups_get_normal_monitors ($group_array, array(), array(), false, false, true);
if (!empty($group_array)) {
// 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["total_not_init"] += $data["monitor_not_init"];
// Get monitor CRITICAL, except disabled and non-init
$data["monitor_critical"] += (int) groups_get_critical_monitors ($group_array, array(), array(), false, false, true);
// Get TOTAL agents in a group
$data["total_agents"] += (int) groups_get_total_agents ($group_array, array(), array(), false, false, true);
// 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);
// Get Agents Critical
$data["agent_critical"] += (int) groups_get_critical_agents ($group_array, array(), array(), false, false, true);
// Get Agents Unknown
$data["agent_unknown"] += (int) groups_get_unknown_agents ($group_array, array(), array(), false, false, true);
// Get Agents Not init
$data["agent_not_init"] += (int) groups_get_not_init_agents ($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["total_not_init"] += $data["monitor_not_init"];
// Get TOTAL agents in a group
$data["total_agents"] += (int) groups_get_total_agents ($group_array, array(), array(), false, false, true);
// 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);
// Get Agents Critical
$data["agent_critical"] += (int) groups_get_critical_agents ($group_array, array(), array(), false, false, true);
// Get Agents Unknown
$data["agent_unknown"] += (int) groups_get_unknown_agents ($group_array, array(), array(), false, false, true);
// 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"];
// Calculate not_normal monitors
$data["monitor_not_normal"] += $data["monitor_checks"] - $data["monitor_ok"];
$data["monitor_checks"] += $data["monitor_not_init"] + $data["monitor_unknown"] + $data["monitor_warning"] + $data["monitor_critical"] + $data["monitor_ok"];
}
// 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"];
/*
Monitor health (percentage)
Data health (percentage)
Global health (percentage)
Module sanity (percentage)
Alert level (percentage)
Server Sanity 0% Uninitialized modules
*/
}
// Calculate not_normal monitors
$data["monitor_not_normal"] += $data["monitor_checks"] - $data["monitor_ok"];
if ($data["monitor_unknown"] > 0 && $data["monitor_checks"] > 0) {
$data["monitor_health"] = format_numeric (100 - ($data["monitor_not_normal"] / ($data["monitor_checks"] / 100)), 1);
}

View File

@ -4650,6 +4650,9 @@ sub pandora_group_statistics ($$) {
# 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';
# For each valid group get the stats: Simple uh?
foreach my $group_row (@groups) {
@ -4658,30 +4661,49 @@ sub pandora_group_statistics ($$) {
# 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(*) FROM $table WHERE disabled=0 AND critical_count=0 AND warning_count=0 AND unknown_count>0 AND id_grupo=?", $group);
$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(*) FROM $table WHERE id_grupo = $group AND disabled=0");
$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 $table WHERE disabled=0 AND id_grupo=?", $group);
$modules = get_db_value ($dbh, "SELECT SUM(total_count) 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);
$normal = get_db_value ($dbh, "SELECT COUNT(*) FROM $table WHERE disabled=0 AND critical_count=0 AND warning_count=0 AND unknown_count=0 AND normal_count>0 AND id_grupo=?", $group);
$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);
$critical = get_db_value ($dbh, "SELECT COUNT(*) FROM $table WHERE disabled=0 AND critical_count>0 AND id_grupo=?", $group);
$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(*) FROM $table WHERE disabled=0 AND critical_count=0 AND warning_count>0 AND id_grupo=?", $group);
$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(*) FROM $table WHERE disabled=0 AND critical_count=0 AND warning_count=0 AND unknown_count>0 AND id_grupo=?", $group);
$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(*) FROM $table WHERE disabled=0 AND total_count=notinit_count AND id_grupo=?", $group);
$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)