diff --git a/pandora_console/include/class/Tree.class.php b/pandora_console/include/class/Tree.class.php index e383c1c13b..afbaab246d 100644 --- a/pandora_console/include/class/Tree.class.php +++ b/pandora_console/include/class/Tree.class.php @@ -1006,6 +1006,52 @@ class Tree { $item['total_count'] = $item['_total_agents_']; if (isset($item['_monitors_alerts_fired_'])) $item['total_fired_count'] = $item['_monitors_alerts_fired_']; + + // Agent filter for Strict ACL users + if ($this->filter["statusAgent"] != -1) { + switch ($this->filter["statusAgent"]) { + case AGENT_STATUS_NOT_INIT: + $item['total_count'] = $item['total_not_init_count']; + + $item['total_unknown_count'] = 0; + $item['total_critical_count'] = 0; + $item['total_warning_count'] = 0; + $item['total_normal_count'] = 0; + break; + case AGENT_STATUS_CRITICAL: + $item['total_count'] = $item['total_critical_count']; + + $item['total_unknown_count'] = 0; + $item['total_warning_count'] = 0; + $item['total_not_init_count'] = 0; + $item['total_normal_count'] = 0; + break; + case AGENT_STATUS_WARNING: + $item['total_count'] = $item['total_warning_count']; + + $item['total_unknown_count'] = 0; + $item['total_critical_count'] = 0; + $item['total_not_init_count'] = 0; + $item['total_normal_count'] = 0; + break; + case AGENT_STATUS_UNKNOWN: + $item['total_count'] = $item['total_unknown_count']; + + $item['total_critical_count'] = 0; + $item['total_warning_count'] = 0; + $item['total_not_init_count'] = 0; + $item['total_normal_count'] = 0; + break; + case AGENT_STATUS_NORMAL: + $item['total_count'] = $item['total_normal_count']; + + $item['total_unknown_count'] = 0; + $item['total_critical_count'] = 0; + $item['total_warning_count'] = 0; + $item['total_not_init_count'] = 0; + break; + } + } } @@ -1320,25 +1366,33 @@ class Tree { // Realtime counters for Strict ACL if ($this->strictACL) { + $agent_filter = array("id" => $agent['id']); + $module_filter = array(); + + if (isset($this->filter["statusModule"])) + $module_filter["status"] = $this->filter["statusModule"]; + if (isset($this->filter["searchModule"])) + $module_filter["name"] = $this->filter["searchModule"]; + if ($agent['rootType'] == "group") { $agent['counters'] = array(); - $agent['counters']['unknown'] = agents_monitor_unknown($agent['id']); - $agent['counters']['critical'] = agents_monitor_critical($agent['id']); - $agent['counters']['warning'] = agents_monitor_warning($agent['id']); - $agent['counters']['not_init'] = agents_monitor_notinit($agent['id']); - $agent['counters']['ok'] = agents_monitor_ok($agent['id']); - $agent['counters']['total'] = agents_monitor_total($agent['id']); + $agent['counters']['unknown'] = (int) groups_get_unknown_monitors ($agent['rootID'], $agent_filter, $module_filter, true, $this->acltags); + $agent['counters']['critical'] = (int) groups_get_critical_monitors ($agent['rootID'], $agent_filter, $module_filter, true, $this->acltags); + $agent['counters']['warning'] = (int) groups_get_warning_monitors ($agent['rootID'], $agent_filter, $module_filter, true, $this->acltags); + $agent['counters']['not_init'] = (int) groups_get_not_init_monitors ($agent['rootID'], $agent_filter, $module_filter, true, $this->acltags); + $agent['counters']['ok'] = (int) groups_get_normal_monitors ($agent['rootID'], $agent_filter, $module_filter, true, $this->acltags); + $agent['counters']['total'] = (int) groups_get_total_monitors ($agent['rootID'], $agent_filter, $module_filter, true, $this->acltags); $agent['counters']['alerts'] = agents_get_alerts_fired($agent['id']); } else if ($agent['rootType'] == "tag") { $agent['counters'] = array(); - $agent['counters']['unknown'] = tags_monitors_unknown($agent['rootID'], $this->acltags, $agent['id']); - $agent['counters']['critical'] = tags_monitors_critical($agent['rootID'], $this->acltags, $agent['id']); - $agent['counters']['warning'] = tags_monitors_warning($agent['rootID'], $this->acltags, $agent['id']); - $agent['counters']['not_init'] = tags_monitors_not_init($agent['rootID'], $this->acltags, $agent['id']); - $agent['counters']['ok'] = tags_monitors_normal($agent['rootID'], $this->acltags, $agent['id']); - $agent['counters']['total'] = tags_monitors_total($agent['rootID'], $this->acltags, $agent['id']); - $agent['counters']['alerts'] = tags_monitors_fired_alerts($agent['rootID'], $this->acltags, $agent['id']); + $agent['counters']['unknown'] = (int) tags_get_unknown_monitors($agent['rootID'], $this->acltags, $agent_filter, $module_filter); + $agent['counters']['critical'] = (int) tags_get_critical_monitors($agent['rootID'], $this->acltags, $agent_filter, $module_filter); + $agent['counters']['warning'] = (int) tags_get_warning_monitors($agent['rootID'], $this->acltags, $agent_filter, $module_filter); + $agent['counters']['not_init'] = (int) tags_get_not_init_monitors($agent['rootID'], $this->acltags, $agent_filter, $module_filter); + $agent['counters']['ok'] = (int) tags_get_normal_monitors($agent['rootID'], $this->acltags, $agent_filter, $module_filter); + $agent['counters']['total'] = (int) tags_get_total_monitors($agent['rootID'], $this->acltags, $agent_filter, $module_filter); + $agent['counters']['alerts'] = (int) tags_monitors_fired_alerts($agent['rootID'], $this->acltags, $agent['id']); } } @@ -1580,8 +1634,20 @@ class Tree { // Groups and tags if ($this->id == -1) { + $agent_filter = array(); + if (isset($this->filter["statusAgent"])) + $agent_filter["status"] = $this->filter["statusAgent"]; + if (isset($this->filter["searchAgent"])) + $agent_filter["name"] = $this->filter["searchAgent"]; + + $module_filter = array(); + if (isset($this->filter["statusModule"])) + $module_filter["status"] = $this->filter["statusModule"]; + if (isset($this->filter["searchModule"])) + $module_filter["name"] = $this->filter["searchModule"]; + if (! defined ('METACONSOLE')) { - $items = group_get_data($config['id_user'], $this->strictACL, $this->acltags, false, 'tree'); + $items = group_get_data($config['id_user'], $this->strictACL, $this->acltags, false, 'tree', $agent_filter, $module_filter); // Build the group and tag hierarchy $processed_items = array(); @@ -1612,7 +1678,7 @@ class Tree { continue; db_clean_cache(); - $items = group_get_data($config['id_user'], $this->strictACL, $this->acltags, false, 'tree'); + $items = group_get_data($config['id_user'], $this->strictACL, $this->acltags, false, 'tree', $agent_filter, $module_filter); // Build the group and tag hierarchy $processed_items = array(); diff --git a/pandora_console/include/functions_groups.php b/pandora_console/include/functions_groups.php index 13fde48eae..ac0aa4e541 100644 --- a/pandora_console/include/functions_groups.php +++ b/pandora_console/include/functions_groups.php @@ -1140,327 +1140,622 @@ function groups_create_group($group_name, $rest_values){ return $result; } -// Get agents NOT INIT - -function groups_agent_not_init ($group_array, $strict_user = false, $id_group_strict = false) { +/** + * Get the number of the agents that pass the filters. + * + * @param mixed $group Id in integer or a set of ids into an array. + * @param array $agent_filter Filter of the agents. + * This filter support the following fields: + * -'status': (mixed) Agent status. Single or grouped into an array. e.g.: AGENT_STATUS_CRITICAL. + * -'name': (string) Agent name. e.g.: "agent_1". + * @param array $module_filter Filter of the modules. + * This filter support the following fields: + * -'status': (mixed) Module status. Single or grouped into an array. e.g.: AGENT_MODULE_STATUS_CRITICAL. + * -'name': (string) Module name. e.g.: "module_1". + * @param bool $strict_user If the user has enabled the strict ACL mode or not. + * @param array $groups_and_tags Array with strict ACL rules. + * @param bool $realtime Search realtime values or the values processed by the server. + * + * @return int Number of agents. + * + */ +function groups_get_agents_counter ($group, $agent_filter = array(), $module_filter = array(), $strict_user = false, $groups_and_tags = false, $realtime = false) { - // If there are not groups to query, we jump to nextone - - if (empty ($group_array)) { + if (empty($group)) { 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) { - $tags_clause = " AND tagente.id_agente IN ( - SELECT id_agente - FROM tagente_modulo - WHERE id_agente_modulo NOT IN ( - SELECT id_agente_modulo - FROM ttag_module))"; - - $sql = " - SELECT COUNT(*) - FROM tagente - WHERE tagente.disabled = 0 - AND id_grupo = $id_group_strict - AND critical_count = 0 - AND warning_count = 0 - AND unknown_count = 0 - AND normal_count = 0 - AND (notinit_count > 0 OR total_count = 0) - $tags_clause"; - - $count = db_get_sql ($sql); + else if (is_array($group)) { + $groups = $group; } else { - $count = db_get_sql (" - SELECT COUNT(*) - FROM tagente - WHERE disabled = 0 - AND critical_count = 0 - AND warning_count = 0 - AND unknown_count = 0 - AND normal_count = 0 - AND (notinit_count > 0 OR total_count = 0) - AND id_grupo IN $group_clause"); + $groups = array($group); } - return $count > 0 ? $count : 0; -} + $group_str = implode (",", $groups); + $groups_clause = "AND ta.id_grupo IN ($group_str)"; - -// Get unknown agents by using the status code in modules. - -function groups_agent_unknown ($group_array, $strict_user = false, $id_group_strict = false) { - - if (empty ($group_array)) { - return 0; - } - else if (!is_array ($group_array)) { - $group_array = array($group_array); + $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) )))"; + } + } } - $group_clause = implode (",", $group_array); - $group_clause = "(" . $group_clause . ")"; - - if ($strict_user) { - $tags_clause = " AND tagente.id_agente IN (SELECT id_agente FROM tagente_modulo - WHERE id_agente_modulo NOT IN (SELECT id_agente_modulo FROM ttag_module))"; - $sql = "SELECT COUNT(*) FROM tagente WHERE tagente.disabled=0 - AND id_grupo=$id_group_strict - AND critical_count=0 - AND warning_count=0 AND unknown_count>0 - $tags_clause"; - - $count = db_get_sql ($sql); - } else { - $count = db_get_sql ("SELECT COUNT(*) FROM tagente WHERE tagente.disabled=0 AND critical_count=0 AND warning_count=0 AND unknown_count>0 AND id_grupo IN $group_clause"); + $agent_name_filter = ""; + $agent_status = AGENT_STATUS_ALL; + if (!empty($agent_filter)) { + // Name + if (isset($agent_filter["name"]) && !empty($agent_filter["name"])) { + $agent_name_filter = "AND ta.nombre LIKE '%" . $agent_filter["name"] . "%'"; + } + // Status + if (isset($agent_filter["status"])) { + if (is_array($agent_filter["status"])) + $agent_status = array_unique($agent_filter["status"]); + else + $agent_status = $agent_filter["status"]; + } } - return $count > 0 ? $count : 0; -} - -function groups_agent_total($group_array, $strict_user = false, $id_group_strict = false) { - - 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) { - $tags_clause = " AND ta.id_agente IN (SELECT id_agente FROM tagente_modulo - WHERE id_agente_modulo NOT IN (SELECT id_agente_modulo FROM ttag_module))"; - $sql = "SELECT COUNT(ta.id_agente) - FROM tagente AS ta - WHERE ta.disabled = 0 - AND ta.id_grupo = ".$id_group_strict . - $tags_clause; - - $count = db_get_sql($sql); - - } else { - $sql = "SELECT COUNT(ta.id_agente) - FROM tagente AS ta - WHERE ta.disabled = 0 - AND ta.id_grupo IN $group_clause"; - - $count = db_get_sql($sql); - } - - return $count > 0 ? $count : 0; -} - -// Get ok agents by using the status code in modules. - -function groups_agent_ok ($group_array, $strict_user = false, $id_group_strict = false) { - - if (empty ($group_array)) { - return 0; + $module_name_filter = ""; + $module_status_filter = ""; + if (!empty($module_filter)) { + // IMPORTANT: The module filters will force the realtime search + $realtime = true; - } - else if (!is_array ($group_array)) { - $group_array = array($group_array); + // Name + if (isset($module_filter["name"]) && !empty($module_filter["name"])) { + $module_name_filter = "AND tam.nombre LIKE '%" . $module_filter["name"] . "%'"; + } + // Status + if (isset($module_filter["status"])) { + $module_status = $module_filter["status"]; + if (is_array($module_status)) + $module_status = array_unique($module_status); + else + $module_status = array($module_status); + + $status_array = ""; + foreach ($module_status as $status) { + switch ($status) { + case AGENT_MODULE_STATUS_ALL: + $status_array[] = AGENT_MODULE_STATUS_CRITICAL_ALERT; + $status_array[] = AGENT_MODULE_STATUS_CRITICAL_BAD; + $status_array[] = AGENT_MODULE_STATUS_WARNING_ALERT; + $status_array[] = AGENT_MODULE_STATUS_WARNING; + $status_array[] = AGENT_MODULE_STATUS_UNKNOWN; + $status_array[] = AGENT_MODULE_STATUS_NO_DATA; + $status_array[] = AGENT_MODULE_STATUS_NOT_INIT; + $status_array[] = AGENT_MODULE_STATUS_NORMAL_ALERT; + $status_array[] = AGENT_MODULE_STATUS_NORMAL; + break; + case AGENT_MODULE_STATUS_CRITICAL_ALERT: + case AGENT_MODULE_STATUS_CRITICAL_BAD: + $status_array[] = AGENT_MODULE_STATUS_CRITICAL_ALERT; + $status_array[] = AGENT_MODULE_STATUS_CRITICAL_BAD; + break; + case AGENT_MODULE_STATUS_WARNING_ALERT: + case AGENT_MODULE_STATUS_WARNING: + $status_array[] = AGENT_MODULE_STATUS_WARNING_ALERT; + $status_array[] = AGENT_MODULE_STATUS_WARNING; + break; + case AGENT_MODULE_STATUS_UNKNOWN: + $status_array[] = AGENT_MODULE_STATUS_UNKNOWN; + break; + case AGENT_MODULE_STATUS_NO_DATA: + case AGENT_MODULE_STATUS_NOT_INIT: + $status_array[] = AGENT_MODULE_STATUS_NO_DATA; + $status_array[] = AGENT_MODULE_STATUS_NOT_INIT; + break; + case AGENT_MODULE_STATUS_NORMAL_ALERT: + case AGENT_MODULE_STATUS_NORMAL: + $status_array[] = AGENT_MODULE_STATUS_NORMAL_ALERT; + $status_array[] = AGENT_MODULE_STATUS_NORMAL; + break; + } + } + if (!empty($status_array)) { + $status_array = array_unique($status_array); + $status_str = implode(",", $status_array); + + $module_status_filter = "INNER JOIN tagente_estado AS tae + ON tam.id_agente_modulo = tae.id_agente_modulo + AND tae.estado IN ($status_str)"; + } + } } - $group_clause = implode (",", $group_array); - $group_clause = "($group_clause)"; - - if ($strict_user) { - $tags_clause = " AND ta.id_agente IN (SELECT id_agente - FROM tagente_modulo - WHERE id_agente_modulo NOT IN (SELECT id_agente_modulo FROM ttag_module))"; - $sql = "SELECT COUNT(ta.id_agente) + $count = 0; + // Realtime + if ($realtime) { + $sql = "SELECT DISTINCT ta.id_agente FROM tagente AS ta - WHERE ta.disabled = 0 - AND ta.id_grupo = $id_group_strict - AND ta.critical_count = 0 - AND ta.warning_count = 0 - AND ta.unknown_count = 0 - AND ta.normal_count > 0 + INNER JOIN tagente_modulo AS tam + ON ta.id_agente = tam.id_agente + AND tam.disabled = 0 + $module_name_filter + $module_status_filter + WHERE ta.disabled = 0 + $agent_name_filter + $groups_clause $tags_clause"; + $agents = db_get_all_rows_sql($sql); - $count = db_get_sql ($sql); - } else { - $sql = "SELECT COUNT(ta.id_agente) - FROM tagente AS ta - WHERE ta.disabled = 0 - AND ta.critical_count = 0 - AND ta.warning_count = 0 - AND ta.unknown_count = 0 - AND ta.normal_count > 0 - AND ta.id_grupo IN $group_clause"; + if ($agents === false) + return $count; - $count = db_get_sql ($sql); - } + if ($agent_status == AGENT_STATUS_ALL) + return count($agents); - return $count > 0 ? $count : 0; + foreach ($agents as $agent) { + $agent_filter["id"] = $agent["id"]; + $total = (int) groups_get_total_monitors ($group, $agent_filter, $module_filter, $strict_user, $groups_and_tags, $realtime); + $critical = (int) groups_get_critical_monitors ($group, $agent_filter, $module_filter, $strict_user, $groups_and_tags, $realtime); + $warning = (int) groups_get_warning_monitors ($group, $agent_filter, $module_filter, $strict_user, $groups_and_tags, $realtime); + $unknown = (int) groups_get_unknown_monitors ($group, $agent_filter, $module_filter, $strict_user, $groups_and_tags, $realtime); + $not_init = (int) groups_get_not_init_monitors ($group, $agent_filter, $module_filter, $strict_user, $groups_and_tags, $realtime); + $normal = (int) groups_get_normal_monitors ($group, $agent_filter, $module_filter, $strict_user, $groups_and_tags, $realtime); + + if (!is_array($agent_status)) { + switch ($agent_status) { + case AGENT_STATUS_CRITICAL: + if ($critical > 0) + $count ++; + break; + case AGENT_STATUS_WARNING: + if ($total > 0 && $critical = 0 && $warning > 0) + $count ++; + break; + case AGENT_STATUS_UNKNOWN: + if ($critical == 0 && $warning == 0 && $unknown > 0) + $count ++; + break; + case AGENT_STATUS_NOT_INIT: + if ($total == 0 || $total == $not_init) + $count ++; + break; + case AGENT_STATUS_NORMAL: + if ($critical == 0 && $warning == 0 && $unknown == 0 && $normal > 0) + $count ++; + break; + default: + // The status doesn't exist + return 0; + } + } + else { + if (array_search(AGENT_STATUS_CRITICAL, $agent_status) !== false) { + if ($critical > 0) + $count ++; + } + else if (array_search(AGENT_STATUS_WARNING, $agent_status) !== false) { + if ($total > 0 && $critical = 0 && $warning > 0) + $count ++; + } + else if (array_search(AGENT_STATUS_UNKNOWN, $agent_status) !== false) { + if ($critical == 0 && $warning == 0 && $unknown > 0) + $count ++; + } + else if (array_search(AGENT_STATUS_NOT_INIT, $agent_status) !== false) { + if ($total == 0 || $total == $not_init) + $count ++; + } + else if (array_search(AGENT_STATUS_NORMAL, $agent_status) !== false) { + if ($critical == 0 && $warning == 0 && $unknown == 0 && $normal > 0) + $count ++; + } + // Invalid status + else { + return 0; + } + } + } + } + // Server processed + else { + $status_filter = ""; + // Transform the element into a one element array + if (!is_array($agent_status)) + $agent_status = array($agent_status); + + // Support for multiple status. It counts the agents for each status and sum the result + foreach ($agent_status as $status) { + switch ($agent_status) { + case AGENT_STATUS_ALL: + $status_filter = ""; + break; + case AGENT_STATUS_CRITICAL: + $status_filter = "AND ta.critical_count > 0"; + break; + case AGENT_STATUS_WARNING: + $status_filter = "AND ta.total_count > 0 + AND ta.critical_count = 0 + AND ta.warning_count > 0"; + break; + case AGENT_STATUS_UNKNOWN: + $status_filter = "AND ta.critical_count = 0 + AND ta.warning_count = 0 + AND ta.unknown_count > 0"; + break; + case AGENT_STATUS_NOT_INIT: + $status_filter = "AND (ta.total_count = 0 + OR ta.total_count = ta.notinit_count)"; + break; + case AGENT_STATUS_NORMAL: + $status_filter = "AND ta.critical_count = 0 + AND ta.warning_count = 0 + AND ta.unknown_count = 0 + AND ta.normal_count > 0"; + break; + default: + // The type doesn't exist + return 0; + } + + $sql = "SELECT COUNT(DISTINCT ta.id_agente) + FROM tagente AS ta + WHERE ta.disabled = 0 + $agent_name_filter + $status_filter + $groups_clause"; + + $res = db_get_sql($sql); + if ($res !== false) + $count += $res; + } + } + + return $count; } -// Get critical agents by using the status code in modules. - -function groups_agent_critical ($group_array, $strict_user = false, $id_group_strict = false) { - - 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)"; - - //TODO REVIEW ORACLE AND POSTGRES - - if ($strict_user) { - $tags_clause = " AND ta.id_agente IN (SELECT id_agente FROM tagente_modulo - WHERE id_agente_modulo NOT IN (SELECT id_agente_modulo FROM ttag_module))"; - $sql = "SELECT COUNT(ta.id_agente) - FROM tagente AS ta - WHERE ta.disabled = 0 - AND ta.id_grupo = $id_group_strict - AND ta.critical_count > 0 - $tags_clause"; - - $count = db_get_sql ($sql); - } else { - $sql = "SELECT COUNT(ta.id_agente) - FROM tagente AS ta - WHERE ta.disabled = 0 - AND ta.critical_count > 0 - AND ta.id_grupo IN $group_clause"; - - $count = db_get_sql ($sql); - } - - return $count > 0 ? $count : 0; +/** + * Get the number of the agents that pass the filters. + * + * @param mixed $group Id in integer or a set of ids into an array. + * @param array $agent_filter Filter of the agents. + * This filter support the following fields: + * -'name': (string) Agent name. e.g.: "agent_1". + * @param array $module_filter Filter of the modules. + * This filter support the following fields: + * -'status': (mixed) Module status. Single or grouped into an array. e.g.: AGENT_MODULE_STATUS_CRITICAL. + * -'name': (string) Module name. e.g.: "module_1". + * @param bool $strict_user If the user has enabled the strict ACL mode or not. + * @param array $groups_and_tags Array with strict ACL rules. + * @param bool $realtime Search realtime values or the values processed by the server. + * + * @return int Number of agents. + * + */ +function groups_get_total_agents ($group, $agent_filter = array(), $module_filter = array(), $strict_user = false, $groups_and_tags = false, $realtime = false) { + // Always modify the agent status filter + $agent_filter["status"] = AGENT_STATUS_ALL; + return groups_get_agents_counter($group, $agent_filter, $module_filter, $strict_user, $groups_and_tags, $realtime); } -// Get warning agents by using the status code in modules. - -function groups_agent_warning ($group_array, $strict_user = false, $id_group_strict = false) { - - 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) { - $tags_clause = " AND ta.id_agente IN (SELECT id_agente FROM tagente_modulo - WHERE id_agente_modulo NOT IN (SELECT id_agente_modulo FROM ttag_module))"; - $sql = "SELECT COUNT(ta.id_agente) - FROM tagente AS ta - WHERE ta.disabled = 0 - AND ta.id_grupo = $id_group_strict - AND ta.critical_count = 0 - AND ta.warning_count > 0 - $tags_clause"; - - $count = db_get_sql ($sql); - } else { - $sql = "SELECT COUNT(ta.id_agente) - FROM tagente AS ta - WHERE ta.disabled = 0 - AND ta.critical_count = 0 - AND ta.warning_count > 0 - AND ta.id_grupo IN $group_clause"; - - $count = db_get_sql ($sql); - } - - return $count > 0 ? $count : 0; +/** + * Get the number of the normal agents that pass the filters. + * + * @param mixed $group Id in integer or a set of ids into an array. + * @param array $agent_filter Filter of the agents. + * This filter support the following fields: + * -'name': (string) Agent name. e.g.: "agent_1". + * @param array $module_filter Filter of the modules. + * This filter support the following fields: + * -'status': (mixed) Module status. Single or grouped into an array. e.g.: AGENT_MODULE_STATUS_CRITICAL. + * -'name': (string) Module name. e.g.: "module_1". + * @param bool $strict_user If the user has enabled the strict ACL mode or not. + * @param array $groups_and_tags Array with strict ACL rules. + * @param bool $realtime Search realtime values or the values processed by the server. + * + * @return int Number of agents. + * + */ +function groups_get_normal_agents ($group, $agent_filter = array(), $module_filter = array(), $strict_user = false, $groups_and_tags = false, $realtime = false) { + // Always modify the agent status filter + $agent_filter["status"] = AGENT_STATUS_NORMAL; + return groups_get_agents_counter($group, $agent_filter, $module_filter, $strict_user, $groups_and_tags, $realtime); } +/** + * Get the number of the critical agents that pass the filters. + * + * @param mixed $group Id in integer or a set of ids into an array. + * @param array $agent_filter Filter of the agents. + * This filter support the following fields: + * -'name': (string) Agent name. e.g.: "agent_1". + * @param array $module_filter Filter of the modules. + * This filter support the following fields: + * -'status': (mixed) Module status. Single or grouped into an array. e.g.: AGENT_MODULE_STATUS_CRITICAL. + * -'name': (string) Module name. e.g.: "module_1". + * @param bool $strict_user If the user has enabled the strict ACL mode or not. + * @param array $groups_and_tags Array with strict ACL rules. + * @param bool $realtime Search realtime values or the values processed by the server. + * + * @return int Number of agents. + * + */ +function groups_get_critical_agents ($group, $agent_filter = array(), $module_filter = array(), $strict_user = false, $groups_and_tags = false, $realtime = false) { + // Always modify the agent status filter + $agent_filter["status"] = AGENT_STATUS_CRITICAL; + return groups_get_agents_counter($group, $agent_filter, $module_filter, $strict_user, $groups_and_tags, $realtime); +} -function groups_monitors_count ($type, $group_array, $strict_user = false, $id_group_strict = false) { +/** + * Get the number of the warning agents that pass the filters. + * + * @param mixed $group Id in integer or a set of ids into an array. + * @param array $agent_filter Filter of the agents. + * This filter support the following fields: + * -'name': (string) Agent name. e.g.: "agent_1". + * @param array $module_filter Filter of the modules. + * This filter support the following fields: + * -'status': (mixed) Module status. Single or grouped into an array. e.g.: AGENT_MODULE_STATUS_CRITICAL. + * -'name': (string) Module name. e.g.: "module_1". + * @param bool $strict_user If the user has enabled the strict ACL mode or not. + * @param array $groups_and_tags Array with strict ACL rules. + * @param bool $realtime Search realtime values or the values processed by the server. + * + * @return int Number of agents. + * + */ +function groups_get_warning_agents ($group, $agent_filter = array(), $module_filter = array(), $strict_user = false, $groups_and_tags = false, $realtime = false) { + // Always modify the agent status filter + $agent_filter["status"] = AGENT_STATUS_WARNING; + return groups_get_agents_counter($group, $agent_filter, $module_filter, $strict_user, $groups_and_tags, $realtime); +} + +/** + * Get the number of the unknown agents that pass the filters. + * + * @param mixed $group Id in integer or a set of ids into an array. + * @param array $agent_filter Filter of the agents. + * This filter support the following fields: + * -'name': (string) Agent name. e.g.: "agent_1". + * @param array $module_filter Filter of the modules. + * This filter support the following fields: + * -'status': (mixed) Module status. Single or grouped into an array. e.g.: AGENT_MODULE_STATUS_CRITICAL. + * -'name': (string) Module name. e.g.: "module_1". + * @param bool $strict_user If the user has enabled the strict ACL mode or not. + * @param array $groups_and_tags Array with strict ACL rules. + * @param bool $realtime Search realtime values or the values processed by the server. + * + * @return int Number of agents. + * + */ +function groups_get_unknown_agents ($group, $agent_filter = array(), $module_filter = array(), $strict_user = false, $groups_and_tags = false, $realtime = false) { + // Always modify the agent status filter + $agent_filter["status"] = AGENT_STATUS_UNKNOWN; + return groups_get_agents_counter($group, $agent_filter, $module_filter, $strict_user, $groups_and_tags, $realtime); +} + +/** + * Get the number of the not init agents that pass the filters. + * + * @param mixed $group Id in integer or a set of ids into an array. + * @param array $agent_filter Filter of the agents. + * This filter support the following fields: + * -'name': (string) Agent name. e.g.: "agent_1". + * @param array $module_filter Filter of the modules. + * This filter support the following fields: + * -'status': (mixed) Module status. Single or grouped into an array. e.g.: AGENT_MODULE_STATUS_CRITICAL. + * -'name': (string) Module name. e.g.: "module_1". + * @param bool $strict_user If the user has enabled the strict ACL mode or not. + * @param array $groups_and_tags Array with strict ACL rules. + * @param bool $realtime Search realtime values or the values processed by the server. + * + * @return int Number of agents. + * + */ +function groups_get_not_init_agents ($group, $agent_filter = array(), $module_filter = array(), $strict_user = false, $groups_and_tags = false, $realtime = false) { + // Always modify the agent status filter + $agent_filter["status"] = AGENT_STATUS_NOT_INIT; + return groups_get_agents_counter($group, $agent_filter, $module_filter, $strict_user, $groups_and_tags, $realtime); +} + +/** + * Get the number of the monitors that pass the filters. + * + * @param mixed $group Id in integer or a set of ids into an array. + * @param array $agent_filter Filter of the agents. + * This filter support the following fields: + * -'name': (string) Agent name. e.g.: "agent_1". + * -'id': (mixed) Agent id. e.g.: "1". + * @param array $module_filter Filter of the modules. + * This filter support the following fields: + * -'status': (mixed) Module status. Single or grouped into an array. e.g.: AGENT_MODULE_STATUS_CRITICAL. + * -'name': (string) Module name. e.g.: "module_1". + * @param bool $strict_user If the user has enabled the strict ACL mode or not. + * @param array $groups_and_tags Array with strict ACL rules. + * @param bool $realtime Search realtime values or the values processed by the server. + * + * @return int Number of monitors. + * + */ +function groups_get_monitors_counter ($group, $agent_filter = array(), $module_filter = array(), $strict_user = false, $groups_and_tags = false, $realtime = false) { - // If there are not groups to query, we jump to nextone - if (empty ($group_array)) { + if (empty($group)) { return 0; } - else if (!is_array ($group_array)) { - $group_array = array($group_array); + else if (is_array($group)) { + $groups = $group; } - - $group_clause = implode (",", $group_array); - $group_clause = "($group_clause)"; - - switch ($type) { - case AGENT_MODULE_STATUS_CRITICAL_ALERT: - case AGENT_MODULE_STATUS_CRITICAL_BAD: - if ($strict_user) - $status = AGENT_MODULE_STATUS_CRITICAL_ALERT.",".AGENT_MODULE_STATUS_CRITICAL_BAD; - else - $status = 'critical_count'; - break; - case AGENT_MODULE_STATUS_WARNING_ALERT: - case AGENT_MODULE_STATUS_WARNING: - if ($strict_user) - $status = AGENT_MODULE_STATUS_WARNING_ALERT.",".AGENT_MODULE_STATUS_WARNING; - else - $status = 'warning_count'; - break; - case AGENT_MODULE_STATUS_UNKNOWN: - if ($strict_user) - $status = AGENT_MODULE_STATUS_UNKNOWN; - else - $status = 'unknown_count'; - break; - case AGENT_MODULE_STATUS_NO_DATA: - case AGENT_MODULE_STATUS_NOT_INIT: - if ($strict_user) - $status = AGENT_MODULE_STATUS_NO_DATA.",".AGENT_MODULE_STATUS_NOT_INIT; - else - $status = 'notinit_count'; - break; - case AGENT_MODULE_STATUS_NORMAL_ALERT: - case AGENT_MODULE_STATUS_NORMAL: - if ($strict_user) - $status = AGENT_MODULE_STATUS_NORMAL_ALERT.",".AGENT_MODULE_STATUS_NORMAL; - else - $status = 'normal_count'; - break; - default: - // The type doesn't exist - return; + else { + $groups = array($group); } if ($strict_user) { + $realtime = true; + } + + $group_str = implode (",", $groups); + $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 = ""; + $agents_clause = ""; + if (!empty($agent_filter)) { + // Name + if (isset($agent_filter["name"]) && !empty($agent_filter["name"])) { + $agent_name_filter = "AND ta.nombre LIKE '%" . $agent_filter["name"] . "%'"; + } + // ID + if (isset($agent_filter["id"])) { + if (is_array($agent_filter["id"])) + $agents = array_unique($agent_filter["id"]); + else + $agents = array($agent_filter["id"]); + $agents_str = implode (",", $agents); + $agents_clause = "AND ta.id_agente IN ($agents_str)"; + } + } + + + $module_name_filter = ""; + $module_status_array = ""; + $modules_clause = ""; + if (!empty($module_filter)) { + + // Name + if (isset($module_filter["name"]) && !empty($module_filter["name"])) { + // IMPORTANT: The module filters will force the realtime search + $realtime = true; + + $module_name_filter = "AND tam.nombre LIKE '%" . $module_filter["name"] . "%'"; + } + // Status + if (isset($module_filter["status"])) { + if (is_array($module_filter["status"])) + $module_status = array_unique($module_filter["status"]); + else + $module_status = array($module_filter["status"]); + + $status_array = ""; + foreach ($module_status as $status) { + switch ($status) { + case AGENT_MODULE_STATUS_ALL: + $status_array[] = AGENT_MODULE_STATUS_CRITICAL_ALERT; + $status_array[] = AGENT_MODULE_STATUS_CRITICAL_BAD; + $status_array[] = AGENT_MODULE_STATUS_WARNING_ALERT; + $status_array[] = AGENT_MODULE_STATUS_WARNING; + $status_array[] = AGENT_MODULE_STATUS_UNKNOWN; + $status_array[] = AGENT_MODULE_STATUS_NO_DATA; + $status_array[] = AGENT_MODULE_STATUS_NOT_INIT; + $status_array[] = AGENT_MODULE_STATUS_NORMAL_ALERT; + $status_array[] = AGENT_MODULE_STATUS_NORMAL; + break; + case AGENT_MODULE_STATUS_CRITICAL_ALERT: + case AGENT_MODULE_STATUS_CRITICAL_BAD: + $status_array[] = AGENT_MODULE_STATUS_CRITICAL_ALERT; + $status_array[] = AGENT_MODULE_STATUS_CRITICAL_BAD; + break; + case AGENT_MODULE_STATUS_WARNING_ALERT: + case AGENT_MODULE_STATUS_WARNING: + $status_array[] = AGENT_MODULE_STATUS_WARNING_ALERT; + $status_array[] = AGENT_MODULE_STATUS_WARNING; + break; + case AGENT_MODULE_STATUS_UNKNOWN: + $status_array[] = AGENT_MODULE_STATUS_UNKNOWN; + break; + case AGENT_MODULE_STATUS_NO_DATA: + case AGENT_MODULE_STATUS_NOT_INIT: + $status_array[] = AGENT_MODULE_STATUS_NO_DATA; + $status_array[] = AGENT_MODULE_STATUS_NOT_INIT; + break; + case AGENT_MODULE_STATUS_NORMAL_ALERT: + case AGENT_MODULE_STATUS_NORMAL: + $status_array[] = AGENT_MODULE_STATUS_NORMAL_ALERT; + $status_array[] = AGENT_MODULE_STATUS_NORMAL; + break; + default: + // The status doesn't exist + return 0; + } + } + if (!empty($status_array)) { + $status_array = array_unique($status_array); + $status_str = implode(",", $status_array); + + $modules_clause = "AND tae.estado IN ($status_str)"; + } + } + } + + if ($realtime) { $sql = "SELECT COUNT(DISTINCT tam.id_agente_modulo) FROM tagente_modulo AS tam INNER JOIN tagente_estado AS tae ON tam.id_agente_modulo = tae.id_agente_modulo - AND tae.estado IN ($status) + $modules_clause INNER JOIN tagente AS ta ON tam.id_agente = ta.id_agente AND ta.disabled = 0 - AND ta.id_grupo = $id_group_strict - WHERE tam.disabled = 0"; + $agent_name_filter + $agents_clause + $groups_clause + WHERE tam.disabled = 0 + $module_name_filter + $tags_clause"; } else { - $sql = "SELECT SUM($status) - FROM tagente - WHERE disabled = 0 - AND id_grupo IN $group_clause"; + $status_columns_array = array(); + foreach ($module_status_array as $status) { + switch ($status) { + case AGENT_MODULE_STATUS_CRITICAL_ALERT: + case AGENT_MODULE_STATUS_CRITICAL_BAD: + $status_columns_array = 'ta.critical_count'; + break; + case AGENT_MODULE_STATUS_WARNING_ALERT: + case AGENT_MODULE_STATUS_WARNING: + $status_columns_array = 'ta.warning_count'; + break; + case AGENT_MODULE_STATUS_UNKNOWN: + $status_columns_array = 'ta.unknown_count'; + break; + case AGENT_MODULE_STATUS_NO_DATA: + case AGENT_MODULE_STATUS_NOT_INIT: + $status_columns_array = 'ta.notinit_count'; + break; + case AGENT_MODULE_STATUS_NORMAL_ALERT: + case AGENT_MODULE_STATUS_NORMAL: + $status_columns_array = 'ta.normal_count'; + break; + default: + // The type doesn't exist + return 0; + } + } + if (empty($status_columns_array)) + return 0; + + $status_columns_str = implode(",", $status_columns_array); + + $sql = "SELECT SUM($status_columns_str) + FROM tagente AS ta + WHERE ta.disabled = 0 + $agent_name_filter + $agents_clause + $groups_clause + $tags_clause"; } $count = (int) db_get_sql ($sql); @@ -1468,29 +1763,148 @@ function groups_monitors_count ($type, $group_array, $strict_user = false, $id_g return $count; } -// Get monitor NOT INIT, except disabled AND async modules -function groups_monitor_not_init ($group_array, $strict_user = false, $id_group_strict = false) { - return groups_monitors_count (AGENT_MODULE_STATUS_NOT_INIT, $group_array, $strict_user, $id_group_strict); +/** + * Get the number of the monitors that pass the filters. + * + * @param mixed $group Id in integer or a set of ids into an array. + * @param array $agent_filter Filter of the agents. + * This filter support the following fields: + * -'name': (string) Agent name. e.g.: "agent_1". + * -'id': (int/array) Agent id. e.g.: "1". + * @param array $module_filter Filter of the modules. + * This filter support the following fields: + * -'name': (string) Module name. e.g.: "module_1". + * @param bool $strict_user If the user has enabled the strict ACL mode or not. + * @param array $groups_and_tags Array with strict ACL rules. + * @param bool $realtime Search realtime values or the values processed by the server. + * + * @return int Number of monitors. + * + */ +function groups_get_total_monitors ($group, $agent_filter = array(), $module_filter = array(), $strict_user = false, $groups_and_tags = false, $realtime = false) { + // Always modify the module status filter + $module_filter["status"] = AGENT_MODULE_STATUS_ALL; + return groups_get_monitors_counter($group, $agent_filter, $module_filter, $strict_user, $groups_and_tags, $realtime); } -// Get monitor OK, except disabled and non-init -function groups_monitor_ok ($group_array, $strict_user = false, $id_group_strict = false) { - return groups_monitors_count (AGENT_MODULE_STATUS_NORMAL, $group_array, $strict_user, $id_group_strict); +/** + * Get the number of the normal monitors that pass the filters. + * + * @param mixed $group Id in integer or a set of ids into an array. + * @param array $agent_filter Filter of the agents. + * This filter support the following fields: + * -'name': (string) Agent name. e.g.: "agent_1". + * -'id': (int/array) Agent id. e.g.: "1". + * @param array $module_filter Filter of the modules. + * This filter support the following fields: + * -'name': (string) Module name. e.g.: "module_1". + * @param bool $strict_user If the user has enabled the strict ACL mode or not. + * @param array $groups_and_tags Array with strict ACL rules. + * @param bool $realtime Search realtime values or the values processed by the server. + * + * @return int Number of monitors. + * + */ +function groups_get_normal_monitors ($group, $agent_filter = array(), $module_filter = array(), $strict_user = false, $groups_and_tags = false, $realtime = false) { + // Always modify the module status filter + $module_filter["status"] = AGENT_MODULE_STATUS_NORMAL; + return groups_get_monitors_counter($group, $agent_filter, $module_filter, $strict_user, $groups_and_tags, $realtime); } -// Get monitor CRITICAL, except disabled and non-init -function groups_monitor_critical ($group_array, $strict_user = false, $id_group_strict = false) { - return groups_monitors_count (AGENT_MODULE_STATUS_CRITICAL_BAD, $group_array, $strict_user, $id_group_strict); +/** + * Get the number of the critical monitors that pass the filters. + * + * @param mixed $group Id in integer or a set of ids into an array. + * @param array $agent_filter Filter of the agents. + * This filter support the following fields: + * -'name': (string) Agent name. e.g.: "agent_1". + * -'id': (int/array) Agent id. e.g.: "1". + * @param array $module_filter Filter of the modules. + * This filter support the following fields: + * -'name': (string) Module name. e.g.: "module_1". + * @param bool $strict_user If the user has enabled the strict ACL mode or not. + * @param array $groups_and_tags Array with strict ACL rules. + * @param bool $realtime Search realtime values or the values processed by the server. + * + * @return int Number of monitors. + * + */ +function groups_get_critical_monitors ($group, $agent_filter = array(), $module_filter = array(), $strict_user = false, $groups_and_tags = false, $realtime = false) { + // Always modify the module status filter + $module_filter["status"] = AGENT_MODULE_STATUS_CRITICAL_BAD; + return groups_get_monitors_counter($group, $agent_filter, $module_filter, $strict_user, $groups_and_tags, $realtime); } -// Get monitor WARNING, except disabled and non-init -function groups_monitor_warning ($group_array, $strict_user = false, $id_group_strict = false) { - return groups_monitors_count (AGENT_MODULE_STATUS_WARNING, $group_array, $strict_user, $id_group_strict); +/** + * Get the number of the warning monitors that pass the filters. + * + * @param mixed $group Id in integer or a set of ids into an array. + * @param array $agent_filter Filter of the agents. + * This filter support the following fields: + * -'name': (string) Agent name. e.g.: "agent_1". + * -'id': (int/array) Agent id. e.g.: "1". + * @param array $module_filter Filter of the modules. + * This filter support the following fields: + * -'name': (string) Module name. e.g.: "module_1". + * @param bool $strict_user If the user has enabled the strict ACL mode or not. + * @param array $groups_and_tags Array with strict ACL rules. + * @param bool $realtime Search realtime values or the values processed by the server. + * + * @return int Number of monitors. + * + */ +function groups_get_warning_monitors ($group, $agent_filter = array(), $module_filter = array(), $strict_user = false, $groups_and_tags = false, $realtime = false) { + // Always modify the module status filter + $module_filter["status"] = AGENT_MODULE_STATUS_WARNING; + return groups_get_monitors_counter($group, $agent_filter, $module_filter, $strict_user, $groups_and_tags, $realtime); } -// Get monitor UNKNOWN, except disabled and non-init -function groups_monitor_unknown ($group_array, $strict_user = false, $id_group_strict = false) { - return groups_monitors_count (AGENT_MODULE_STATUS_UNKNOWN, $group_array, $strict_user, $id_group_strict); +/** + * Get the number of the unknown monitors that pass the filters. + * + * @param mixed $group Id in integer or a set of ids into an array. + * @param array $agent_filter Filter of the agents. + * This filter support the following fields: + * -'name': (string) Agent name. e.g.: "agent_1". + * -'id': (int/array) Agent id. e.g.: "1". + * @param array $module_filter Filter of the modules. + * This filter support the following fields: + * -'name': (string) Module name. e.g.: "module_1". + * @param bool $strict_user If the user has enabled the strict ACL mode or not. + * @param array $groups_and_tags Array with strict ACL rules. + * @param bool $realtime Search realtime values or the values processed by the server. + * + * @return int Number of monitors. + * + */ +function groups_get_unknown_monitors ($group, $agent_filter = array(), $module_filter = array(), $strict_user = false, $groups_and_tags = false, $realtime = false) { + // Always modify the module status filter + $module_filter["status"] = AGENT_MODULE_STATUS_UNKNOWN; + return groups_get_monitors_counter($group, $agent_filter, $module_filter, $strict_user, $groups_and_tags, $realtime); +} + +/** + * Get the number of the not init monitors that pass the filters. + * + * @param mixed $group Id in integer or a set of ids into an array. + * @param array $agent_filter Filter of the agents. + * This filter support the following fields: + * -'name': (string) Agent name. e.g.: "agent_1". + * -'id': (int/array) Agent id. e.g.: "1". + * @param array $module_filter Filter of the modules. + * This filter support the following fields: + * -'name': (string) Module name. e.g.: "module_1". + * @param bool $strict_user If the user has enabled the strict ACL mode or not. + * @param array $groups_and_tags Array with strict ACL rules. + * @param bool $realtime Search realtime values or the values processed by the server. + * + * @return int Number of monitors. + * + */ +function groups_get_not_init_monitors ($group, $agent_filter = array(), $module_filter = array(), $strict_user = false, $groups_and_tags = false, $realtime = false) { + // Always modify the module status filter + $module_filter["status"] = AGENT_MODULE_STATUS_NOT_INIT; + return groups_get_monitors_counter($group, $agent_filter, $module_filter, $strict_user, $groups_and_tags, $realtime); } // Get alerts defined for a given group, except disabled @@ -1802,7 +2216,7 @@ function groups_get_all_hierarchy_group ($id_group, $hierarchy = array()) { return $hierarchy; } -function group_get_data ($id_user = false, $user_strict = false, $acltags, $returnAllGroup = false, $mode = 'group') { +function group_get_data ($id_user = false, $user_strict = false, $acltags, $returnAllGroup = false, $mode = 'group', $agent_filter = array(), $module_filter = array()) { global $config; if ($id_user == false) { $id_user = $config['id_user']; @@ -1913,12 +2327,12 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu $list[$i]['_total_agents_'] = $group_stat[0]["agents"]; // This fields are not in database - $list[$i]['_monitors_ok_'] = groups_monitor_ok($id, $user_strict, $id); - $list[$i]['_monitors_critical_'] = groups_monitor_critical($id, $user_strict, $id); - $list[$i]['_monitors_warning_'] = groups_monitor_warning($id, $user_strict, $id); - $list[$i]['_monitors_unknown_'] = groups_monitor_unknown($id, $user_strict, $id); - $list[$i]['_monitors_not_init_'] = groups_monitor_not_init($id, $user_strict, $id); - $list[$i]['_agents_not_init_'] = groups_agent_not_init ($id, $user_strict, $id); + $list[$i]['_monitors_ok_'] = (int) groups_get_normal_monitors($id); + $list[$i]['_monitors_critical_'] = (int) groups_get_critical_monitors($id); + $list[$i]['_monitors_warning_'] = (int) groups_get_warning_monitors($id); + $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"]; @@ -2017,20 +2431,20 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu if ($mode == 'tree' && !empty($item['parent'])) $list[$i]['_parent_id_'] = $item['parent']; - $list[$i]['_monitors_ok_'] = groups_monitor_ok($id, $user_strict, $id); - $list[$i]['_monitors_critical_'] = groups_monitor_critical($id, $user_strict, $id); - $list[$i]['_monitors_warning_'] = groups_monitor_warning($id, $user_strict, $id); - $list[$i]['_agents_unknown_'] = groups_agent_unknown ($id, $user_strict, $id); + $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"]); + $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]['_total_agents_'] = groups_agent_total ($id, $user_strict, $id); - $list[$i]['_monitors_unknown_'] = groups_monitor_unknown($id, $user_strict, $id); - $list[$i]['_monitors_not_init_'] = groups_monitor_not_init($id, $user_strict, $id); - $list[$i]['_agents_not_init_'] = groups_agent_not_init ($id, $user_strict, $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"]); if ($mode == 'tactical' || $mode == 'tree') { - $list[$i]['_agents_ok_'] = groups_agent_ok ($id, $user_strict, $id); - $list[$i]['_agents_warning_'] = groups_agent_warning ($id, $user_strict, $id); - $list[$i]['_agents_critical_'] = groups_agent_critical ($id, $user_strict, $id); + $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 @@ -2125,20 +2539,20 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu $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_'] = tags_get_total_agents ($id, $acltags); - $list[$i]['_agents_unknown_'] = tags_get_unknown_agents ($id, $acltags); - $list[$i]['_agents_not_init_'] = tags_get_not_init_agents ($id, $acltags); - $list[$i]['_monitors_ok_'] = tags_monitors_normal ($id, $acltags); - $list[$i]['_monitors_critical_'] = tags_monitors_critical ($id, $acltags); - $list[$i]['_monitors_warning_'] = tags_monitors_warning ($id, $acltags); - $list[$i]['_monitors_not_init_'] = tags_monitors_not_init ($id, $acltags); - $list[$i]['_monitors_unknown_'] = tags_monitors_unknown ($id, $acltags); + $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_'] = tags_get_normal_agents ($id, $acltags); - $list[$i]['_agents_warning_'] = tags_get_warning_agents ($id, $acltags); - $list[$i]['_agents_critical_'] = tags_get_critical_agents ($id, $acltags); + $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') { diff --git a/pandora_console/include/functions_networkmap.php b/pandora_console/include/functions_networkmap.php index 73fcb995c4..005f8f3274 100644 --- a/pandora_console/include/functions_networkmap.php +++ b/pandora_console/include/functions_networkmap.php @@ -1023,12 +1023,16 @@ function networkmap_create_agent_node ($agent, $simple = 0, $font_size = 10, $cu global $hack_networkmap_mobile; if ($strict_user) { - $strict_data['normal_count'] = groups_agent_ok ($agent['id_grupo'], $strict_user, $agent['id_grupo']); - $strict_data['warning_count'] = groups_agent_warning ($agent['id_grupo'], $strict_user, $agent['id_grupo']); - $strict_data['critical_count'] = groups_agent_critical ($agent['id_grupo'], $strict_user, $agent['id_grupo']); - $strict_data['unknown_count'] = groups_agent_unknown ($agent['id_grupo'], $strict_user, $agent['id_grupo']); - $strict_data['notinit_count'] = groups_agent_not_init ($agent['id_grupo'], $strict_user, $agent['id_grupo']); - $strict_data['total_count'] = groups_agent_total ($agent['id_grupo'], $strict_user, $agent['id_grupo']); + require_once($config['homedir']."/include/functions_tags.php"); + $acltags = tags_get_user_module_and_tags ($config["id_user"], 'AR', $strict_user); + + $agent_filter = array("id" => $agent["id_agente"]); + $strict_data['normal_count'] = (int) groups_get_normal_monitors ($agent['id_grupo'], $agent_filter, array(), $strict_user, $acltags); + $strict_data['warning_count'] = (int) groups_get_warning_monitors ($agent['id_grupo'], $agent_filter, array(), $strict_user, $acltags); + $strict_data['critical_count'] = (int) groups_get_critical_monitors ($agent['id_grupo'], $agent_filter, array(), $strict_user, $acltags); + $strict_data['unknown_count'] = (int) groups_get_unknown_monitors ($agent['id_grupo'], $agent_filter, array(), $strict_user, $acltags); + $strict_data['notinit_count'] = (int) groups_get_not_init_monitors ($agent['id_grupo'], $agent_filter, array(), $strict_user, $acltags); + $strict_data['total_count'] = (int) groups_get_total_monitors ($agent['id_grupo'], $agent_filter, array(), $strict_user, $acltags); $status = agents_get_status_from_counts($strict_data); } else { $status = agents_get_status_from_counts($agent); diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index a65b940701..a67ab69379 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -1873,11 +1873,11 @@ function reporting_get_group_stats ($id_group = 0, $access = 'AR') { $data["utimestamp"] = $group_stat[0]["utimestamp"]; // This fields are not in database - $data["monitor_ok"] += groups_monitor_ok($group); - $data["monitor_warning"] += groups_monitor_warning($group); - $data["monitor_critical"] += groups_monitor_critical($group); - $data["monitor_unknown"] += groups_monitor_unknown($group); - $data["monitor_not_init"] += groups_monitor_not_init($group); + $data["monitor_ok"] += (int) groups_get_normal_monitors($group); + $data["monitor_warning"] += (int) groups_get_warning_monitors($group); + $data["monitor_critical"] += (int) groups_get_critical_monitors($group); + $data["monitor_unknown"] += (int) groups_get_unknown_monitors($group); + $data["monitor_not_init"] += (int) groups_get_not_init_monitors($group); } // ------------------------------------------------------------------- @@ -1940,23 +1940,20 @@ function reporting_get_group_stats ($id_group = 0, $access = 'AR') { */ if (!empty($group_array)) { - // Get unknown agents by using the status code in modules - $data["agents_unknown"] += groups_agent_unknown ($group_array); - // Get monitor NOT INIT, except disabled AND async modules - $data["monitor_not_init"] += groups_monitor_not_init ($group_array); + $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"] += groups_monitor_ok ($group_array); + $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"] += groups_monitor_critical ($group_array); + $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"] += groups_monitor_warning ($group_array); + $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"] += groups_monitor_unknown ($group_array); + $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) ; @@ -1966,26 +1963,26 @@ function reporting_get_group_stats ($id_group = 0, $access = 'AR') { // Calculate totals using partial counts from above - // Get TOTAL agents in a group - $data["total_agents"] += groups_total_agents ($group_array); - // 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"] += groups_agent_ok($group_array); + $data["agent_ok"] += (int) groups_get_normal_agents ($group_array, array(), array(), false, false, true); // Get Agents Warning - $data["agent_warning"] += groups_agent_warning($group_array); + $data["agent_warning"] += (int) groups_get_warning_agents ($group_array, array(), array(), false, false, true); // Get Agents Critical - $data["agent_critical"] += groups_agent_critical($group_array); + $data["agent_critical"] += (int) groups_get_critical_agents ($group_array, array(), array(), false, false, true); // Get Agents Unknown - $data["agent_unknown"] += groups_agent_unknown($group_array); + $data["agent_unknown"] += (int) groups_get_unknown_agents ($group_array, array(), array(), false, false, true); // Get Agents Not init - $data["agent_not_init"] += groups_agent_not_init($group_array); + $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. diff --git a/pandora_console/include/functions_tags.php b/pandora_console/include/functions_tags.php index da2b31cfb5..31fb766ea8 100644 --- a/pandora_console/include/functions_tags.php +++ b/pandora_console/include/functions_tags.php @@ -1264,17 +1264,24 @@ function tags_checks_event_acl($id_user, $id_group, $access, $tags = array(), $c } /** - * Get the agents counters by filtering by id_tag. - * - * @param int $type Type of the status to filter the counter. - * @param int $id_tag Id of the tag to filter the modules. + * Get the number of the agents that pass the filters. + * + * @param mixed $id_tag Id in integer or a set of ids into an array. * @param array $groups_and_tags Array with strict ACL rules. - * @param mixed $id_agent Id or ids of the agent to filter the modules. - * @param bool $realtime Realime or preprocessed (realtime is slower). + * @param array $agent_filter Filter of the agents. + * This filter support the following fields: + * -'status': (mixed) Agent status. Single or grouped into an array. e.g.: AGENT_STATUS_CRITICAL. + * -'name': (string) Agent name. e.g.: "agent_1". + * @param array $module_filter Filter of the modules. + * This filter support the following fields: + * -'status': (mixed) Module status. Single or grouped into an array. e.g.: AGENT_MODULE_STATUS_CRITICAL. + * -'name': (string) Module name. e.g.: "module_1". + * @param bool $realtime Search realtime values or the values processed by the server. + * + * @return int Number of monitors. * - * @return mixed Returns count of agents of the selected status or false on error. */ -function tags_get_agents_counter ($type, $id_tag, $groups_and_tags = array(), $id_agent = false, $realtime = true) { +function tags_get_agents_counter ($id_tag, $groups_and_tags = array(), $agent_filter = array(), $module_filter = array(), $realtime = true) { // Avoid mysql error if (empty($id_tag)) @@ -1296,15 +1303,94 @@ function tags_get_agents_counter ($type, $id_tag, $groups_and_tags = array(), $i } } if (array_search(0, $groups_id) === false) { + $groups_id = array_unique($groups_id); $groups_id_str = implode(",", $groups_id); $groups_clause = " AND ta.id_grupo IN ($groups_id_str)"; } } - $agents_clause = ""; - if ($id_agent !== false) { - if (is_array($id_agent)) - $id_agent = implode(",", $id_agent); - $agents_clause = " AND ta.id_agente IN ($id_agent)"; + + $agent_name_filter = ""; + $agent_status = AGENT_STATUS_ALL; + if (!empty($agent_filter)) { + // Name + if (isset($agent_filter["name"]) && !empty($agent_filter["name"])) { + $agent_name_filter = "AND ta.nombre LIKE '%" . $agent_filter["name"] . "%'"; + } + // Status + if (isset($agent_filter["status"])) { + if (is_array($agent_filter["status"])) + $agent_status = array_unique($agent_filter["status"]); + else + $agent_status = $agent_filter["status"]; + } + } + + $module_name_filter = ""; + $module_status_filter = ""; + if (!empty($module_filter)) { + // IMPORTANT: The module filters will force the realtime search + $realtime = true; + + // Name + if (isset($module_filter["name"]) && !empty($module_filter["name"])) { + $module_name_filter = "AND tam.nombre LIKE '%" . $module_filter["name"] . "%'"; + } + // Status + if (isset($module_filter["status"])) { + $module_status = $module_filter["status"]; + if (is_array($module_status)) + $module_status = array_unique($module_status); + else + $module_status = array($module_status); + + $status_array = ""; + foreach ($module_status as $status) { + switch ($status) { + case AGENT_MODULE_STATUS_ALL: + $status_array[] = AGENT_MODULE_STATUS_CRITICAL_ALERT; + $status_array[] = AGENT_MODULE_STATUS_CRITICAL_BAD; + $status_array[] = AGENT_MODULE_STATUS_WARNING_ALERT; + $status_array[] = AGENT_MODULE_STATUS_WARNING; + $status_array[] = AGENT_MODULE_STATUS_UNKNOWN; + $status_array[] = AGENT_MODULE_STATUS_NO_DATA; + $status_array[] = AGENT_MODULE_STATUS_NOT_INIT; + $status_array[] = AGENT_MODULE_STATUS_NORMAL_ALERT; + $status_array[] = AGENT_MODULE_STATUS_NORMAL; + break; + case AGENT_MODULE_STATUS_CRITICAL_ALERT: + case AGENT_MODULE_STATUS_CRITICAL_BAD: + $status_array[] = AGENT_MODULE_STATUS_CRITICAL_ALERT; + $status_array[] = AGENT_MODULE_STATUS_CRITICAL_BAD; + break; + case AGENT_MODULE_STATUS_WARNING_ALERT: + case AGENT_MODULE_STATUS_WARNING: + $status_array[] = AGENT_MODULE_STATUS_WARNING_ALERT; + $status_array[] = AGENT_MODULE_STATUS_WARNING; + break; + case AGENT_MODULE_STATUS_UNKNOWN: + $status_array[] = AGENT_MODULE_STATUS_UNKNOWN; + break; + case AGENT_MODULE_STATUS_NO_DATA: + case AGENT_MODULE_STATUS_NOT_INIT: + $status_array[] = AGENT_MODULE_STATUS_NO_DATA; + $status_array[] = AGENT_MODULE_STATUS_NOT_INIT; + break; + case AGENT_MODULE_STATUS_NORMAL_ALERT: + case AGENT_MODULE_STATUS_NORMAL: + $status_array[] = AGENT_MODULE_STATUS_NORMAL_ALERT; + $status_array[] = AGENT_MODULE_STATUS_NORMAL; + break; + } + } + if (!empty($status_array)) { + $status_array = array_unique($status_array); + $status_str = implode(",", $status_array); + + $module_status_filter = "INNER JOIN tagente_estado AS tae + ON tam.id_agente_modulo = tae.id_agente_modulo + AND tae.estado IN ($status_str)"; + } + } } $count = 0; @@ -1314,191 +1400,304 @@ function tags_get_agents_counter ($type, $id_tag, $groups_and_tags = array(), $i INNER JOIN tagente_modulo AS tam ON ta.id_agente = tam.id_agente AND tam.disabled = 0 + $module_name_filter + $module_status_filter INNER JOIN ttag_module AS ttm ON ttm.id_tag = $id_tag AND tam.id_agente_modulo = ttm.id_agente_modulo WHERE ta.disabled = 0 - $agents_clause + $agent_name_filter $groups_clause"; $agents = db_get_all_rows_sql($sql); if ($agents === false) - return false; + return $count; - if ($type == AGENT_STATUS_ALL) + if ($agent_status == AGENT_STATUS_ALL) return count($agents); foreach ($agents as $agent) { - $total = (int) tags_monitors_total($id_tag, $groups_and_tags, $agent['id_agente']); - $critical = (int) tags_monitors_critical($id_tag, $groups_and_tags, $agent['id_agente']); - $warning = (int) tags_monitors_warning($id_tag, $groups_and_tags, $agent['id_agente']); - $unknown = (int) tags_monitors_unknown($id_tag, $groups_and_tags, $agent['id_agente']); - $not_init = (int) tags_monitors_not_init($id_tag, $groups_and_tags, $agent['id_agente']); - $normal = (int) tags_monitors_normal($id_tag, $groups_and_tags, $agent['id_agente']); + $agent_filter["id"] = $agent["id"]; + $total = (int) tags_get_total_monitors ($id_tag, $groups_and_tags, $agent_filter, $module_filter); + $critical = (int) tags_get_critical_monitors ($id_tag, $groups_and_tags, $agent_filter, $module_filter); + $warning = (int) tags_get_warning_monitors ($id_tag, $groups_and_tags, $agent_filter, $module_filter); + $unknown = (int) tags_get_unknown_monitors ($id_tag, $groups_and_tags, $agent_filter, $module_filter); + $not_init = (int) tags_get_not_init_monitors ($id_tag, $groups_and_tags, $agent_filter, $module_filter); + $normal = (int) tags_get_normal_monitors ($id_tag, $groups_and_tags, $agent_filter, $module_filter); - switch ($type) { - case AGENT_STATUS_CRITICAL: + if (!is_array($agent_status)) { + switch ($agent_status) { + case AGENT_STATUS_CRITICAL: + if ($critical > 0) + $count ++; + break; + case AGENT_STATUS_WARNING: + if ($total > 0 && $critical = 0 && $warning > 0) + $count ++; + break; + case AGENT_STATUS_UNKNOWN: + if ($critical == 0 && $warning == 0 && $unknown > 0) + $count ++; + break; + case AGENT_STATUS_NOT_INIT: + if ($total == 0 || $total == $not_init) + $count ++; + break; + case AGENT_STATUS_NORMAL: + if ($critical == 0 && $warning == 0 && $unknown == 0 && $normal > 0) + $count ++; + break; + default: + // The status doesn't exist + return 0; + } + } + else { + if (array_search(AGENT_STATUS_CRITICAL, $agent_status) !== false) { if ($critical > 0) $count ++; - break; - case AGENT_STATUS_WARNING: + } + else if (array_search(AGENT_STATUS_WARNING, $agent_status) !== false) { if ($total > 0 && $critical = 0 && $warning > 0) $count ++; - break; - case AGENT_STATUS_UNKNOWN: + } + else if (array_search(AGENT_STATUS_UNKNOWN, $agent_status) !== false) { if ($critical == 0 && $warning == 0 && $unknown > 0) $count ++; - break; - case AGENT_STATUS_NOT_INIT: + } + else if (array_search(AGENT_STATUS_NOT_INIT, $agent_status) !== false) { if ($total == 0 || $total == $not_init) $count ++; - break; - case AGENT_STATUS_NORMAL: + } + else if (array_search(AGENT_STATUS_NORMAL, $agent_status) !== false) { if ($critical == 0 && $warning == 0 && $unknown == 0 && $normal > 0) $count ++; - break; - default: - // The type doesn't exist - return false; + } + // Invalid status + else { + return 0; + } } } } else { $status_filter = ""; - switch ($type) { - case AGENT_STATUS_ALL: - $status_filter = ""; - break; - case AGENT_STATUS_CRITICAL: - $status_filter = "AND ta.critical_count > 0"; - break; - case AGENT_STATUS_WARNING: - $status_filter = "AND ta.total_count > 0 - AND ta.critical_count = 0 - AND ta.warning_count > 0"; - break; - case AGENT_STATUS_UNKNOWN: - $status_filter = "AND ta.critical_count = 0 - AND ta.warning_count = 0 - AND ta.unknown_count > 0"; - break; - case AGENT_STATUS_NOT_INIT: - $status_filter = "AND (ta.total_count = 0 - OR ta.total_count = ta.notinit_count)"; - break; - case AGENT_STATUS_NORMAL: - $status_filter = "AND ta.critical_count = 0 - AND ta.warning_count = 0 - AND ta.unknown_count = 0 - AND ta.normal_count > 0"; - break; - default: - // The type doesn't exist - return false; - } + // Transform the element into a one element array + if (!is_array($agent_status)) + $agent_status = array($agent_status); - $sql = "SELECT COUNT(DISTINCT ta.id_agente) - FROM tagente AS ta - INNER JOIN tagente_modulo AS tam - ON ta.id_agente = tam.id_agente - AND tam.disabled = 0 - INNER JOIN ttag_module AS ttm - ON ttm.id_tag = $id_tag - AND tam.id_agente_modulo = ttm.id_agente_modulo - WHERE ta.disabled = 0 - $status_filter - $agents_clause - $groups_clause"; - - $count = db_get_sql($sql); + // Support for multiple status. It counts the agents for each status and sum the result + foreach ($agent_status as $status) { + switch ($agent_status) { + case AGENT_STATUS_ALL: + $status_filter = ""; + break; + case AGENT_STATUS_CRITICAL: + $status_filter = "AND ta.critical_count > 0"; + break; + case AGENT_STATUS_WARNING: + $status_filter = "AND ta.total_count > 0 + AND ta.critical_count = 0 + AND ta.warning_count > 0"; + break; + case AGENT_STATUS_UNKNOWN: + $status_filter = "AND ta.critical_count = 0 + AND ta.warning_count = 0 + AND ta.unknown_count > 0"; + break; + case AGENT_STATUS_NOT_INIT: + $status_filter = "AND (ta.total_count = 0 + OR ta.total_count = ta.notinit_count)"; + break; + case AGENT_STATUS_NORMAL: + $status_filter = "AND ta.critical_count = 0 + AND ta.warning_count = 0 + AND ta.unknown_count = 0 + AND ta.normal_count > 0"; + break; + default: + // The type doesn't exist + return 0; + } + + $sql = "SELECT COUNT(DISTINCT ta.id_agente) + FROM tagente AS ta + INNER JOIN tagente_modulo AS tam + ON ta.id_agente = tam.id_agente + AND tam.disabled = 0 + $module_name_filter + $module_status_filter + INNER JOIN ttag_module AS ttm + ON ttm.id_tag = $id_tag + AND tam.id_agente_modulo = ttm.id_agente_modulo + WHERE ta.disabled = 0 + $status_filter + $agent_name_filter + $groups_clause"; + + $count += (int) db_get_sql($sql); + } } return $count; } /** - * Get total agents filtering by id_tag. - * - * @param int $id_tag Id of the tag to search total agents. + * Get the number of the agents that pass the filters. + * + * @param mixed $id_tag Id in integer or a set of ids into an array. * @param array $groups_and_tags Array with strict ACL rules. + * @param array $agent_filter Filter of the agents. + * This filter support the following fields: + * -'name': (string) Agent name. e.g.: "agent_1". + * @param array $module_filter Filter of the modules. + * This filter support the following fields: + * -'status': (mixed) Module status. Single or grouped into an array. e.g.: AGENT_MODULE_STATUS_CRITICAL. + * -'name': (string) Module name. e.g.: "module_1". + * @param bool $realtime Search realtime values or the values processed by the server. + * + * @return int Number of monitors. * - * @return mixed Returns count of agents with this tag or false if they aren't. */ -function tags_get_total_agents ($id_tag, $groups_and_tags = array()) { - return tags_get_agents_counter(AGENT_STATUS_ALL, $id_tag, $groups_and_tags); -} - - /** - * Get normal agents by using the status code in modules by filtering by id_tag. - * - * @param int $id_tag Id of the tag to search normal agents. - * @param array $groups_and_tags Array with strict ACL rules. - * - * @return mixed Returns count of agents in normal status or false if they aren't. - */ -function tags_get_normal_agents ($id_tag, $groups_and_tags = array()) { - return tags_get_agents_counter(AGENT_STATUS_NORMAL, $id_tag, $groups_and_tags); -} - - /** - * Get warning agents by using the status code in modules by filtering by id_tag. - * - * @param int $id_tag Id of the tag to search warning agents. - * @param array $groups_and_tags Array with strict ACL rules. - * - * @return mixed Returns count of agents in warning status or false if they aren't. - */ -function tags_get_warning_agents ($id_tag, $groups_and_tags = array()) { - return tags_get_agents_counter(AGENT_STATUS_WARNING, $id_tag, $groups_and_tags); +function tags_get_total_agents ($id_tag, $groups_and_tags = array(), $agent_filter = array(), $module_filter = array(), $realtime = true) { + // Always modify the agent status filter + $agent_filter["status"] = AGENT_STATUS_ALL; + return tags_get_agents_counter($id_tag, $groups_and_tags, $agent_filter, $module_filter, $realtime); } /** - * Get unknown agents filtering by id_tag. - * - * @param int $id_tag Id of the tag to search unknown agents. + * Get the number of the normal agents that pass the filters. + * + * @param mixed $id_tag Id in integer or a set of ids into an array. * @param array $groups_and_tags Array with strict ACL rules. + * @param array $agent_filter Filter of the agents. + * This filter support the following fields: + * -'name': (string) Agent name. e.g.: "agent_1". + * @param array $module_filter Filter of the modules. + * This filter support the following fields: + * -'status': (mixed) Module status. Single or grouped into an array. e.g.: AGENT_MODULE_STATUS_CRITICAL. + * -'name': (string) Module name. e.g.: "module_1". + * @param bool $realtime Search realtime values or the values processed by the server. + * + * @return int Number of monitors. * - * @return mixed Returns count of unknown agents with this tag or false if they aren't. */ -function tags_get_critical_agents ($id_tag, $groups_and_tags = array()) { - return tags_get_agents_counter(AGENT_STATUS_CRITICAL, $id_tag, $groups_and_tags); +function tags_get_normal_agents ($id_tag, $groups_and_tags = array(), $agent_filter = array(), $module_filter = array(), $realtime = true) { + // Always modify the agent status filter + $agent_filter["status"] = AGENT_STATUS_NORMAL; + return tags_get_agents_counter($id_tag, $groups_and_tags, $agent_filter, $module_filter, $realtime); } /** - * Get unknown agents filtering by id_tag. - * - * @param int $id_tag Id of the tag to search unknown agents. + * Get the number of the warning agents that pass the filters. + * + * @param mixed $id_tag Id in integer or a set of ids into an array. * @param array $groups_and_tags Array with strict ACL rules. + * @param array $agent_filter Filter of the agents. + * This filter support the following fields: + * -'name': (string) Agent name. e.g.: "agent_1". + * @param array $module_filter Filter of the modules. + * This filter support the following fields: + * -'status': (mixed) Module status. Single or grouped into an array. e.g.: AGENT_MODULE_STATUS_CRITICAL. + * -'name': (string) Module name. e.g.: "module_1". + * @param bool $realtime Search realtime values or the values processed by the server. + * + * @return int Number of monitors. * - * @return mixed Returns count of unknown agents with this tag or false if they aren't. */ -function tags_get_unknown_agents ($id_tag, $groups_and_tags = array()) { - return tags_get_agents_counter(AGENT_STATUS_UNKNOWN, $id_tag, $groups_and_tags); +function tags_get_warning_agents ($id_tag, $groups_and_tags = array(), $agent_filter = array(), $module_filter = array(), $realtime = true) { + // Always modify the agent status filter + $agent_filter["status"] = AGENT_STATUS_WARNING; + return tags_get_agents_counter($id_tag, $groups_and_tags, $agent_filter, $module_filter, $realtime); } /** - * Get not init agents filtering by id_tag. - * - * @param int $id_tag Id of the tag to search not init agents. + * Get the number of the critical agents that pass the filters. + * + * @param mixed $id_tag Id in integer or a set of ids into an array. * @param array $groups_and_tags Array with strict ACL rules. + * @param array $agent_filter Filter of the agents. + * This filter support the following fields: + * -'name': (string) Agent name. e.g.: "agent_1". + * @param array $module_filter Filter of the modules. + * This filter support the following fields: + * -'status': (mixed) Module status. Single or grouped into an array. e.g.: AGENT_MODULE_STATUS_CRITICAL. + * -'name': (string) Module name. e.g.: "module_1". + * @param bool $realtime Search realtime values or the values processed by the server. + * + * @return int Number of monitors. * - * @return mixed Returns count of not init agents with this tag or false if they aren't. */ -function tags_get_not_init_agents ($id_tag, $groups_and_tags = array()) { - return tags_get_agents_counter(AGENT_STATUS_NOT_INIT, $id_tag, $groups_and_tags); +function tags_get_critical_agents ($id_tag, $groups_and_tags = array(), $agent_filter = array(), $module_filter = array(), $realtime = true) { + // Always modify the agent status filter + $agent_filter["status"] = AGENT_STATUS_CRITICAL; + return tags_get_agents_counter($id_tag, $groups_and_tags, $agent_filter, $module_filter, $realtime); } /** - * Get the monitors count. - * - * @param int $type Type of the status to filter the counter. - * @param int $id_tag Id of the tag to filter the modules. + * Get the number of the unknown agents that pass the filters. + * + * @param mixed $id_tag Id in integer or a set of ids into an array. * @param array $groups_and_tags Array with strict ACL rules. - * @param mixed $id_agente Id or ids of the agent to filter the modules. + * @param array $agent_filter Filter of the agents. + * This filter support the following fields: + * -'name': (string) Agent name. e.g.: "agent_1". + * @param array $module_filter Filter of the modules. + * This filter support the following fields: + * -'status': (mixed) Module status. Single or grouped into an array. e.g.: AGENT_MODULE_STATUS_CRITICAL. + * -'name': (string) Module name. e.g.: "module_1". + * @param bool $realtime Search realtime values or the values processed by the server. + * + * @return int Number of monitors. * - * @return mixed Returns the count of the modules or false on error. */ -function tags_monitors_count ($type, $id_tag, $groups_and_tags = array(), $id_agente = false) { +function tags_get_unknown_agents ($id_tag, $groups_and_tags = array(), $agent_filter = array(), $module_filter = array(), $realtime = true) { + // Always modify the agent status filter + $agent_filter["status"] = AGENT_STATUS_UNKNOWN; + return tags_get_agents_counter($id_tag, $groups_and_tags, $agent_filter, $module_filter, $realtime); +} + +/** + * Get the number of the not init agents that pass the filters. + * + * @param mixed $id_tag Id in integer or a set of ids into an array. + * @param array $groups_and_tags Array with strict ACL rules. + * @param array $agent_filter Filter of the agents. + * This filter support the following fields: + * -'name': (string) Agent name. e.g.: "agent_1". + * @param array $module_filter Filter of the modules. + * This filter support the following fields: + * -'status': (mixed) Module status. Single or grouped into an array. e.g.: AGENT_MODULE_STATUS_CRITICAL. + * -'name': (string) Module name. e.g.: "module_1". + * @param bool $realtime Search realtime values or the values processed by the server. + * + * @return int Number of monitors. + * + */ +function tags_get_not_init_agents ($id_tag, $groups_and_tags = array(), $agent_filter = array(), $module_filter = array(), $realtime = true) { + // Always modify the agent status filter + $agent_filter["status"] = AGENT_STATUS_NOT_INIT; + return tags_get_agents_counter($id_tag, $groups_and_tags, $agent_filter, $module_filter, $realtime); +} + +/** + * Get the number of the monitors that pass the filters. + * + * @param mixed $id_tag Id in integer or a set of ids into an array. + * @param array $groups_and_tags Array with strict ACL rules. + * @param array $agent_filter Filter of the agents. + * This filter support the following fields: + * -'name': (string) Agent name. e.g.: "agent_1". + * -'id': (mixed) Agent id. e.g.: "1". + * @param array $module_filter Filter of the modules. + * This filter support the following fields: + * -'status': (mixed) Module status. Single or grouped into an array. e.g.: AGENT_MODULE_STATUS_CRITICAL. + * -'name': (string) Module name. e.g.: "module_1". + * + * @return int Number of monitors. + * + */ +function tags_get_monitors_counter ($id_tag, $groups_and_tags = array(), $agent_filter = array(), $module_filter = array()) { // Avoid mysql error if (empty($id_tag)) @@ -1520,64 +1719,113 @@ function tags_monitors_count ($type, $id_tag, $groups_and_tags = array(), $id_ag } } if (array_search(0, $groups_id) === false) { + $groups_id = array_unique($groups_id); $groups_id_str = implode(",", $groups_id); $groups_clause = " AND ta.id_grupo IN ($groups_id_str)"; } } + + $agent_name_filter = ""; $agents_clause = ""; - if ($id_agente !== false) { - if (is_array($id_agente)) { - $id_agente = implode(",", $id_agente); + if (!empty($agent_filter)) { + // Name + if (isset($agent_filter["name"]) && !empty($agent_filter["name"])) { + $agent_name_filter = "AND ta.nombre LIKE '%" . $agent_filter["name"] . "%'"; + } + // ID + if (isset($agent_filter["id"])) { + if (is_array($agent_filter["id"])) + $agents = array_unique($agent_filter["id"]); + else + $agents = array($agent_filter["id"]); + $agents_str = implode (",", $agents); + $agents_clause = "AND ta.id_agente IN ($agents_str)"; } - $agents_clause = " AND ta.id_agente IN ($id_agente)"; } - - switch ($type) { - case AGENT_MODULE_STATUS_ALL: - $status = AGENT_MODULE_STATUS_CRITICAL_ALERT.",".AGENT_MODULE_STATUS_CRITICAL_BAD - . "," . AGENT_MODULE_STATUS_WARNING_ALERT.",".AGENT_MODULE_STATUS_WARNING - . "," . AGENT_MODULE_STATUS_UNKNOWN - . "," . AGENT_MODULE_STATUS_NO_DATA.",".AGENT_MODULE_STATUS_NOT_INIT - . "," . AGENT_MODULE_STATUS_NORMAL_ALERT.",".AGENT_MODULE_STATUS_NORMAL; - break; - case AGENT_MODULE_STATUS_CRITICAL_ALERT: - case AGENT_MODULE_STATUS_CRITICAL_BAD: - $status = AGENT_MODULE_STATUS_CRITICAL_ALERT.",".AGENT_MODULE_STATUS_CRITICAL_BAD; - break; - case AGENT_MODULE_STATUS_WARNING_ALERT: - case AGENT_MODULE_STATUS_WARNING: - $status = AGENT_MODULE_STATUS_WARNING_ALERT.",".AGENT_MODULE_STATUS_WARNING; - break; - case AGENT_MODULE_STATUS_UNKNOWN: - $status = AGENT_MODULE_STATUS_UNKNOWN; - break; - case AGENT_MODULE_STATUS_NO_DATA: - case AGENT_MODULE_STATUS_NOT_INIT: - $status = AGENT_MODULE_STATUS_NO_DATA.",".AGENT_MODULE_STATUS_NOT_INIT; - break; - case AGENT_MODULE_STATUS_NORMAL_ALERT: - case AGENT_MODULE_STATUS_NORMAL: - $status = AGENT_MODULE_STATUS_NORMAL_ALERT.",".AGENT_MODULE_STATUS_NORMAL; - break; - default: - // The type doesn't exist - return false; + + $module_name_filter = ""; + $module_status_array = ""; + $modules_clause = ""; + if (!empty($module_filter)) { + // Name + if (isset($module_filter["name"]) && !empty($module_filter["name"])) { + $module_name_filter = "AND tam.nombre LIKE '%" . $module_filter["name"] . "%'"; + } + // Status + if (isset($module_filter["status"])) { + $module_status = $module_filter["status"]; + if (is_array($module_status)) + $module_status = array_unique($module_status); + else + $module_status = array($module_status); + + $status_array = ""; + foreach ($module_status as $status) { + switch ($status) { + case AGENT_MODULE_STATUS_ALL: + $status_array[] = AGENT_MODULE_STATUS_CRITICAL_ALERT; + $status_array[] = AGENT_MODULE_STATUS_CRITICAL_BAD; + $status_array[] = AGENT_MODULE_STATUS_WARNING_ALERT; + $status_array[] = AGENT_MODULE_STATUS_WARNING; + $status_array[] = AGENT_MODULE_STATUS_UNKNOWN; + $status_array[] = AGENT_MODULE_STATUS_NO_DATA; + $status_array[] = AGENT_MODULE_STATUS_NOT_INIT; + $status_array[] = AGENT_MODULE_STATUS_NORMAL_ALERT; + $status_array[] = AGENT_MODULE_STATUS_NORMAL; + break; + case AGENT_MODULE_STATUS_CRITICAL_ALERT: + case AGENT_MODULE_STATUS_CRITICAL_BAD: + $status_array[] = AGENT_MODULE_STATUS_CRITICAL_ALERT; + $status_array[] = AGENT_MODULE_STATUS_CRITICAL_BAD; + break; + case AGENT_MODULE_STATUS_WARNING_ALERT: + case AGENT_MODULE_STATUS_WARNING: + $status_array[] = AGENT_MODULE_STATUS_WARNING_ALERT; + $status_array[] = AGENT_MODULE_STATUS_WARNING; + break; + case AGENT_MODULE_STATUS_UNKNOWN: + $status_array[] = AGENT_MODULE_STATUS_UNKNOWN; + break; + case AGENT_MODULE_STATUS_NO_DATA: + case AGENT_MODULE_STATUS_NOT_INIT: + $status_array[] = AGENT_MODULE_STATUS_NO_DATA; + $status_array[] = AGENT_MODULE_STATUS_NOT_INIT; + break; + case AGENT_MODULE_STATUS_NORMAL_ALERT: + case AGENT_MODULE_STATUS_NORMAL: + $status_array[] = AGENT_MODULE_STATUS_NORMAL_ALERT; + $status_array[] = AGENT_MODULE_STATUS_NORMAL; + break; + default: + // The status doesn't exist + return false; + } + } + if (!empty($status_array)) { + $status_array = array_unique($status_array); + $status_str = implode(",", $status_array); + + $modules_clause = "AND tae.estado IN ($status_str)"; + } + } } $sql = "SELECT COUNT(DISTINCT tam.id_agente_modulo) FROM tagente_modulo AS tam INNER JOIN tagente_estado AS tae ON tam.id_agente_modulo = tae.id_agente_modulo - AND tae.estado IN ($status) + $modules_clause INNER JOIN ttag_module AS ttm ON ttm.id_tag = $id_tag AND tam.id_agente_modulo = ttm.id_agente_modulo INNER JOIN tagente AS ta ON tam.id_agente = ta.id_agente AND ta.disabled = 0 + $agent_name_filter $agents_clause $groups_clause - WHERE tam.disabled = 0"; + WHERE tam.disabled = 0 + $module_name_filter"; $count = db_get_sql ($sql); @@ -1585,81 +1833,135 @@ function tags_monitors_count ($type, $id_tag, $groups_and_tags = array(), $id_ag } /** - * Get the total monitors count. - * - * @param int $id_tag Id of the tag to filter the modules. + * Get the number of the total monitors that pass the filters. + * + * @param mixed $id_tag Id in integer or a set of ids into an array. * @param array $groups_and_tags Array with strict ACL rules. - * @param mixed $id_agente Id or ids of the agent to filter the modules. + * @param array $agent_filter Filter of the agents. + * This filter support the following fields: + * -'id': (mixed) Agent id. e.g.: "1". + * @param array $module_filter Filter of the modules. + * This filter support the following fields: + * -'status': (mixed) Module status. Single or grouped into an array. e.g.: AGENT_MODULE_STATUS_CRITICAL. + * -'name': (string) Module name. e.g.: "module_1". + * + * @return int Number of monitors. * - * @return mixed Returns the count of the total modules or false on error. */ -function tags_monitors_total ($id_tag, $groups_and_tags = array(), $id_agente = false) { - return tags_monitors_count(AGENT_MODULE_STATUS_ALL, $id_tag, $groups_and_tags, $id_agente); +function tags_get_total_monitors ($id_tag, $groups_and_tags = array(), $agent_filter = array(), $module_filter = array()) { + // Always modify the module status filter + $module_filter["status"] = AGENT_MODULE_STATUS_ALL; + return tags_get_monitors_counter($id_tag, $groups_and_tags, $agent_filter, $module_filter); } /** - * Get the normal monitors count. - * - * @param int $id_tag Id of the tag to filter the modules. + * Get the number of the normal monitors that pass the filters. + * + * @param mixed $id_tag Id in integer or a set of ids into an array. * @param array $groups_and_tags Array with strict ACL rules. - * @param mixed $id_agente Id or ids of the agent to filter the modules. + * @param array $agent_filter Filter of the agents. + * This filter support the following fields: + * -'id': (mixed) Agent id. e.g.: "1". + * @param array $module_filter Filter of the modules. + * This filter support the following fields: + * -'status': (mixed) Module status. Single or grouped into an array. e.g.: AGENT_MODULE_STATUS_CRITICAL. + * -'name': (string) Module name. e.g.: "module_1". + * + * @return int Number of monitors. * - * @return mixed Returns the count of the normal modules or false on error. */ -function tags_monitors_normal ($id_tag, $groups_and_tags = array(), $id_agente = false) { - return tags_monitors_count(AGENT_MODULE_STATUS_NORMAL, $id_tag, $groups_and_tags, $id_agente); +function tags_get_normal_monitors ($id_tag, $groups_and_tags = array(), $agent_filter = array(), $module_filter = array()) { + // Always modify the module status filter + $module_filter["status"] = AGENT_MODULE_STATUS_NORMAL; + return tags_get_monitors_counter($id_tag, $groups_and_tags, $agent_filter, $module_filter); } /** - * Get the critical monitors count. - * - * @param int $id_tag Id of the tag to filter the modules. + * Get the number of the critical monitors that pass the filters. + * + * @param mixed $id_tag Id in integer or a set of ids into an array. * @param array $groups_and_tags Array with strict ACL rules. - * @param mixed $id_agente Id or ids of the agent to filter the modules. + * @param array $agent_filter Filter of the agents. + * This filter support the following fields: + * -'id': (mixed) Agent id. e.g.: "1". + * @param array $module_filter Filter of the modules. + * This filter support the following fields: + * -'status': (mixed) Module status. Single or grouped into an array. e.g.: AGENT_MODULE_STATUS_CRITICAL. + * -'name': (string) Module name. e.g.: "module_1". + * + * @return int Number of monitors. * - * @return mixed Returns the count of the critical modules or false on error. */ -function tags_monitors_critical ($id_tag, $groups_and_tags = array(), $id_agente = false) { - return tags_monitors_count(AGENT_MODULE_STATUS_CRITICAL_BAD, $id_tag, $groups_and_tags, $id_agente); +function tags_get_critical_monitors ($id_tag, $groups_and_tags = array(), $agent_filter = array(), $module_filter = array()) { + // Always modify the module status filter + $module_filter["status"] = AGENT_MODULE_STATUS_CRITICAL_BAD; + return tags_get_monitors_counter($id_tag, $groups_and_tags, $agent_filter, $module_filter); } /** - * Get the warning monitors count. - * - * @param int $id_tag Id of the tag to filter the modules. + * Get the number of the warning monitors that pass the filters. + * + * @param mixed $id_tag Id in integer or a set of ids into an array. * @param array $groups_and_tags Array with strict ACL rules. - * @param mixed $id_agente Id or ids of the agent to filter the modules. + * @param array $agent_filter Filter of the agents. + * This filter support the following fields: + * -'id': (mixed) Agent id. e.g.: "1". + * @param array $module_filter Filter of the modules. + * This filter support the following fields: + * -'status': (mixed) Module status. Single or grouped into an array. e.g.: AGENT_MODULE_STATUS_CRITICAL. + * -'name': (string) Module name. e.g.: "module_1". + * + * @return int Number of monitors. * - * @return mixed Returns the count of the warning modules or false on error. */ -function tags_monitors_warning ($id_tag, $groups_and_tags = array(), $id_agente = false) { - return tags_monitors_count(AGENT_MODULE_STATUS_WARNING, $id_tag, $groups_and_tags, $id_agente); +function tags_get_warning_monitors ($id_tag, $groups_and_tags = array(), $agent_filter = array(), $module_filter = array()) { + // Always modify the module status filter + $module_filter["status"] = AGENT_MODULE_STATUS_WARNING; + return tags_get_monitors_counter($id_tag, $groups_and_tags, $agent_filter, $module_filter); } /** - * Get the not init monitors count. - * - * @param int $id_tag Id of the tag to filter the modules. + * Get the number of the not init monitors that pass the filters. + * + * @param mixed $id_tag Id in integer or a set of ids into an array. * @param array $groups_and_tags Array with strict ACL rules. - * @param mixed $id_agente Id or ids of the agent to filter the modules. + * @param array $agent_filter Filter of the agents. + * This filter support the following fields: + * -'id': (mixed) Agent id. e.g.: "1". + * @param array $module_filter Filter of the modules. + * This filter support the following fields: + * -'status': (mixed) Module status. Single or grouped into an array. e.g.: AGENT_MODULE_STATUS_CRITICAL. + * -'name': (string) Module name. e.g.: "module_1". + * + * @return int Number of monitors. * - * @return mixed Returns the count of the not init modules or false on error. */ -function tags_monitors_not_init ($id_tag, $groups_and_tags = array(), $id_agente = false) { - return tags_monitors_count(AGENT_MODULE_STATUS_NOT_INIT, $id_tag, $groups_and_tags, $id_agente); +function tags_get_not_init_monitors ($id_tag, $groups_and_tags = array(), $agent_filter = array(), $module_filter = array()) { + // Always modify the module status filter + $module_filter["status"] = AGENT_MODULE_STATUS_NOT_INIT; + return tags_get_monitors_counter($id_tag, $groups_and_tags, $agent_filter, $module_filter); } /** - * Get the unknown monitors count. - * - * @param int $id_tag Id of the tag to filter the modules. + * Get the number of the unknown monitors that pass the filters. + * + * @param mixed $id_tag Id in integer or a set of ids into an array. * @param array $groups_and_tags Array with strict ACL rules. - * @param mixed $id_agente Id or ids of the agent to filter the modules. + * @param array $agent_filter Filter of the agents. + * This filter support the following fields: + * -'id': (mixed) Agent id. e.g.: "1". + * @param array $module_filter Filter of the modules. + * This filter support the following fields: + * -'status': (mixed) Module status. Single or grouped into an array. e.g.: AGENT_MODULE_STATUS_CRITICAL. + * -'name': (string) Module name. e.g.: "module_1". + * + * @return int Number of monitors. * - * @return mixed Returns the count of the unknown modules or false on error. */ -function tags_monitors_unknown ($id_tag, $groups_and_tags = array(), $id_agente = false) { - return tags_monitors_count(AGENT_MODULE_STATUS_UNKNOWN, $id_tag, $groups_and_tags, $id_agente); +function tags_get_unknown_monitors ($id_tag, $groups_and_tags = array(), $agent_filter = array(), $module_filter = array()) { + // Always modify the module status filter + $module_filter["status"] = AGENT_MODULE_STATUS_UNKNOWN; + return tags_get_monitors_counter($id_tag, $groups_and_tags, $agent_filter, $module_filter); } /** diff --git a/pandora_console/operation/tree.php b/pandora_console/operation/tree.php index 5a55da0594..dafd0714c9 100755 --- a/pandora_console/operation/tree.php +++ b/pandora_console/operation/tree.php @@ -122,28 +122,6 @@ else{ } // ---------------------Tabs ------------------------------------------- - -if (! defined ('METACONSOLE')) { - -} -else { - // Check if the loaded tab is allowed or not - // $allowed_tabs = array('group'); - - // if ($config['enable_tags_tree']) { - // $allowed_tabs[] = 'tag'; - // } - - // if (!in_array($activeTab, $allowed_tabs)) { - // db_pandora_audit("HACK Attempt", - // "Trying to access to not allowed tab on tree view"); - // include ("general/noaccess.php"); - - // exit; - // } - // End of tab check -} - // --------------------- form filter ----------------------------------- $table = new StdClass(); @@ -164,56 +142,48 @@ $row = array(); $row[] = __('Agent status'); $row[] = html_print_select($agent_status_arr, "status_agent", $status_agent, '', '', 0, true); $row[] = __('Search agent'); -if (defined('METACONSOLE')) - $row[] = html_print_input_text("search_agent", $search_agent, '', 70, 30, true); -else - $row[] = html_print_input_text("search_agent", $search_agent, '', 40, 30, true); - +$row[] = html_print_input_text("search_agent", $search_agent, '', 40, 30, true); + // Button $row[] = html_print_submit_button(__('Filter'), "uptbutton", false, 'class="sub search"', true); $table->rowspan[][count($row)-1] = 2; $table->data[] = $row; -// Module filter -$module_status_arr = array(); -$module_status_arr[-1] = __('All'); //default -$module_status_arr[AGENT_MODULE_STATUS_NORMAL] = __('Normal'); -$module_status_arr[AGENT_MODULE_STATUS_WARNING] = __('Warning'); -$module_status_arr[AGENT_MODULE_STATUS_CRITICAL_BAD] = __('Critical'); -$module_status_arr[AGENT_MODULE_STATUS_UNKNOWN] = __('Unknown'); -$module_status_arr[AGENT_MODULE_STATUS_NOT_INIT] = __('Not init'); +if (!$strict_acl) { + // Module filter + $module_status_arr = array(); + $module_status_arr[-1] = __('All'); //default + $module_status_arr[AGENT_MODULE_STATUS_NORMAL] = __('Normal'); + $module_status_arr[AGENT_MODULE_STATUS_WARNING] = __('Warning'); + $module_status_arr[AGENT_MODULE_STATUS_CRITICAL_BAD] = __('Critical'); + $module_status_arr[AGENT_MODULE_STATUS_UNKNOWN] = __('Unknown'); + $module_status_arr[AGENT_MODULE_STATUS_NOT_INIT] = __('Not init'); -$row = array(); -$row[] = __('Module status'); -$row[] = html_print_select($module_status_arr, "status_module", $status_module, '', '', 0, true); -$row[] = __('Search module'); -if (defined('METACONSOLE')) - $row[] = html_print_input_text("search_module", $search_module, '', 70, 30, true); -else + $row = array(); + $row[] = __('Module status'); + $row[] = html_print_select($module_status_arr, "status_module", $status_module, '', '', 0, true); + $row[] = __('Search module'); $row[] = html_print_input_text("search_module", $search_module, '', 40, 30, true); -$table->data[] = $row; + $table->data[] = $row; +} if (defined('METACONSOLE')) { - $table->width = "96%"; - $table->cellpadding = "0"; - $table->cellspacing = "0"; - $table->class='databox_filters'; - $table->styleTable='padding-top:0px'; + $table->width = "70%"; + $table->class='tree_filters'; + echo "