removed unwanted code

This commit is contained in:
daniel 2018-08-24 12:55:09 +02:00
parent fbe4e15ca7
commit e6a42f45be

View File

@ -2352,70 +2352,42 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
if ($id_user == false) {
$id_user = $config['id_user'];
}
$user_groups = array();
$user_tags = array();
$groups_without_tags = array();
foreach ($acltags as $group => $tags) {
if ($user_strict) { //Remove groups with tags
if ($tags == '') {
$groups_without_tags[$group] = $group;
}
}
$user_groups[$group] = groups_get_name($group);
if ($tags != '') {
$tags_group = explode(',', $tags);
foreach ($tags_group as $tag) {
$user_tags[$tag] = tags_get_name($tag);
}
}
}
if ($user_strict) {
$user_groups_ids = implode(',', array_keys($groups_without_tags));
}
else {
$user_groups_ids = implode(',', array_keys($acltags));
}
$user_groups_ids = implode(',', array_keys($acltags));
if (!empty($user_groups_ids)) {
switch ($config["dbtype"]) {
case "mysql":
$list_groups = db_get_all_rows_sql("
SELECT *
FROM tgrupo
WHERE id_grupo IN (" . $user_groups_ids . ")
ORDER BY nombre COLLATE utf8_general_ci ASC");
break;
case "postgresql":
$list_groups = db_get_all_rows_sql("
SELECT *
FROM tgrupo
WHERE id_grupo IN (" . $user_groups_ids . ")
ORDER BY nombre ASC");
break;
case "oracle":
$list_groups = db_get_all_rows_sql("
SELECT *
FROM tgrupo
WHERE id_grupo IN (" . $user_groups_ids . ")
ORDER BY nombre ASC");
break;
}
$list_groups = db_get_all_rows_sql("
SELECT *
FROM tgrupo
WHERE id_grupo IN (" . $user_groups_ids . ")
ORDER BY nombre COLLATE utf8_general_ci ASC"
);
}
$list = array();
if ($list_groups == false) {
$list_groups = array();
}
if ($returnAllGroup) {
$i = 1;
$list[0]['_id_'] = 0;
$list[0]['_name_'] = __('All');
$list[0]['_agents_unknown_'] = 0;
$list[0]['_monitors_alerts_fired_'] = 0;
$list[0]['_total_agents_'] = 0;
@ -2425,7 +2397,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
$list[0]['_monitors_unknown_'] = 0;
$list[0]['_monitors_not_init_'] = 0;
$list[0]['_agents_not_init_'] = 0;
if ($mode == 'tactical') {
$list[0]['_agents_ok_'] = 0;
$list[0]['_agents_warning_'] = 0;
@ -2436,81 +2408,93 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
else {
$i = 0;
}
/*
/*
* Agent cache for metaconsole.
* Retrieve the statistic data from the cache table.
*/
if (!$user_strict && is_metaconsole() && !empty($list_groups)) {
if (is_metaconsole() && !empty($list_groups)) {
$cache_table = 'tmetaconsole_agent';
$sql_stats = "SELECT id_grupo, COUNT(id_agente) AS agents_total,
SUM(total_count) AS monitors_total,
SUM(normal_count) AS monitors_ok,
SUM(warning_count) AS monitors_warning,
SUM(critical_count) AS monitors_critical,
SUM(unknown_count) AS monitors_unknown,
SUM(notinit_count) AS monitors_not_init,
SUM(fired_count) AS alerts_fired
FROM $cache_table
WHERE disabled = 0
AND id_grupo IN ($user_groups_ids)
GROUP BY id_grupo";
$sql_stats =
"SELECT id_grupo, COUNT(id_agente) AS agents_total,
SUM(total_count) AS monitors_total,
SUM(normal_count) AS monitors_ok,
SUM(warning_count) AS monitors_warning,
SUM(critical_count) AS monitors_critical,
SUM(unknown_count) AS monitors_unknown,
SUM(notinit_count) AS monitors_not_init,
SUM(fired_count) AS alerts_fired
FROM $cache_table
WHERE disabled = 0
AND id_grupo IN ($user_groups_ids)
GROUP BY id_grupo"
;
$data_stats = db_get_all_rows_sql($sql_stats);
$sql_stats_unknown = "SELECT id_grupo, COUNT(id_agente) AS agents_unknown
FROM $cache_table
WHERE disabled = 0
AND id_grupo IN ($user_groups_ids)
AND critical_count = 0
AND warning_count = 0
AND unknown_count > 0
GROUP BY id_grupo";
$sql_stats_unknown =
"SELECT id_grupo, COUNT(id_agente) AS agents_unknown
FROM $cache_table
WHERE disabled = 0
AND id_grupo IN ($user_groups_ids)
AND critical_count = 0
AND warning_count = 0
AND unknown_count > 0
GROUP BY id_grupo"
;
$data_stats_unknown = db_get_all_rows_sql($sql_stats_unknown);
$sql_stats_not_init = "SELECT id_grupo, COUNT(id_agente) AS agents_not_init
FROM $cache_table
WHERE disabled = 0
AND id_grupo IN ($user_groups_ids)
AND (total_count = 0 OR total_count = notinit_count)
GROUP BY id_grupo";
$sql_stats_not_init =
"SELECT id_grupo, COUNT(id_agente) AS agents_not_init
FROM $cache_table
WHERE disabled = 0
AND id_grupo IN ($user_groups_ids)
AND (total_count = 0 OR total_count = notinit_count)
GROUP BY id_grupo"
;
$data_stats_not_init = db_get_all_rows_sql($sql_stats_not_init);
if ($mode == 'tactical' || $mode == 'tree') {
$sql_stats_ok = "SELECT id_grupo, COUNT(id_agente) AS agents_ok
FROM $cache_table
WHERE disabled = 0
AND id_grupo IN ($user_groups_ids)
AND critical_count = 0
AND warning_count = 0
AND unknown_count = 0
AND normal_count > 0
GROUP BY id_grupo";
$sql_stats_ok =
"SELECT id_grupo, COUNT(id_agente) AS agents_ok
FROM $cache_table
WHERE disabled = 0
AND id_grupo IN ($user_groups_ids)
AND critical_count = 0
AND warning_count = 0
AND unknown_count = 0
AND normal_count > 0
GROUP BY id_grupo"
;
$data_stats_ok = db_get_all_rows_sql($sql_stats_ok);
$sql_stats_warning = "SELECT id_grupo, COUNT(id_agente) AS agents_warning
FROM $cache_table
WHERE disabled = 0
AND id_grupo IN ($user_groups_ids)
AND critical_count = 0
AND warning_count > 0
GROUP BY id_grupo";
$sql_stats_warning =
"SELECT id_grupo, COUNT(id_agente) AS agents_warning
FROM $cache_table
WHERE disabled = 0
AND id_grupo IN ($user_groups_ids)
AND critical_count = 0
AND warning_count > 0
GROUP BY id_grupo"
;
$data_stats_warning = db_get_all_rows_sql($sql_stats_warning);
$sql_stats_critical = "SELECT id_grupo, COUNT(id_agente) AS agents_critical
FROM $cache_table
WHERE disabled = 0
AND id_grupo IN ($user_groups_ids)
AND critical_count > 0
GROUP BY id_grupo";
$sql_stats_critical =
"SELECT id_grupo, COUNT(id_agente) AS agents_critical
FROM $cache_table
WHERE disabled = 0
AND id_grupo IN ($user_groups_ids)
AND critical_count > 0
GROUP BY id_grupo"
;
$data_stats_critical = db_get_all_rows_sql($sql_stats_critical);
}
$stats_by_group = array();
if (!empty($data_stats)) {
foreach ($data_stats as $value) {
$group_id = (int) $value['id_grupo'];
$stats = array();
$stats['agents_total'] = (int) $value['agents_total'];
$stats['monitors_total'] = (int) $value['monitors_total'];
@ -2522,7 +2506,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
$stats['alerts_fired'] = (int) $value['alerts_fired'];
$stats_by_group[$group_id] = $stats;
}
if (!empty($stats_by_group)) {
if (!empty($data_stats_unknown)) {
foreach ($data_stats_unknown as $value) {
@ -2567,26 +2551,26 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
}
}
}
foreach ($list_groups as $key => $item) {
$id = $item['id_grupo'];
if (!$user_strict && is_metaconsole()) { // Agent cache
if (is_metaconsole()) { // Agent cache
$group_stat = array();
if (isset($stats_by_group[$id]))
$group_stat = $stats_by_group[$id];
$list[$i]['_id_'] = $id;
$list[$i]['_name_'] = $item['nombre'];
$list[$i]['_iconImg_'] = html_print_image ("images/groups_small/" . groups_get_icon($item['id_grupo']).".png", true, array ("style" => 'vertical-align: middle;'));
if ($mode == 'tree' && !empty($item['parent']))
$list[$i]['_parent_id_'] = $item['parent'];
$list[$i]['_agents_unknown_'] = isset($group_stat['agents_unknown']) ? $group_stat['agents_unknown'] : 0;
$list[$i]['_monitors_alerts_fired_'] = isset($group_stat['alerts_fired']) ? $group_stat['alerts_fired'] : 0;
$list[$i]['_total_agents_'] = isset($group_stat['agents_total']) ? $group_stat['agents_total'] : 0;
// This fields are not in database
$list[$i]['_monitors_ok_'] = isset($group_stat['monitors_ok']) ? $group_stat['monitors_ok'] : 0;
$list[$i]['_monitors_critical_'] = isset($group_stat['monitors_critical']) ? $group_stat['monitors_critical'] : 0;
@ -2594,38 +2578,38 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
$list[$i]['_monitors_unknown_'] = isset($group_stat['monitors_unknown']) ? $group_stat['monitors_unknown'] : 0;
$list[$i]['_monitors_not_init_'] = isset($group_stat['monitors_not_init']) ? $group_stat['monitors_not_init'] : 0;
$list[$i]['_agents_not_init_'] = isset($group_stat['agents_not_init']) ? $group_stat['agents_not_init'] : 0;
if ($mode == 'tactical' || $mode == 'tree') {
$list[$i]['_agents_ok_'] = isset($group_stat['agents_ok']) ? $group_stat['agents_ok'] : 0;
$list[$i]['_agents_warning_'] = isset($group_stat['agents_warning']) ? $group_stat['agents_warning'] : 0;
$list[$i]['_agents_critical_'] = isset($group_stat['agents_critical']) ? $group_stat['agents_critical'] : 0;
$list[$i]['_monitors_alerts_'] = isset($group_stat['alerts']) ? $group_stat['alerts'] : 0;;
$list[$i]["_monitor_alerts_fire_count_"] = $group_stat[0]["alerts_fired"];
$list[$i]["_total_checks_"] = $group_stat[0]["modules"];
$list[$i]["_total_alerts_"] = $group_stat[0]["alerts"];
}
if ($mode == 'tactical') {
// Get total count of monitors for this group, except disabled.
// Get total count of monitors for this group, except disabled.
$list[$i]["_monitor_checks_"] = $list[$i]["_monitors_not_init_"] + $list[$i]["_monitors_unknown_"] + $list[$i]["_monitors_warning_"] + $list[$i]["_monitors_critical_"] + $list[$i]["_monitors_ok_"];
// Calculate not_normal monitors
$list[$i]["_monitor_not_normal_"] = $list[$i]["_monitor_checks_"] - $list[$i]["_monitors_ok_"];
if ($list[$i]["_monitor_not_normal_"] > 0 && $list[$i]["_monitor_checks_"] > 0) {
$list[$i]["_monitor_health_"] = format_numeric (100 - ($list[$i]["_monitor_not_normal_"] / ($list[$i]["_monitor_checks_"] / 100)), 1);
}
else {
$list[$i]["_monitor_health_"] = 100;
}
if ($list[$i]["_monitors_not_init_"] > 0 && $list[$i]["_monitor_checks_"] > 0) {
$list[$i]["_module_sanity_"] = format_numeric (100 - ($list[$i]["_monitors_not_init_"] / ($list[$i]["_monitor_checks_"] / 100)), 1);
}
else {
$list[$i]["_module_sanity_"] = 100;
}
if (isset($list[$i]["_alerts_"])) {
if ($list[$i]["_monitors_alerts_fired_"] > 0 && $list[$i]["_alerts_"] > 0) {
$list[$i]["_alert_level_"] = format_numeric (100 - ($list[$i]["_monitors_alerts_fired_"] / ($list[$i]["_alerts_"] / 100)), 1);
@ -2638,19 +2622,19 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
$list[$i]["_alert_level_"] = 100;
$list[$i]["_alerts_"] = 0;
}
$list[$i]["_monitor_bad_"] = $list[$i]["_monitors_critical_"] + $list[$i]["_monitors_warning_"];
if ($list[$i]["_monitor_bad_"] > 0 && $list[$i]["_monitor_checks_"] > 0) {
$list[$i]["_global_health_"] = format_numeric (100 - ($list[$i]["_monitor_bad_"] / ($list[$i]["_monitor_checks_"] / 100)), 1);
}
else {
$list[$i]["_global_health_"] = 100;
}
$list[$i]["_server_sanity_"] = format_numeric (100 - $list[$i]["_module_sanity_"], 1);
}
if ($returnAllGroup) {
$list[0]['_agents_unknown_'] += $list[$i]['_agents_unknown_'];
$list[0]['_monitors_alerts_fired_'] += $list[$i]['_monitors_alerts_fired_'];
@ -2661,7 +2645,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
$list[0]['_monitors_unknown_'] += $list[$i]['_monitors_unknown_'];
$list[0]['_monitors_not_init_'] += $list[$i]['_monitors_not_init_'];
$list[0]['_agents_not_init_'] += $list[$i]['_agents_not_init_'];
if ($mode == 'tactical' || $mode == 'tree') {
$list[0]['_agents_ok_'] += $list[$i]['_agents_ok_'];
$list[0]['_agents_warning_'] += $list[$i]['_agents_warning_'];
@ -2669,7 +2653,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
$list[0]['_monitors_alerts_'] += $list[$i]['_monitors_alerts_'];
}
}
if ($mode == 'group') {
if (($list[$i]['_agents_unknown_'] == 0) && ($list[$i]['_monitors_alerts_fired_'] == 0)
&& ($list[$i]['_total_agents_'] == 0) && ($list[$i]['_monitors_ok_'] == 0)
@ -2677,26 +2661,26 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
unset($list[$i]);
}
}
}
else if (($config["realtimestats"] == 0) && !$user_strict) {
else if (($config["realtimestats"] == 0)) {
$group_stat = db_get_all_rows_sql ("SELECT *
FROM tgroup_stat, tgrupo
WHERE tgrupo.id_grupo = tgroup_stat.id_group
AND tgroup_stat.id_group = $id
ORDER BY nombre");
$list[$i]['_id_'] = $id;
$list[$i]['_name_'] = $item['nombre'];
$list[$i]['_iconImg_'] = html_print_image ("images/groups_small/" . groups_get_icon($item['id_grupo']).".png", true, array ("style" => 'vertical-align: middle;'));
if ($mode == 'tree' && !empty($item['parent']))
$list[$i]['_parent_id_'] = $item['parent'];
$list[$i]['_agents_unknown_'] = $group_stat[0]["unknown"];
$list[$i]['_monitors_alerts_fired_'] = $group_stat[0]["alerts_fired"];
$list[$i]['_total_agents_'] = $group_stat[0]["agents"];
// This fields are not in database
$list[$i]['_monitors_ok_'] = (int) groups_get_normal_monitors($id);
$list[$i]['_monitors_critical_'] = (int) groups_get_critical_monitors($id);
@ -2704,38 +2688,38 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
$list[$i]['_monitors_unknown_'] = (int) groups_get_unknown_monitors($id);
$list[$i]['_monitors_not_init_'] = (int) groups_get_not_init_monitors($id);
$list[$i]['_agents_not_init_'] = (int) groups_get_not_init_agents($id);
if ($mode == 'tactical' || $mode == 'tree') {
$list[$i]['_agents_ok_'] = $group_stat[0]["normal"];
$list[$i]['_agents_warning_'] = $group_stat[0]["warning"];
$list[$i]['_agents_critical_'] = $group_stat[0]["critical"];
$list[$i]['_monitors_alerts_'] = $group_stat[0]["alerts"];
$list[$i]["_monitor_alerts_fire_count_"] = $group_stat[0]["alerts_fired"];
$list[$i]["_total_checks_"] = $group_stat[0]["modules"];
$list[$i]["_total_alerts_"] = $group_stat[0]["alerts"];
}
if ($mode == 'tactical') {
// Get total count of monitors for this group, except disabled.
// Get total count of monitors for this group, except disabled.
$list[$i]["_monitor_checks_"] = $list[$i]["_monitors_not_init_"] + $list[$i]["_monitors_unknown_"] + $list[$i]["_monitors_warning_"] + $list[$i]["_monitors_critical_"] + $list[$i]["_monitors_ok_"];
// Calculate not_normal monitors
$list[$i]["_monitor_not_normal_"] = $list[$i]["_monitor_checks_"] - $list[$i]["_monitors_ok_"];
if ($list[$i]["_monitor_not_normal_"] > 0 && $list[$i]["_monitor_checks_"] > 0) {
$list[$i]["_monitor_health_"] = format_numeric (100 - ($list[$i]["_monitor_not_normal_"] / ($list[$i]["_monitor_checks_"] / 100)), 1);
}
else {
$list[$i]["_monitor_health_"] = 100;
}
if ($list[$i]["_monitors_not_init_"] > 0 && $list[$i]["_monitor_checks_"] > 0) {
$list[$i]["_module_sanity_"] = format_numeric (100 - ($list[$i]["_monitors_not_init_"] / ($list[$i]["_monitor_checks_"] / 100)), 1);
}
else {
$list[$i]["_module_sanity_"] = 100;
}
if (isset($list[$i]["_alerts_"])) {
if ($list[$i]["_monitors_alerts_fired_"] > 0 && $list[$i]["_alerts_"] > 0) {
$list[$i]["_alert_level_"] = format_numeric (100 - ($list[$i]["_monitors_alerts_fired_"] / ($list[$i]["_alerts_"] / 100)), 1);
@ -2743,24 +2727,24 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
else {
$list[$i]["_alert_level_"] = 100;
}
}
}
else {
$list[$i]["_alert_level_"] = 100;
$list[$i]["_alerts_"] = 0;
}
$list[$i]["_monitor_bad_"] = $list[$i]["_monitors_critical_"] + $list[$i]["_monitors_warning_"];
if ($list[$i]["_monitor_bad_"] > 0 && $list[$i]["_monitor_checks_"] > 0) {
$list[$i]["_global_health_"] = format_numeric (100 - ($list[$i]["_monitor_bad_"] / ($list[$i]["_monitor_checks_"] / 100)), 1);
}
else {
$list[$i]["_global_health_"] = 100;
}
$list[$i]["_server_sanity_"] = format_numeric (100 - $list[$i]["_module_sanity_"], 1);
}
if ($returnAllGroup) {
$list[0]['_agents_unknown_'] += $group_stat[0]["unknown"];
$list[0]['_monitors_alerts_fired_'] += $group_stat[0]["alerts_fired"];
@ -2771,7 +2755,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
$list[0]['_monitors_unknown_'] += $list[$i]['_monitors_unknown_'];
$list[0]['_monitors_not_init_'] += $list[$i]['_monitors_not_init_'];
$list[0]['_agents_not_init_'] += $list[$i]['_agents_not_init_'];
if ($mode == 'tactical' || $mode == 'tree') {
$list[0]['_agents_ok_'] += $group_stat[0]["normal"];
$list[0]['_agents_warning_'] += $group_stat[0]["warning"];
@ -2779,7 +2763,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
$list[0]['_monitors_alerts_'] += $group_stat[0]["alerts"];
}
}
if ($mode == 'group') {
if (! defined ('METACONSOLE')) {
if (($list[$i]['_agents_unknown_'] == 0) && ($list[$i]['_monitors_alerts_fired_'] == 0) && ($list[$i]['_total_agents_'] == 0) && ($list[$i]['_monitors_ok_'] == 0) && ($list[$i]['_monitors_critical_'] == 0) && ($list[$i]['_monitors_warning_'] == 0) && ($list[$i]['_monitors_unknown_'] == 0) && ($list[$i]['_monitors_not_init_'] == 0) && ($list[$i]['_agents_not_init_'] == 0)) {
@ -2792,16 +2776,15 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
}
}
}
}
else {
$list[$i]['_id_'] = $id;
$list[$i]['_name_'] = $item['nombre'];
$list[$i]['_iconImg_'] = html_print_image ("images/groups_small/" . groups_get_icon($item['id_grupo']).".png", true, array ("style" => 'vertical-align: middle;'));
if ($mode == 'tree' && !empty($item['parent']))
$list[$i]['_parent_id_'] = $item['parent'];
$list[$i]['_monitors_ok_'] = (int) groups_get_normal_monitors ($id, $agent_filter, $module_filter, $user_strict, $acltags, $config["realtimestats"]);
$list[$i]['_monitors_critical_'] = (int) groups_get_critical_monitors ($id, $agent_filter, $module_filter, $user_strict, $acltags, $config["realtimestats"]);
$list[$i]['_monitors_warning_'] = (int) groups_get_warning_monitors ($id, $agent_filter, $module_filter, $user_strict, $acltags, $config["realtimestats"]);
@ -2811,37 +2794,37 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
$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"]);
if ($mode == 'tactical' || $mode == 'tree') {
$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);
// TODO
//~ $list[$i]["_total_checks_"]
//~ $list[$i]["_total_checks_"]
//~ $list[$i]["_total_alerts_"]
// Get total count of monitors for this group, except disabled.
// Get total count of monitors for this group, except disabled.
$list[$i]["_monitor_checks_"] = $list[$i]["_monitors_not_init_"] + $list[$i]["_monitors_unknown_"] + $list[$i]["_monitors_warning_"] + $list[$i]["_monitors_critical_"] + $list[$i]["_monitors_ok_"];
// Calculate not_normal monitors
$list[$i]["_monitor_not_normal_"] = $list[$i]["_monitor_checks_"] - $list[$i]["_monitors_ok_"];
if ($list[$i]["_monitor_not_normal_"] > 0 && $list[$i]["_monitor_checks_"] > 0) {
$list[$i]["_monitor_health_"] = format_numeric (100 - ($list[$i]["_monitor_not_normal_"] / ($list[$i]["_monitor_checks_"] / 100)), 1);
}
else {
$list[$i]["_monitor_health_"] = 100;
}
if ($list[$i]["_monitors_not_init_"] > 0 && $list[$i]["_monitor_checks_"] > 0) {
$list[$i]["_module_sanity_"] = format_numeric (100 - ($list[$i]["_monitors_not_init_"] / ($list[$i]["_monitor_checks_"] / 100)), 1);
}
else {
$list[$i]["_module_sanity_"] = 100;
}
if (isset($list[$i]["_alerts_"])) {
if ($list[$i]["_monitors_alerts_fired_"] > 0 && $list[$i]["_alerts_"] > 0) {
$list[$i]["_alert_level_"] = format_numeric (100 - ($list[$i]["_monitors_alerts_fired_"] / ($list[$i]["_alerts_"] / 100)), 1);
@ -2854,19 +2837,19 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
$list[$i]["_alert_level_"] = 100;
$list[$i]["_alerts_"] = 0;
}
$list[$i]["_monitor_bad_"] = $list[$i]["_monitors_critical_"] + $list[$i]["_monitors_warning_"];
if ($list[$i]["_monitor_bad_"] > 0 && $list[$i]["_monitor_checks_"] > 0) {
$list[$i]["_global_health_"] = format_numeric (100 - ($list[$i]["_monitor_bad_"] / ($list[$i]["_monitor_checks_"] / 100)), 1);
}
else {
$list[$i]["_global_health_"] = 100;
}
$list[$i]["_server_sanity_"] = format_numeric (100 - $list[$i]["_module_sanity_"], 1);
}
if ($returnAllGroup) {
$list[0]['_agents_unknown_'] += $list[$i]['_agents_unknown_'];
$list[0]['_monitors_alerts_fired_'] += $list[$i]['_monitors_alerts_fired_'];
@ -2877,7 +2860,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
$list[0]['_monitors_unknown_'] += $list[$i]['_monitors_unknown_'];
$list[0]['_monitors_not_init_'] = $list[$i]['_monitors_not_init_'];
$list[0]['_agents_not_init_'] += $list[$i]['_agents_not_init_'];
if ($mode == 'tactical' || $mode == 'tree') {
$list[0]['_agents_ok_'] += $list[$i]['_agents_ok_'];
$list[0]['_agents_warning_'] += $list[$i]['_agents_warning_'];
@ -2885,7 +2868,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
$list[0]['_monitors_alerts_'] += $list[$i]['_monitors_alerts_'];
}
}
if ($mode == 'group') {
if (! defined ('METACONSOLE')) {
if (($list[$i]['_agents_unknown_'] == 0) && ($list[$i]['_monitors_alerts_fired_'] == 0) && ($list[$i]['_total_agents_'] == 0) && ($list[$i]['_monitors_ok_'] == 0) && ($list[$i]['_monitors_critical_'] == 0) && ($list[$i]['_monitors_warning_'] == 0) && ($list[$i]['_monitors_unknown_'] == 0) && ($list[$i]['_monitors_not_init_'] == 0) && ($list[$i]['_agents_not_init_'] == 0)) {
@ -2900,113 +2883,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
}
$i++;
}
if ($user_strict) {
foreach ($user_tags as $group_id => $tag_name) {
$id = db_get_value('id_tag', 'ttag', 'name', $tag_name);
$list[$i]['_id_'] = $id;
$list[$i]['_name_'] = $tag_name;
$list[$i]['_iconImg_'] = html_print_image ("images/tag_red.png", true, array ("style" => 'vertical-align: middle;'));
$list[$i]['_is_tag_'] = 1;
$list[$i]['_total_agents_'] = (int) tags_get_total_agents ($id, $acltags, $agent_filter, $module_filter, $config["realtimestats"]);
$list[$i]['_agents_unknown_'] = (int) tags_get_unknown_agents ($id, $acltags, $agent_filter, $module_filter, $config["realtimestats"]);
$list[$i]['_agents_not_init_'] = (int) tags_get_not_init_agents ($id, $acltags, $agent_filter, $module_filter, $config["realtimestats"]);
$list[$i]['_monitors_ok_'] = (int) tags_get_normal_monitors ($id, $acltags, $agent_filter, $module_filter);
$list[$i]['_monitors_critical_'] = (int) tags_get_critical_monitors ($id, $acltags, $agent_filter, $module_filter);
$list[$i]['_monitors_warning_'] = (int) tags_get_warning_monitors ($id, $acltags, $agent_filter, $module_filter);
$list[$i]['_monitors_not_init_'] = (int) tags_get_not_init_monitors ($id, $acltags, $agent_filter, $module_filter);
$list[$i]['_monitors_unknown_'] = (int) tags_get_unknown_monitors ($id, $acltags, $agent_filter, $module_filter);
$list[$i]['_monitors_alerts_fired_'] = tags_monitors_fired_alerts($id, $acltags);
if ($mode == 'tactical' || $mode == 'tree') {
$list[$i]['_agents_ok_'] = (int) tags_get_normal_agents ($id, $acltags, $agent_filter, $module_filter, $config["realtimestats"]);
$list[$i]['_agents_warning_'] = (int) tags_get_warning_agents ($id, $acltags, $agent_filter, $module_filter, $config["realtimestats"]);
$list[$i]['_agents_critical_'] = (int) tags_get_critical_agents ($id, $acltags, $agent_filter, $module_filter, $config["realtimestats"]);
$list[$i]['_monitors_alerts_'] = tags_get_monitors_alerts ($id, $acltags);
}
if ($mode == 'tactical') {
// Get total count of monitors for this group, except disabled.
$list[$i]["_monitor_checks_"] = $list[$i]["_monitors_not_init_"] + $list[$i]["_monitors_unknown_"] + $list[$i]["_monitors_warning_"] + $list[$i]["_monitors_critical_"] + $list[$i]["_monitors_ok_"];
// Calculate not_normal monitors
$list[$i]["_monitor_not_normal_"] = $list[$i]["_monitor_checks_"] - $list[$i]["_monitors_ok_"];
if ($list[$i]["_monitor_not_normal_"] > 0 && $list[$i]["_monitor_checks_"] > 0) {
$list[$i]["_monitor_health_"] = format_numeric (100 - ($list[$i]["_monitor_not_normal_"] / ($list[$i]["_monitor_checks_"] / 100)), 1);
}
else {
$list[$i]["_monitor_health_"] = 100;
}
if ($list[$i]["_monitors_not_init_"] > 0 && $list[$i]["_monitor_checks_"] > 0) {
$list[$i]["_module_sanity_"] = format_numeric (100 - ($list[$i]["_monitors_not_init_"] / ($list[$i]["_monitor_checks_"] / 100)), 1);
}
else {
$list[$i]["_module_sanity_"] = 100;
}
if (isset($list[$i]["_monitors_alerts_"])) {
if ($list[$i]["_monitors_alerts_fired_"] > 0 && $list[$i]["_monitors_alerts_"] > 0) {
$list[$i]["_alert_level_"] = format_numeric (100 - ($list[$i]["_monitors_alerts_fired_"] / ($list[$i]["_monitors_alerts_"] / 100)), 1);
}
else {
$list[$i]["_alert_level_"] = 100;
}
}
else {
$list[$i]["_alert_level_"] = 100;
$list[$i]["_monitors_alerts_"] = 0;
}
$list[$i]["_monitor_bad_"] = $list[$i]["_monitors_critical_"] + $list[$i]["_monitors_warning_"];
if ($list[$i]["_monitor_bad_"] > 0 && $list[$i]["_monitor_checks_"] > 0) {
$list[$i]["_global_health_"] = format_numeric (100 - ($list[$i]["_monitor_bad_"] / ($list[$i]["_monitor_checks_"] / 100)), 1);
}
else {
$list[$i]["_global_health_"] = 100;
}
$list[$i]["_server_sanity_"] = format_numeric (100 - $list[$i]["_module_sanity_"], 1);
}
if ($returnAllGroup) {
$list[0]['_agents_unknown_'] += $list[$i]['_agents_unknown_'];
$list[0]['_monitors_alerts_fired_'] += $list[$i]['_monitors_alerts_fired_'];
$list[0]['_total_agents_'] += $list[$i]['_total_agents_'];
$list[0]['_monitors_ok_'] += $list[$i]['_monitors_ok_'];
$list[0]['_monitors_critical_'] += $list[$i]['_monitors_critical_'];
$list[0]['_monitors_warning_'] += $list[$i]['_monitors_warning_'];
$list[0]['_monitors_unknown_'] += $list[$i]['_monitors_unknown_'];
$list[0]['_agents_not_init_'] += $list[$i]['_agents_not_init_'];
$list[0]['_monitors_not_init_'] += $list[$i]['_monitors_not_init_'];
if ($mode == 'tactical' || $mode == 'tree') {
$list[0]['_agents_ok_'] += $list[$i]['_agents_ok_'];
$list[0]['_agents_warning_'] += $list[$i]['_agents_warning_'];
$list[0]['_agents_critical_'] += $list[$i]['_agents_critical_'];
$list[0]['_monitors_alerts_'] += $list[$i]['_monitors_alerts_'];
}
}
if ($mode == 'group') {
if (! defined ('METACONSOLE')) {
if (($list[$i]['_agents_unknown_'] == 0) && ($list[$i]['_monitors_alerts_fired_'] == 0) && ($list[$i]['_total_agents_'] == 0) && ($list[$i]['_monitors_ok_'] == 0) && ($list[$i]['_monitors_critical_'] == 0) && ($list[$i]['_monitors_warning_'] == 0) && ($list[$i]['_monitors_unknown_'] == 0) && ($list[$i]['_monitors_not_init_'] == 0) && ($list[$i]['_agents_not_init_'] == 0)) {
unset($list[$i]);
}
}
else {
if (($list[$i]['_agents_unknown_'] == 0) && ($list[$i]['_monitors_alerts_fired_'] == 0) && ($list[$i]['_total_agents_'] == 0) && ($list[$i]['_monitors_ok_'] == 0) && ($list[$i]['_monitors_critical_'] == 0) && ($list[$i]['_monitors_warning_'] == 0)) {
unset($list[$i]);
}
}
}
$i++;
}
}
return $list;
}