getGroupAclCondition(); $table = is_metaconsole() ? 'tmetaconsole_agent' : 'tagente'; $table_sec = is_metaconsole() ? 'tmetaconsole_agent_secondary_group' : 'tagent_secondary_group'; $sql = "SELECT SUM(ta.critical_count) AS _monitors_critical_, SUM(ta.warning_count) AS _monitors_warning_, SUM(ta.unknown_count) AS _monitors_unknown_, SUM(ta.notinit_count) AS _monitors_not_init_, SUM(ta.normal_count) AS _monitors_ok_, SUM(ta.total_count) AS _monitor_checks_, SUM(ta.fired_count) AS _monitors_alerts_fired_, SUM(IF(ta.critical_count > 0, 1, 0)) AS _agents_critical_, SUM(IF(ta.critical_count = 0 AND ta.warning_count > 0, 1, 0)) AS _agents_warning_, 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_, SUM(IF(ta.total_count = ta.normal_count AND ta.total_count <> ta.notinit_count, 1, 0)) AS _agents_ok_, COUNT(ta.id_agente) AS _total_agents_, '$all_name' AS _name_, 0 AS _id_, '' AS _icon_ FROM $table ta WHERE ta.disabled = 0 AND ta.id_agente IN ( SELECT ta.id_agente FROM $table ta LEFT JOIN $table_sec tasg ON ta.id_agente = tasg.id_agent WHERE ta.disabled = 0 $group_acl GROUP BY ta.id_agente ) "; $data = db_get_row_sql($sql); $data['_monitor_not_normal_'] = ($data['_monitor_checks_'] - $data['_monitors_ok_']); return $data; } function groupview_get_groups_list($id_user=false, $access='AR', $is_not_paginated=false) { global $config; if ($id_user == false) { $id_user = $config['id_user']; } $tree_group = new TreeGroup('group', 'group'); $tree_group->setPropagateCounters(false); $tree_group->setFilter( [ 'searchAgent' => '', 'statusAgent' => AGENT_STATUS_ALL, 'searchModule' => '', 'statusModule' => -1, 'groupID' => 0, 'tagID' => 0, 'show_not_init_agents' => 1, 'show_not_init_modules' => 1, ] ); $info = $tree_group->getArray(); $info = groupview_plain_groups($info); $counter = count($info); $offset = get_parameter('offset', 0); $groups_view = $is_not_paginated ? $info : array_slice($info, $offset, $config['block_size']); $agents_counters = array_reduce( $groups_view, function ($carry, $item) { $carry[$item['id']] = $item; return $carry; }, [] ); $modules_counters = groupview_get_modules_counters(array_keys($agents_counters)); $modules_counters = array_reduce( $modules_counters, function ($carry, $item) { $carry[$item['g']] = $item; return $carry; }, [] ); $total_counters = []; foreach ($agents_counters as $id_group => $agent_counter) { $list[$id_group]['_name_'] = $agent_counter['name']; $list[$id_group]['_id_'] = $agent_counter['id']; $list[$id_group]['_iconImg_'] = $agent_counter['icon']; $list[$id_group]['_agents_critical_'] = $agent_counter['counters']['critical']; $list[$id_group]['_agents_warning_'] = $agent_counter['counters']['warning']; $list[$id_group]['_agents_unknown_'] = $agent_counter['counters']['unknown']; $list[$id_group]['_agents_not_init_'] = $agent_counter['counters']['not_init']; $list[$id_group]['_agents_ok_'] = $agent_counter['counters']['ok']; $list[$id_group]['_total_agents_'] = $agent_counter['counters']['total']; $list[$id_group]['_monitors_critical_'] = (int) $modules_counters[$id_group]['total_module_critical']; $list[$id_group]['_monitors_warning_'] = (int) $modules_counters[$id_group]['total_module_warning']; $list[$id_group]['_monitors_unknown_'] = (int) $modules_counters[$id_group]['total_module_unknown']; $list[$id_group]['_monitors_not_init_'] = (int) $modules_counters[$id_group]['total_module_not_init']; $list[$id_group]['_monitors_ok_'] = (int) $modules_counters[$id_group]['total_module_normal']; $list[$id_group]['_monitor_checks_'] = (int) $modules_counters[$id_group]['total_module']; $list[$id_group]['_monitor_not_normal_'] = ($list[$group['id_grupo']]['_monitor_checks_'] - $list[$group['id_grupo']]['_monitors_ok_']); $list[$id_group]['_monitors_alerts_fired_'] = (int) $modules_counters[$id_group]['total_module_alerts']; } array_unshift($list, groupview_get_all_counters($tree_group)); return [ 'groups' => $list, 'counter' => $counter, ]; }