Fixed problems with strict users. Tiquet: #3308
This commit is contained in:
parent
94af41f00c
commit
f766bef9bb
|
@ -14,8 +14,8 @@
|
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
include_once ("include/functions_groups.php");
|
||||
include_once ("include/functions_tags.php");
|
||||
include_once ($config['homedir'] . "/include/functions_groups.php");
|
||||
include_once ($config['homedir'] . "/include/functions_tags.php");
|
||||
|
||||
function groupview_get_all_data ($id_user = false, $user_strict = false, $acltags, $returnAllGroup = false, $agent_filter = array(), $module_filter = array()) {
|
||||
global $config;
|
||||
|
@ -449,7 +449,7 @@ function groupview_get_groups_list($id_user = false, $user_strict = false, $acce
|
|||
}
|
||||
$server_list = groupview_get_data ($id_user, $user_strict,
|
||||
$acltags, $returnAllGroup);
|
||||
|
||||
|
||||
foreach ($server_list as $server_item) {
|
||||
if (! isset ($result_list[$server_item['_name_']])) {
|
||||
|
||||
|
@ -490,9 +490,7 @@ function groupview_get_data ($id_user = false, $user_strict = false, $acltags, $
|
|||
$groups_without_tags = array();
|
||||
foreach ($acltags as $group => $tags) {
|
||||
if ($user_strict) { //Remove groups with tags
|
||||
if ($tags == '') {
|
||||
$groups_without_tags[$group] = $group;
|
||||
}
|
||||
$groups_without_tags[$group] = $group;
|
||||
}
|
||||
$user_groups[$group] = groups_get_name($group);
|
||||
if ($tags != '') {
|
||||
|
@ -504,14 +502,16 @@ function groupview_get_data ($id_user = false, $user_strict = false, $acltags, $
|
|||
}
|
||||
}
|
||||
|
||||
$user_groups_ids = '0,';
|
||||
|
||||
if (!$user_strict)
|
||||
$acltags[0] = 0;
|
||||
|
||||
if ($user_strict) {
|
||||
$user_groups_ids .= implode(',', array_keys($groups_without_tags));
|
||||
$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)) {
|
||||
if (is_metaconsole()) {
|
||||
switch ($config["dbtype"]) {
|
||||
|
@ -570,66 +570,70 @@ function groupview_get_data ($id_user = false, $user_strict = false, $acltags, $
|
|||
}
|
||||
}
|
||||
}
|
||||
//Add the group "All" at first
|
||||
$group_all = array('id_grupo'=>0, 'nombre'=>'All', 'icon'=>'', 'parent'=>'', 'propagate'=>0, 'disabled'=>0,
|
||||
'custom_id'=>'', 'id_skin'=>0, 'description'=>'', 'contact'=>'', 'other'=>'', 'password'=>'');
|
||||
array_unshift($list_groups, $group_all);
|
||||
//Takes the parents even without agents, first ids
|
||||
$fathers_id = '';
|
||||
$list_father_groups = array();
|
||||
foreach ($list_groups as $group) {
|
||||
if ($group['parent'] != '') {
|
||||
$grup = $group['parent'];
|
||||
while ($grup != 0) {
|
||||
$recursive_fathers = db_get_row_sql ("SELECT parent FROM tgrupo
|
||||
WHERE id_grupo = " . $grup);
|
||||
$grup = $recursive_fathers['parent'];
|
||||
if (!strpos($fathers_id, $grup)) {
|
||||
$fathers_id .= ',' . $grup;
|
||||
|
||||
if (!$user_strict) {
|
||||
//Add the group "All" at first
|
||||
$group_all = array('id_grupo'=>0, 'nombre'=>'All', 'icon'=>'', 'parent'=>'', 'propagate'=>0, 'disabled'=>0,
|
||||
'custom_id'=>'', 'id_skin'=>0, 'description'=>'', 'contact'=>'', 'other'=>'', 'password'=>'');
|
||||
array_unshift($list_groups, $group_all);
|
||||
//Takes the parents even without agents, first ids
|
||||
$fathers_id = '';
|
||||
$list_father_groups = array();
|
||||
foreach ($list_groups as $group) {
|
||||
if ($group['parent'] != '') {
|
||||
$grup = $group['parent'];
|
||||
while ($grup != 0) {
|
||||
$recursive_fathers = db_get_row_sql ("SELECT parent FROM tgrupo
|
||||
WHERE id_grupo = " . $grup);
|
||||
$grup = $recursive_fathers['parent'];
|
||||
if (!strpos($fathers_id, $grup)) {
|
||||
$fathers_id .= ',' . $grup;
|
||||
}
|
||||
}
|
||||
if (!strpos($fathers_id, $group['parent'])) {
|
||||
$fathers_id .= ',' . $group['parent'];
|
||||
}
|
||||
}
|
||||
if (!strpos($fathers_id, $group['parent'])) {
|
||||
$fathers_id .= ',' . $group['parent'];
|
||||
}
|
||||
}
|
||||
}
|
||||
//Eliminate the first comma
|
||||
$fathers_id = substr($fathers_id, 1);
|
||||
//Takes the parents even without agents, complete groups
|
||||
$list_father_groups = db_get_all_rows_sql("
|
||||
SELECT *
|
||||
FROM tgrupo
|
||||
WHERE id_grupo IN (" . $fathers_id . ")
|
||||
ORDER BY nombre COLLATE utf8_general_ci ASC");
|
||||
if (!empty($list_father_groups)) {
|
||||
//Merges the arrays and eliminates the duplicates groups
|
||||
$list_groups = array_merge($list_groups, $list_father_groups);
|
||||
}
|
||||
$list_groups = groupview_array_unique_multidim($list_groups, 'id_grupo');
|
||||
//Order groups (Father-children)
|
||||
$ordered_groups = groupview_order_groups_for_parents($list_groups);
|
||||
$ordered_ids = array();
|
||||
$ordered_ids = groupview_order_group_ids($ordered_groups, $ordered_ids);
|
||||
$final_list = array();
|
||||
array_push($final_list, $group_all);
|
||||
|
||||
foreach ($ordered_ids as $key) {
|
||||
if ($key == 'All') {
|
||||
continue;
|
||||
}
|
||||
$complete_group = db_get_row_sql("
|
||||
//Eliminate the first comma
|
||||
$fathers_id = substr($fathers_id, 1);
|
||||
//Takes the parents even without agents, complete groups
|
||||
$list_father_groups = db_get_all_rows_sql("
|
||||
SELECT *
|
||||
FROM tgrupo
|
||||
WHERE nombre = '" . $key . "'");
|
||||
array_push($final_list, $complete_group);
|
||||
WHERE id_grupo IN (" . $fathers_id . ")
|
||||
ORDER BY nombre COLLATE utf8_general_ci ASC");
|
||||
if (!empty($list_father_groups)) {
|
||||
//Merges the arrays and eliminates the duplicates groups
|
||||
$list_groups = array_merge($list_groups, $list_father_groups);
|
||||
}
|
||||
$list_groups = groupview_array_unique_multidim($list_groups, 'id_grupo');
|
||||
//Order groups (Father-children)
|
||||
$ordered_groups = groupview_order_groups_for_parents($list_groups);
|
||||
$ordered_ids = array();
|
||||
$ordered_ids = groupview_order_group_ids($ordered_groups, $ordered_ids);
|
||||
$final_list = array();
|
||||
array_push($final_list, $group_all);
|
||||
|
||||
foreach ($ordered_ids as $key) {
|
||||
if ($key == 'All') {
|
||||
continue;
|
||||
}
|
||||
$complete_group = db_get_row_sql("
|
||||
SELECT *
|
||||
FROM tgrupo
|
||||
WHERE nombre = '" . $key . "'");
|
||||
array_push($final_list, $complete_group);
|
||||
}
|
||||
|
||||
$list_groups = $final_list;
|
||||
}
|
||||
|
||||
$list_groups = $final_list;
|
||||
|
||||
|
||||
$list = array();
|
||||
foreach ($list_groups as $group) {
|
||||
$list[$group['id_grupo']]['_name_'] = $group['nombre'];
|
||||
$list[$group['id_grupo']]['_id_'] = $group['id_grupo'];
|
||||
$list[$group['id_grupo']]['icon'] = $group['icon'];
|
||||
$list[$group['id_grupo']]['_monitors_critical_'] = 0;
|
||||
$list[$group['id_grupo']]['_monitors_warning_'] = 0;
|
||||
$list[$group['id_grupo']]['_monitors_unknown_'] = 0;
|
||||
|
@ -663,7 +667,10 @@ function groupview_get_data ($id_user = false, $user_strict = false, $acltags, $
|
|||
$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_"];
|
||||
|
||||
|
||||
if ($group['icon'])
|
||||
$list[$group['id_grupo']]["_iconImg_"] = html_print_image ("images/".$group['icon'].".png", true, array ("style" => 'vertical-align: middle;'));
|
||||
|
||||
// Calculate not_normal monitors
|
||||
$list[$group['id_grupo']]["_monitor_not_normal_"] = $list["_monitor_checks_"] - $list["_monitors_ok_"];
|
||||
|
||||
|
@ -761,105 +768,96 @@ function groupview_get_data ($id_user = false, $user_strict = false, $acltags, $
|
|||
$list["_server_sanity_"] = format_numeric (100 - $list["_module_sanity_"], 1);
|
||||
}
|
||||
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_'];
|
||||
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']]['_monitors_alerts_fired_'] = (int)$group_agents['_monitors_alerts_fired_'];
|
||||
|
||||
$list[$group['id_grupo']]['_total_agents_'] = (int)$group_agents['_total_agents_'];
|
||||
$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_"];
|
||||
$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_"];
|
||||
// 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_'];
|
||||
$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 (($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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$i = 1;
|
||||
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;
|
||||
|
||||
if ($user_strict) {
|
||||
$i = 0;
|
||||
foreach ($user_tags as $group_id => $tag_name) {
|
||||
$id = db_get_value('id_tag', 'ttag', 'name', $tag_name);
|
||||
$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);
|
||||
|
||||
$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 ($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 (! 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]);
|
||||
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]);
|
||||
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++;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue