A lot of changes into the agents and modules counters
This commit is contained in:
parent
7e1b707b64
commit
ecb5a4097f
|
@ -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();
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 "<div class='view_tree'>";
|
||||
}
|
||||
if (!$strict_acl) {
|
||||
$form_html = '<form id="tree_search" method="post" action="index.php?sec=monitoring&sec2=operation/tree&refr=0&tab='.$tab.'&pure='.$config['pure'].'">';
|
||||
$form_html .= html_print_table($table, true);
|
||||
$form_html .= '</form>';
|
||||
if (defined('METACONSOLE')) {
|
||||
echo "<div class='view_tree'>";
|
||||
ui_toggle($form_html, __('Show Options'));
|
||||
echo "<br>";
|
||||
}else{
|
||||
echo "<br>";
|
||||
ui_toggle($form_html, __('Tree search'));
|
||||
}
|
||||
|
||||
$form_html = '<form id="tree_search" method="post" action="index.php?sec=monitoring&sec2=operation/tree&refr=0&tab='.$tab.'&pure='.$config['pure'].'">';
|
||||
$form_html .= html_print_table($table, true);
|
||||
$form_html .= '</form>';
|
||||
if (defined('METACONSOLE')) {
|
||||
echo $form_html;
|
||||
echo "<br>";
|
||||
}else{
|
||||
echo "<br>";
|
||||
ui_toggle($form_html, __('Tree search'));
|
||||
}
|
||||
|
||||
html_print_input_hidden("group-id", $group_id);
|
||||
|
|
Loading…
Reference in New Issue