';
diff --git a/pandora_console/include/ajax/module.php b/pandora_console/include/ajax/module.php
index 7f59e1f5d3..275924df36 100755
--- a/pandora_console/include/ajax/module.php
+++ b/pandora_console/include/ajax/module.php
@@ -74,9 +74,9 @@ if ($search_modules) {
$id_agents = json_decode(io_safe_output(get_parameter('id_agents')));
$filter = '%' . get_parameter('q', '') . '%';
$other_filter = json_decode(io_safe_output(get_parameter('other_filter')), true);
-
+ // TODO TAGS agents_get_modules
$modules = agents_get_modules($id_agents, false,
- (array('nombre' => $filter) + $other_filter));
+ (array('tagente_modulo.nombre' => $filter) + $other_filter));
if ($modules === false) $modules = array();
@@ -550,10 +550,18 @@ if ($list_modules) {
// Fix: for tag functionality groups have to be all user_groups (propagate ACL funct!)
$groups = users_get_groups($config["id_user"], $access);
- if($cluster_list != 1){
- $tags_sql = tags_get_acl_tags($config['id_user'],
- array_keys($groups), $access, 'module_condition', 'AND',
- 'tagente_modulo', false, array(), true);
+ $tags_join = "";
+ $tags_sql = "";
+ if($cluster_list != 1) {
+ $tags = tags_get_user_applied_agent_tags ($id_agent, $access);
+ if ($tags === false) {
+ $tags_sql = " AND 1=0";
+ }
+ elseif (is_array($tags)) {
+ $tags_sql = " AND ttag_module.id_tag IN (" . implode(',', $tags) . ")";
+ $tags_join = "LEFT JOIN ttag_module
+ ON ttag_module.id_agente_modulo = tagente_modulo.id_agente_modulo";
+ }
}
$status_filter_monitor = (int)get_parameter('status_filter_monitor', -1);
@@ -571,10 +579,10 @@ if ($list_modules) {
}
if ($status_module_group != -1) {
- $status_module_group_filter = 'id_module_group = ' . $status_module_group;
+ $status_module_group_filter = 'tagente_modulo.id_module_group = ' . $status_module_group;
}
else {
- $status_module_group_filter = 'id_module_group >= 0';
+ $status_module_group_filter = 'tagente_modulo.id_module_group >= 0';
}
$status_text_monitor_sql = '%';
@@ -590,66 +598,22 @@ if ($list_modules) {
}
//Count monitors/modules
- switch ($config["dbtype"]) {
- case "mysql":
- $sql = sprintf("
- SELECT COUNT(*)
- FROM tagente_estado,
- (SELECT *
- FROM tagente_modulo
- WHERE id_agente = %d AND nombre LIKE \"%s\" AND delete_pending = 0
- AND disabled = 0 AND %s) tagente_modulo
- LEFT JOIN tmodule_group
- ON tagente_modulo.id_module_group = tmodule_group.id_mg
- WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
- AND %s %s
- AND tagente_estado.estado != %d
- AND tagente_modulo.%s
- ORDER BY tagente_modulo.id_module_group , %s %s",
- $id_agente, $status_text_monitor_sql,$status_module_group_filter,$status_filter_sql, $tags_sql, $monitor_filter,
- $status_module_group_filter, $order['field'], $order['order']);
- break;
- case "postgresql":
- $sql = sprintf("
- SELECT COUNT(DISTINCT tagente_modulo.id_module_group)
- FROM tagente_estado,
- (SELECT *
- FROM tagente_modulo
- WHERE id_agente = %d AND nombre LIKE '%s'
- AND delete_pending = 0
- AND disabled = 0 AND %s) tagente_modulo
- LEFT JOIN tmodule_group
- ON tagente_modulo.id_module_group = tmodule_group.id_mg
- WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
- AND %s %s
- AND tagente_estado.estado != %d
- AND tagente_modulo.%s
- GROUP BY tagente_modulo.id_module_group,
- tagente_modulo.nombre
- ORDER BY tagente_modulo.id_module_group , %s %s",
- $id_agente, $status_text_monitor_sql,$status_module_group_filter,$status_filter_sql,
- $tags_sql, $monitor_filter,$status_module_group_filter,$order['field'],
- $order['order']);
- break;
- case "oracle":
- $sql = sprintf ("
- SELECT COUNT(*)" .
- " FROM tagente_estado, tagente_modulo
- LEFT JOIN tmodule_group
- ON tmodule_group.id_mg = tagente_modulo.id_module_group
- WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
- AND tagente_modulo.id_agente = %d
- AND tagente_modulo.nombre LIKE '%s'
- AND %s %s
- AND tagente_modulo.delete_pending = 0
- AND tagente_modulo.disabled = 0
- AND tagente_estado.estado != %d
- AND tagente_modulo.%s
- ORDER BY tagente_modulo.id_module_group , %s %s
- ", $id_agente, $status_text_monitor_sql, $status_filter_sql, $tags_sql, $monitor_filter,
- $status_module_group_filter,$order['field'], $order['order']);
- break;
- }
+ $order_sql = $order['field'] . " " . $order['order'];
+ $sql = "SELECT COUNT(*)
+ FROM tagente_modulo
+ $tags_join
+ INNER JOIN tagente_estado
+ ON tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
+ LEFT JOIN tmodule_group
+ ON tagente_modulo.id_module_group = tmodule_group.id_mg
+ WHERE tagente_modulo.id_agente = $id_agente
+ AND nombre LIKE '$status_text_monitor_sql'
+ AND delete_pending = 0
+ AND $status_filter_sql
+ $tags_sql
+ AND tagente_estado.estado != $monitor_filter
+ GROUP BY tagente_modulo.id_agente_modulo
+ ";
$count_modules = db_get_all_rows_sql($sql);
if (isset($count_modules[0]))
@@ -659,68 +623,22 @@ if ($list_modules) {
//Get monitors/modules
// Get all module from agent
- switch ($config["dbtype"]) {
- case "mysql":
- $sql = sprintf("
- SELECT *
- FROM tagente_estado,
- (SELECT *
- FROM tagente_modulo
- WHERE id_agente = %d AND nombre LIKE \"%s\" AND delete_pending = 0
- AND disabled = 0 AND %s) tagente_modulo
- LEFT JOIN tmodule_group
- ON tagente_modulo.id_module_group = tmodule_group.id_mg
- WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
- AND %s %s
- AND tagente_estado.estado != %d
- AND tagente_modulo.%s
- ORDER BY tmodule_group.name , %s %s",
- $id_agente, $status_text_monitor_sql,$status_module_group_filter,$status_filter_sql, $tags_sql, $monitor_filter,
- $status_module_group_filter, $order['field'], $order['order']);
-
- break;
- case "postgresql":
- $sql = sprintf("
- SELECT *
- FROM tagente_estado,
- (SELECT *
- FROM tagente_modulo
- WHERE id_agente = %d AND nombre LIKE '%s' AND delete_pending = 0
- AND disabled = 0 AND %s) tagente_modulo
- LEFT JOIN tmodule_group
- ON tagente_modulo.id_module_group = tmodule_group.id_mg
- WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
- AND %s %s
- AND tagente_estado.estado != %d
- AND tagente_modulo.%s
- ORDER BY tmodule_group.name , %s %s",
- $id_agente, $status_text_monitor_sql,$status_module_group_filter,$status_filter_sql, $tags_sql, $monitor_filter,
- $status_module_group_filter, $order['field'], $order['order']);
- break;
- // If Dbms is Oracle then field_list in sql statement has to be recoded. See oracle_list_all_field_table()
- case "oracle":
- $fields_tagente_estado = oracle_list_all_field_table('tagente_estado', 'string');
- $fields_tagente_modulo = oracle_list_all_field_table('tagente_modulo', 'string');
- $fields_tmodule_group = oracle_list_all_field_table('tmodule_group', 'string');
-
- $sql = sprintf ("
- SELECT " . $fields_tagente_estado . ', ' . $fields_tagente_modulo . ', ' . $fields_tmodule_group .
- " FROM tagente_estado, tagente_modulo
- LEFT JOIN tmodule_group
- ON tmodule_group.id_mg = tagente_modulo.id_module_group
- WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
- AND tagente_modulo.id_agente = %d
- AND tagente_modulo.nombre LIKE '%s'
- AND %s %s
- AND tagente_modulo.delete_pending = 0
- AND tagente_modulo.disabled = 0
- AND tagente_estado.estado != %d
- AND tagente_modulo.%s
- ORDER BY tmodule_group.name , %s %s
- ", $id_agente, $status_text_monitor_sql, $tags_sql, $status_filter_sql, $monitor_filter,
- $status_module_group_filter, $order['field'], $order['order']);
- break;
- }
+ $sql = "SELECT tagente_estado.*, tagente_modulo.*, tmodule_group.*
+ FROM tagente_modulo
+ $tags_join
+ INNER JOIN tagente_estado
+ ON tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
+ LEFT JOIN tmodule_group
+ ON tagente_modulo.id_module_group = tmodule_group.id_mg
+ WHERE tagente_modulo.id_agente = $id_agente
+ AND nombre LIKE '$status_text_monitor_sql'
+ AND delete_pending = 0
+ AND $status_filter_sql
+ $tags_sql
+ AND tagente_estado.estado != $monitor_filter
+ GROUP BY tagente_modulo.id_agente_modulo
+ ORDER BY tmodule_group.name, $order_sql
+ ";
if ($monitors_change_filter) {
$limit = " LIMIT " . $config['block_size'] . " OFFSET 0";
diff --git a/pandora_console/include/ajax/visual_console_builder.ajax.php b/pandora_console/include/ajax/visual_console_builder.ajax.php
index 92a77974e7..7bdddf50b9 100755
--- a/pandora_console/include/ajax/visual_console_builder.ajax.php
+++ b/pandora_console/include/ajax/visual_console_builder.ajax.php
@@ -993,7 +993,6 @@ switch ($action) {
if (isset($elementFields["linked_layout_status_as_service_warning"])) {
$elementFields["linked_layout_status_as_service_warning"] = (float) $elementFields["linked_layout_status_as_service_warning"];
}
-
switch ($type) {
case 'auto_sla_graph':
$elementFields['event_max_time_row'] = $elementFields['period'];
@@ -1059,7 +1058,7 @@ switch ($action) {
$elementFields['id_agent'], false,
array('disabled' => 0,
'id_agente' => $elementFields['id_agent'],
- 'tagente_modulo.id_tipo_modulo IN' => "(17,23,3,10,33)"));
+ 'tagente_modulo.id_tipo_modulo IN' => "(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,18,17,23,3,10,33)"));
$elementFields['modules_html'] = '
';
foreach ($modules as $id => $name) {
diff --git a/pandora_console/include/class/Tree.class.php b/pandora_console/include/class/Tree.class.php
index b72e3ec216..05c994df9e 100644
--- a/pandora_console/include/class/Tree.class.php
+++ b/pandora_console/include/class/Tree.class.php
@@ -28,7 +28,6 @@ class Tree {
protected $userGroups;
protected $userGroupsArray;
- protected $acltags = false;
protected $access = false;
protected $L1fieldName = '';
@@ -69,8 +68,6 @@ class Tree {
enterprise_include_once("include/functions_agents.php");
if (is_metaconsole()) enterprise_include_once("meta/include/functions_ui_meta.php");
-
- $this->acltags = tags_get_user_groups_and_tags($config['id_user'], $this->access);
}
public function setFilter($filter) {
@@ -205,26 +202,19 @@ class Tree {
return "AND ta.$field_filter > 0" . $show_init_condition;
}
- // FIXME: Separate and condition from inner join
protected function getTagJoin () {
- // $parent is the agent id
- $group_id = (int) db_get_value('id_grupo', 'tagente', 'id_agente', $this->id);
- $tag_join = '';
- if (empty($group_id)) {
- // ACL error, this will restrict the module search
- $tag_join = 'INNER JOIN ttag_module tta
- ON 1=0';
- }
- else if (!empty($this->acltags) && isset($this->acltags[$group_id])) {
- $tags_str = $this->acltags[$group_id];
+ return 'INNER JOIN ttag_module ttm
+ ON tam.id_agente_modulo = ttm.id_agente_modulo';
+ }
- if (!empty($tags_str)) {
- $tag_join = sprintf('INNER JOIN ttag_module ttm
- ON tam.id_agente_modulo = ttm.id_agente_modulo
- AND ttm.id_tag IN (%s)', $tags_str);
- }
- }
- return $tag_join;
+ protected function getTagCondition () {
+ $tags = tags_get_user_applied_agent_tags($this->id, "AR");
+ // All tags permision, returns no condition
+ if ($tags === true) return "";
+ // No permision, do not show anything
+ if ($tags === false) return " AND 1=0";
+ $tags_sql = implode(',', $tags);
+ return "AND ttm.id_tag IN ($tags_sql)";;
}
protected function getModuleStatusFilterFromTestado ($state = false, $without_ands = false) {
@@ -900,7 +890,8 @@ class Tree {
$module_search_filter = $this->getModuleSearchFilter();
$module_status_filter = $this->getModuleStatusFilterFromTestado();
$agent_filter = "AND ta.id_agente = " . $this->id;
- $tag_join = $this->getTagJoin();
+ $tag_condition = $this->getTagCondition();
+ $tag_join = empty($tag_condition) ? '' : $this->getTagJoin();
$condition = $this->L2condition;
$inner = $this->L2inner;
@@ -909,9 +900,6 @@ class Tree {
tam.id_tipo_modulo, tam.id_modulo, tae.estado, tae.datos,
tam.parent_module_id AS parent, tatm.id AS alerts';
- // has any of this tags.
- $tag_join = '';
-
$sql = "SELECT $columns
FROM tagente_modulo tam
$tag_join
@@ -932,6 +920,7 @@ class Tree {
$agent_status_filter
$module_status_filter
$module_search_filter
+ $tag_condition
ORDER BY tam.nombre ASC, tam.id_agente_modulo ASC";
return $sql;
}
diff --git a/pandora_console/include/class/TreeTag.class.php b/pandora_console/include/class/TreeTag.class.php
index c6562db725..c02fb7ba4a 100644
--- a/pandora_console/include/class/TreeTag.class.php
+++ b/pandora_console/include/class/TreeTag.class.php
@@ -48,6 +48,14 @@ class TreeTag extends Tree {
$this->getThirdLevel();
}
}
+
+ protected function getTagJoin () {
+ return '';
+ }
+
+ protected function getTagCondition () {
+ return '';
+ }
}
?>
diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php
index 2bb0959b7e..2e9ef1f55f 100644
--- a/pandora_console/include/functions_agents.php
+++ b/pandora_console/include/functions_agents.php
@@ -599,7 +599,6 @@ function agents_process_manage_config ($source_id_agent, $destiny_id_agents, $co
$module = modules_get_agentmodule ($id_agent_module);
if ($module === false)
return false;
-
$modules = agents_get_modules ($id_destiny_agent, false,
array ('nombre' => $module['nombre'], 'disabled' => false));
@@ -825,8 +824,9 @@ function agents_get_group_agents (
$filter = array();
if (!$noACL) {
- $id_group = groups_safe_acl($config["id_user"], $id_group, "AR");
-
+ $id_group = $id_group == 0
+ ? array_keys(users_get_groups(false, "AR", false))
+ : groups_safe_acl($config["id_user"], $id_group, "AR");
if (empty ($id_group)) {
//An empty array means the user doesn't have access
return array ();
@@ -1077,7 +1077,8 @@ function agents_get_modules ($id_agent = null, $details = false,
if (empty($userGroups)) {
return array();
}
- $id_userGroups = $id_groups = array_keys($userGroups);
+ $id_groups = array_keys($userGroups);
+ $id_groups_sql = implode(',', $id_groups);
// =================================================================
// When there is not a agent id. Get a agents of groups that the
@@ -1107,49 +1108,25 @@ function agents_get_modules ($id_agent = null, $details = false,
if (!is_array($id_agent)) {
$id_agent = safe_int ($id_agent, 1);
}
-
- $where = "(
- 1 = (
- SELECT is_admin
- FROM tusuario
- WHERE id_user = '" . $config['id_user'] . "'
- )
- OR
- tagente_modulo.id_agente IN (
- SELECT id_agente
- FROM tagente tas LEFT JOIN tagent_secondary_group tasgs
- ON tas.id_agente = tasgs.id_agent
- WHERE (tas.id_grupo IN (
- " . implode(',', $id_userGroups) . "
- ) OR
- tasgs.id_group IN (
- " . implode(',', $id_userGroups) . "
- )
- )
- )
- OR 0 IN (
- SELECT id_grupo
- FROM tusuario_perfil
- WHERE id_usuario = '" . $config['id_user'] . "'
- AND id_perfil IN (
- SELECT id_perfil
- FROM tperfil WHERE agent_view = 1
- )
- )
+
+ $where = "1 = 1 ";
+ // Groups ACL only when user is not empty
+ if (!users_can_manage_group_all("AR")) {
+ $where = "(
+ tagente.id_grupo IN ($id_groups_sql) OR tasg.id_group IN ($id_groups_sql)
)";
-
- if (! empty ($id_agent)) {
- $where .= sprintf (' AND id_agente IN (%s)', implode (",", (array) $id_agent));
}
-
- $where .= ' AND delete_pending = 0 ';
-
+
+ if (! empty ($id_agent)) {
+ $id_agent_sql = implode (",", (array)$id_agent);
+ $where .= " AND tagente.id_agente IN ($id_agent_sql) ";
+ }
+
if (! empty ($filter)) {
$where .= ' AND ';
if (is_array ($filter)) {
$fields = array ();
-
-
+
//----------------------------------------------------------
// Code for filters as array of arrays
// for example:
@@ -1174,11 +1151,10 @@ function agents_get_modules ($id_agent = null, $details = false,
}
}
//----------------------------------------------------------
-
foreach ($list_filter as $item) {
$field = $item['field'];
$value = $item['value'];
-
+
//Check <> operator
$operatorDistin = false;
if (strlen($value) > 2) {
@@ -1186,119 +1162,91 @@ function agents_get_modules ($id_agent = null, $details = false,
$operatorDistin = true;
}
}
-
+
if ($value[0] == '%') {
- switch ($config['dbtype']) {
- case "mysql":
- case "postgresql":
- array_push ($fields,
- $field . ' LIKE "' . $value . '"');
- break;
- case "oracle":
- array_push ($fields,
- $field . ' LIKE \'' . $value . '\'');
- break;
- }
+ array_push ($fields,
+ $field . ' LIKE "' . $value . '"');
}
else if ($operatorDistin) {
array_push($fields, $field.' <> ' . substr($value, 2));
}
else if (substr($value, -1) == '%') {
- switch ($config['dbtype']) {
- case "mysql":
- case "postgresql":
- array_push ($fields, $field.' LIKE "'.$value.'"');
- break;
- case "oracle":
- array_push ($fields, $field.' LIKE \''.$value.'\'');
- break;
- }
+ array_push ($fields, $field.' LIKE "'.$value.'"');
}
- //else if (strstr($value, '666=666', true) == '') {
else if (strncmp($value, '666=666', 7) == 0) {
- switch ($config['dbtype']) {
- case "mysql":
- case "postgresql":
- array_push ($fields, ' '.$value);
- break;
- case "oracle":
- array_push ($fields, ' '.$value);
- break;
- }
+ array_push ($fields, ' '.$value);
}
else if (preg_match('/\bin\b/i',$field)) {
array_push ($fields, $field.' '.$value);
}
else {
- switch ($config["dbtype"]) {
- case "mysql":
- array_push ($fields, $field.' = "'.$value.'"');
- break;
- case "postgresql":
- array_push ($fields, $field.' = \''.$value.'\'');
- break;
- case "oracle":
- if (is_int ($value) || is_float ($value) || is_double ($value))
- array_push ($fields, $field.' = '.$value.'');
- else
- array_push ($fields, $field.' = \''.$value.'\'');
- break;
- }
+ array_push ($fields, 'tagente_modulo.' . $field.' = "'.$value.'"');
}
}
- $where .= implode (' AND ', $fields);
+ $where .= implode (' AND ', $fields);
}
else {
$where .= $filter;
}
}
-
+
+ $stored_details = $details;
if (empty ($details)) {
- $details = "nombre";
+ $details = "tagente_modulo.nombre";
+ $stored_details = "nombre";
}
- else {
+ else {
+ $details = (array)$details;
$details = io_safe_input ($details);
+ $details = array_map(function ($a) {
+ return preg_match('/tagente_modulo./i', $a) ? $a : 'tagente_modulo.' . $a;
+ },$details
+ );
}
-
- //$where .= " AND id_policy_module = 0 ";
-
+
+ $sql_tags_join = "";
if (tags_has_user_acl_tags($config['id_user'])){
$where_tags = tags_get_acl_tags($config['id_user'], $id_groups, 'AR',
'module_condition', 'AND', 'tagente_modulo', false, array(),
- true);
-
+ true);
$where .= "\n\n" . $where_tags;
+ $sql_tags_join = "INNER JOIN ttag_module
+ ON ttag_module.id_agente_modulo = tagente_modulo.id_agente_modulo";
}
-
+
$sql = sprintf ('SELECT %s%s
FROM tagente_modulo
- WHERE
- %s
- ORDER BY nombre',
- ($details != '*' && $indexed) ? 'id_agente_modulo,' : '',
+ %s
+ INNER JOIN tagente
+ ON tagente.id_agente = tagente_modulo.id_agente
+ LEFT JOIN tagent_secondary_group tasg
+ ON tagente.id_agente = tasg.id_agent
+ WHERE tagente_modulo.delete_pending = 0
+ AND %s
+ GROUP BY tagente_modulo.id_agente_modulo
+ ORDER BY tagente_modulo.nombre',
+ ($details != 'tagente_modulo.*' && $indexed) ? 'tagente_modulo.id_agente_modulo,' : '',
io_safe_output(implode (",", (array) $details)),
+ $sql_tags_join,
$where);
-
-
$result = db_get_all_rows_sql ($sql);
-
-
+
if (empty ($result)) {
return array ();
}
-
+
if (! $indexed)
return $result;
-
+
$modules = array ();
foreach ($result as $module) {
if ($get_not_init_modules || modules_get_agentmodule_is_init($module['id_agente_modulo'])) {
- if (is_array ($details) || $details == '*') {
+ if (is_array ($stored_details) || $stored_details == '*') {
//Just stack the information in array by ID
$modules[$module['id_agente_modulo']] = $module;
}
else {
- $modules[$module['id_agente_modulo']] = $module[$details];
+ $modules[$module['id_agente_modulo']] = $module[$stored_details];
}
}
}
@@ -1400,55 +1348,6 @@ function agents_get_alias_by_name ($name, $case = 'none') {
}
}
-/**
- * Get the number of pandora data packets in the database.
- *
- * In case an array is passed, it will have a value for every agent passed
- * incl. a total otherwise it will just return the total
- *
- * @param mixed Agent id or array of agent id's, 0 for all
- *
- * @return mixed The number of data in the database
- */
-function agents_get_modules_data_count ($id_agent = 0) {
- $id_agent = safe_int ($id_agent, 1);
-
- if (empty ($id_agent)) {
- $id_agent = array ();
- }
- else {
- $id_agent = (array) $id_agent;
- }
-
- $count = array ();
- $count["total"] = 0;
-
- $query[0] = "SELECT COUNT(*) FROM tagente_datos";
-
- foreach ($id_agent as $agent_id) {
- //Init value
- $count[$agent_id] = 0;
- $modules = array_keys (agents_get_modules ($agent_id));
- foreach ($query as $sql) {
- //Add up each table's data
- //Avoid the count over empty array
- if (!empty($modules))
- $count[$agent_id] += (int) db_get_sql ($sql .
- " WHERE id_agente_modulo IN (".implode (",", $modules).")", 0, true);
- }
- //Add total agent count to total count
- $count["total"] += $count[$agent_id];
- }
-
- if ($count["total"] == 0) {
- foreach ($query as $sql) {
- $count["total"] += (int) db_get_sql ($sql, 0, true);
- }
- }
-
- return $count; //Return the array
-}
-
/**
* Check if an agent has alerts fired.
*
@@ -2202,23 +2101,6 @@ function agents_monitor_total ($id_agent, $filter = '', $disabled = false) {
return db_get_sql ($sql);
}
-//Get alert fired for this agent
-
-function agents_get_alerts_fired ($id_agent, $filter="") {
-
- $modules_agent = agents_get_modules($id_agent, "id_agente_modulo", $filter);
-
- if (empty($modules_agent)) {
- return 0;
- }
-
- $mod_clause = "(".implode(",", $modules_agent).")";
-
- return db_get_sql ("SELECT COUNT(times_fired)
- FROM talert_template_modules
- WHERE times_fired != 0 AND id_agent_module IN ".$mod_clause);
-}
-
//Returns the alert image to display tree view
function agents_tree_view_alert_img ($alert_fired) {
@@ -2453,8 +2335,7 @@ function agents_get_network_interfaces ($agents = false, $agents_filter = false)
else
$columns[] = 'descripcion';
- $filter = " id_agente = $agent_id AND disabled = 0 AND id_tipo_modulo IN (".implode(",", $accepted_module_types).") AND (nombre LIKE '%_ifOperStatus' OR nombre LIKE 'ifOperStatus_%')";
-
+ $filter = " tagente_modulo.id_agente = $agent_id AND tagente_modulo.disabled = 0 AND tagente_modulo.id_tipo_modulo IN (".implode(",", $accepted_module_types).") AND (tagente_modulo.nombre LIKE '%_ifOperStatus' OR tagente_modulo.nombre LIKE 'ifOperStatus_%')";
$modules = agents_get_modules($agent_id, $columns, $filter, true, false);
if (!empty($modules)) {
@@ -2520,10 +2401,10 @@ function agents_get_network_interfaces ($agents = false, $agents_filter = false)
);
if($type_interface){
- $interface_traffic_modules = agents_get_modules($agent_id, $columns, "nombre LIKE '". $interface_name . "_if%Octets'");
+ $interface_traffic_modules = agents_get_modules($agent_id, $columns, "tagente_modulo.nombre LIKE '". $interface_name . "_if%Octets'");
}
else{
- $interface_traffic_modules = agents_get_modules($agent_id, $columns, "nombre LIKE 'if%Octets_$interface_name'");
+ $interface_traffic_modules = agents_get_modules($agent_id, $columns, "tagente_modulo.nombre LIKE 'if%Octets_$interface_name'");
}
if (!empty($interface_traffic_modules) && count($interface_traffic_modules) >= 2) {
@@ -2611,85 +2492,173 @@ function agents_get_agent_custom_field ($agent_id, $custom_field_name) {
return db_get_value_sql($sql);
}
-function select_modules_for_agent_group($id_group, $id_agents,
- $selection, $return = true) {
-
- $agents = implode(",", $id_agents);
-
+function select_modules_for_agent_group(
+ $id_group, $id_agents, $selection, $return = true, $index_by_name = false
+) {
+ global $config;
+ $agents = (empty($id_agents)) ? array() : implode(",", $id_agents);
+
+ $filter_agent_group = "";
$filter_group = "";
$filter_agent = "";
+ $selection_filter = "";
+ $sql_conditions_tags = "";
+ $sql_tags_inner = "";
+
+ $groups = array_keys(users_get_groups(false, "AR", false));
if ($id_group != 0) {
- $filter_group = " AND id_module_group = ". $id_group;
+ $filter_group = " AND tagente_modulo.id_module_group = ". $id_group;
}
if ($agents != null) {
- $filter_agent = " AND id_agente IN (" . $agents . ")";
+ $filter_agent = " AND tagente.id_agente IN (" . $agents . ")";
+ }
+ if (!users_can_manage_group_all("AR")) {
+ $group_string = implode(',', $groups);
+ $filter_agent_group = " AND (
+ tagente.id_grupo IN ($group_string)
+ OR tasg.id_group IN ($group_string)
+ )";
+ }
+ if (!$selection && $agents != null) {
+ $number_agents = count($id_agents);
+ $selection_filter = "HAVING COUNT(id_agente_modulo) = $number_agents";
}
- if ($selection == 1 || (count($id_agents) == 1)) {
- $modules = db_get_all_rows_sql("SELECT DISTINCT nombre, id_agente_modulo
- FROM tagente_modulo
- WHERE 1 = 1" . $filter_agent . $filter_group);
-
- if (empty($modules)) $modules = array();
-
- $found = array();
- foreach ($modules as $i=>$row) {
- $check = $row['nombre'];
- if (@$found[$check]++) {
- unset($modules[$i]);
- }
- }
+ if (tags_has_user_acl_tags(false)){
+ $sql_conditions_tags = tags_get_acl_tags(
+ $config['id_user'], $groups, 'AR',
+ 'module_condition', 'AND', 'tagente_modulo', true, array(),
+ false);
+ $sql_tags_inner = "INNER JOIN ttag_module
+ ON ttag_module.id_agente_modulo = tagente_modulo.id_agente_modulo";
}
- else {
- $modules = db_get_all_rows_sql("SELECT nombre, id_agente_modulo
- FROM tagente_modulo
- WHERE 1 = 1" . $filter_agent . $filter_group);
- if (empty($modules)) $modules = array();
+ $sql = "SELECT * FROM
+ (
+ SELECT DISTINCT(tagente_modulo.id_agente_modulo), tagente_modulo.nombre
+ FROM tagente_modulo
+ $sql_tags_inner
+ INNER JOIN tagente
+ ON tagente.id_agente = tagente_modulo.id_agente
+ LEFT JOIN tagent_secondary_group tasg
+ ON tagente.id_agente = tasg.id_agent
+ WHERE tagente.disabled = 0
+ AND tagente_modulo.disabled = 0
+ $filter_agent_group
+ $filter_group
+ $filter_agent
+ $sql_conditions_tags
+ ) x
+ GROUP BY nombre
+ $selection_filter";
- foreach ($modules as $m) {
- $is_in_all_agents = true;
- $module_name = $m['nombre'];
- foreach ($id_agents as $a) {
- $module_in_agent = db_get_value_filter('id_agente_modulo',
- 'tagente_modulo', array('id_agente' => $a, 'nombre' => $module_name));
- if (!$module_in_agent) {
- $is_in_all_agents = false;
- }
- }
- if ($is_in_all_agents) {
- $modules_to_report[] = $m;
- }
- }
- $modules = $modules_to_report;
+ $modules = db_get_all_rows_sql($sql);
+ if ($modules === false) $modules = array();
- $found = array();
- if (is_array($modules) || is_object($modules)){
- foreach ($modules as $i=>$row) {
- $check = $row['nombre'];
- if (@$found[$check]++) {
- unset($modules[$i]);
- }
- }
- }
- }
- if (is_array($modules) || is_object($modules)){
- foreach ($modules as $k => $v) {
- $modules[$k] = io_safe_output($v);
- }
- }
-
- if($return == false){
- foreach ($modules as $value) {
- $modules_array[$value['id_agente_modulo']] = $value['nombre'];
- }
- return $modules_array;
- }
- else{
+ if ($return) {
echo json_encode($modules);
return;
}
+
+ $modules_array = array();
+ foreach ($modules as $value) {
+ if($index_by_name) {
+ $modules_array[io_safe_output($value['nombre'])] =
+ ui_print_truncate_text(
+ io_safe_output($value['nombre']), 'module_medium', false, true
+ );
+ } else {
+ $modules_array[$value['id_agente_modulo']] = $value['nombre'];
+ }
+ }
+ return $modules_array;
+}
+
+function select_agents_for_module_group(
+ $module_names, $selection, $filter, $access = "AR"
+) {
+ global $config;
+
+ $default_filter = array (
+ 'status' => null
+ );
+
+ $filter = array_merge($default_filter, $filter);
+
+ $module_names_condition = "";
+ $filter_agent_group = "";
+ $selection_filter = "";
+ $sql_conditions_tags = "";
+ $sql_tags_inner = "";
+ $status_filter = "";
+ $module_type_filter = "";
+
+ $groups = array_keys(users_get_groups(false, $access, false));
+
+ // Name
+ if (!users_can_manage_group_all($access)) {
+ $group_string = implode(',', $groups);
+ $filter_agent_group = " AND (
+ tagente.id_grupo IN ($group_string)
+ OR tasg.id_group IN ($group_string)
+ )";
+ }
+
+ // Name filter
+ if ($module_names) {
+ $module_names_sql = implode("','", $module_names);
+ $module_names_condition = " AND tagente_modulo.nombre IN ('$module_names_sql') ";
+ }
+
+ // Common or all modules filter
+ if (!$selection) {
+ $number_modules = count($module_names);
+ $selection_filter = "HAVING COUNT(id_agente) = $number_modules";
+ }
+
+ // Status filter
+ if ($filter['status'] != null) {
+ $status_filter = " AND " . modules_get_state_condition(
+ $filter['status'], "tagente_estado"
+ );
+ }
+
+ // Tags input and ACL conditions
+ if (tags_has_user_acl_tags(false) || $filter['tags'] != null){
+ $sql_conditions_tags = tags_get_acl_tags(
+ $config['id_user'], $groups, $access,
+ 'module_condition', 'AND', 'tagente_modulo', true, array(),
+ false);
+ $sql_tags_inner = "INNER JOIN ttag_module
+ ON ttag_module.id_agente_modulo = tagente_modulo.id_agente_modulo";
+ }
+
+ $sql = "SELECT * FROM
+ (
+ SELECT tagente.id_agente, tagente.alias
+ FROM tagente
+ LEFT JOIN tagent_secondary_group tasg
+ ON tagente.id_agente = tasg.id_agent
+ INNER JOIN tagente_modulo
+ ON tagente.id_agente = tagente_modulo.id_agente
+ $sql_tags_inner
+ LEFT JOIN tagente_estado
+ ON tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
+ WHERE tagente.disabled = 0
+ AND tagente_modulo.disabled = 0
+ $module_names_condition
+ $filter_agent_group
+ $sql_conditions_tags
+ $status_filter
+ $module_type_filter
+ GROUP BY tagente_modulo.id_agente_modulo
+ ) x
+ GROUP BY id_agente
+ $selection_filter";
+ $modules = db_get_all_rows_sql($sql);
+ if ($modules === false) return array();
+ return index_array(db_get_all_rows_sql($sql), 'id_agente', 'alias');
}
/**
@@ -2723,6 +2692,7 @@ function agents_get_all_groups_agent ($id_agent, $group = false, $force_meta = f
// If cannot retrieve the group, it means that agent does not exist
if (!$group) return array();
+ enterprise_include_once('include/functions_agents.php');
$secondary_groups = enterprise_hook('agents_get_secondary_groups', array($id_agent, $force_meta));
// Return only an array with the group in open version
diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php
index 52c0338eb4..17cc0c8bde 100644
--- a/pandora_console/include/functions_alerts.php
+++ b/pandora_console/include/functions_alerts.php
@@ -1824,23 +1824,6 @@ function get_group_alerts($id_group, $filter = '', $options = false,
FROM tagente_modulo WHERE delete_pending = 0';
}
- if ($strict_user) {
- $groups = users_get_groups($config["id_user"]);
-
- if ($idGroup !== 0) {
- $where_tags = tags_get_acl_tags($config['id_user'], $idGroup, 'AR', 'module_condition', 'AND', 'tagente_modulo', true, array(), true);
- } else {
- $where_tags = tags_get_acl_tags($config['id_user'], array_keys($groups), 'AR', 'module_condition', 'AND', 'tagente_modulo', true, array(), true);
- }
-
- // If there are any errors add imposible condition
- if (in_array($where_tags, array(ERR_WRONG_PARAMETERS, ERR_ACL))) {
- $subQuery .= ' AND 1 = 0';
- }
- else {
- $subQuery .= $where_tags;
- }
- }
}
else {
if ($allModules)
diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php
index f6b6da21cc..39c5fa59ae 100644
--- a/pandora_console/include/functions_events.php
+++ b/pandora_console/include/functions_events.php
@@ -1531,30 +1531,6 @@ function events_get_all_status ($report = false) {
return $fields;
}
-/**
- * Return all event source.
- *
- * @return array event source array.
- */
-function events_get_all_source () {
- $event_table = events_get_events_table(is_metaconsole(),false);
- $fields = array ();
- $fields[''] = __('All');
-
- if (users_is_admin()) {
- $sources = db_get_all_rows_sql("SELECT DISTINCT(source) FROM ". $event_table);
- } else {
- $groups_user = users_get_groups ($config['id_user'], "ER", true);
- $sources = db_get_all_rows_sql("SELECT DISTINCT(source) FROM ". $event_table. " WHERE id_grupo IN (" .implode(",",array_keys($groups_user)) .")");
- }
-
- foreach ($sources as $key => $source) {
- $fields[$source['source']] = $source['source'];
- }
-
- return $fields;
-}
-
/**
* Decode a numeric status into status description.
*
@@ -2240,12 +2216,7 @@ function events_page_details ($event, $server = "") {
$strict_user = (bool) db_get_value("strict_acl", "tusuario", "id_user", $config['id_user']);
if (!empty($agent['id_grupo'])) {
- if ($strict_user) {
- $acl_graph = tags_check_acl_by_module($module["id_agente_modulo"], $config['id_user'], 'RR') === true;
- }
- else {
- $acl_graph = check_acl($config['id_user'], $agent['id_grupo'], "RR");
- }
+ $acl_graph = check_acl($config['id_user'], $agent['id_grupo'], "RR");
}
if ($acl_graph) {
@@ -3554,7 +3525,6 @@ function events_sql_events_grouped_agents($id_agent, $server_id = -1,
else {
$group_array = array_keys($groups);
}
-
$tags_acls_condition = tags_get_acl_tags($id_user, $group_array, 'ER',
'event_condition', 'AND', '', $meta, array(), true); //FORCE CHECK SQL "(TAG = tag1 AND id_grupo = 1)"
@@ -3600,6 +3570,8 @@ function events_list_events_grouped_agents($sql) {
$table = events_get_events_table(is_metaconsole(), $history);
$sql = "select * from $table
+ LEFT JOIN tagent_secondary_group
+ ON tagent_secondary_group.id_agent = tevento.id_agente
WHERE $sql";
$result = db_get_all_rows_sql ($sql);
diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php
index ff15c53525..4bb4a26b47 100644
--- a/pandora_console/include/functions_graph.php
+++ b/pandora_console/include/functions_graph.php
@@ -20,210 +20,6 @@ include_once($config['homedir'] . "/include/functions_agents.php");
include_once($config['homedir'] . "/include/functions_modules.php");
include_once($config['homedir'] . "/include/functions_users.php");
-function get_graph_statistics ($chart_array) {
- global $config;
-
- /// IMPORTANT!
- ///
- /// The calculus for AVG, MIN and MAX values are in this function
- /// because it must be done based on graph array data not using reporting
- /// function to get coherent data between stats and graph visualization
-
- $stats = array ();
-
- $count = 0;
-
- $size = sizeof($chart_array);
-
- //Initialize stats array
- $stats = array ("avg" => 0, "min" => null, "max" => null, "last" => 0);
-
- foreach ($chart_array as $item) {
-
- //Sum all values later divide by the number of elements
- $stats['avg'] = $stats['avg'] + $item;
-
- //Get minimum
- if ($stats['min'] == null) {
- $stats['min'] = $item;
- }
- else if ($item < $stats['min']) {
- $stats['min'] = $item;
- }
-
- //Get maximum
- if ($stats['max'] == null) {
- $stats['max'] = $item;
- }
- else if ($item > $stats['max']) {
- $stats['max'] = $item;
- }
-
- $count++;
-
- //Get last data
- if ($count == $size) {
- $stats['last'] = $item;
- }
- }
-
- //End the calculus for average
- if ($count > 0) {
-
- $stats['avg'] = $stats['avg'] / $count;
- }
-
- //Format stat data to display properly
- $stats['last'] = remove_right_zeros(number_format($stats['last'], $config['graph_precision']));
- $stats['avg'] = remove_right_zeros(number_format($stats['avg'], $config['graph_precision']));
- $stats['min'] = remove_right_zeros(number_format($stats['min'], $config['graph_precision']));
- $stats['max'] = remove_right_zeros(number_format($stats['max'], $config['graph_precision']));
-
- return $stats;
-}
-
-function get_statwin_graph_statistics ($chart_array, $series_suffix = '') {
-
- /// IMPORTANT!
- ///
- /// The calculus for AVG, MIN and MAX values are in this function
- /// because it must be done based on graph array data not using reporting
- /// function to get coherent data between stats and graph visualization
-
- $stats = array ();
-
- $count = 0;
-
- $size = sizeof($chart_array);
-
- //Initialize stats array
- $stats['sum'] = array ("avg" => 0, "min" => null, "max" => null, "last" => 0);
- $stats['min'] = array ("avg" => 0, "min" => null, "max" => null, "last" => 0);
- $stats['max'] = array ("avg" => 0, "min" => null, "max" => null, "last" => 0);
-
- foreach ($chart_array as $item) {
- if ($series_suffix != '') {
- if (isset($item['sum' . $series_suffix]))
- $item['sum'] = $item['sum' . $series_suffix];
- if (isset($item['min' . $series_suffix]))
- $item['min'] = $item['min' . $series_suffix];
- if (isset($item['max' . $series_suffix]))
- $item['max'] = $item['max' . $series_suffix];
- }
-
- //Get stats for normal graph
- if (isset($item['sum']) && $item['sum']) {
-
- //Sum all values later divide by the number of elements
- $stats['sum']['avg'] = $stats['sum']['avg'] + $item['sum'];
-
- //Get minimum
- if ($stats['sum']['min'] == null) {
- $stats['sum']['min'] = $item['sum'];
- }
- else if ($item['sum'] < $stats['sum']['min']) {
- $stats['sum']['min'] = $item['sum'];
- }
-
- //Get maximum
- if ($stats['sum']['max'] == null) {
- $stats['sum']['max'] = $item['sum'];
- }
- else if ($item['sum'] > $stats['sum']['max']) {
- $stats['sum']['max'] = $item['sum'];
- }
- }
-
- //Get stats for min graph
- if (isset($item['min']) && $item['min']) {
- //Sum all values later divide by the number of elements
- $stats['min']['avg'] = $stats['min']['avg'] + $item['min'];
-
- //Get minimum
- if ($stats['min']['min'] == null) {
- $stats['min']['min'] = $item['min'];
- }
- else if ($item['min'] < $stats['min']['min']) {
- $stats['min']['min'] = $item['min'];
- }
-
- //Get maximum
- if ($stats['min']['max'] == null) {
- $stats['min']['max'] = $item['min'];
- }
- else if ($item['min'] > $stats['min']['max']) {
- $stats['min']['max'] = $item['min'];
- }
- }
-
- //Get stats for max graph
- if (isset($item['max']) && $item['max']) {
- //Sum all values later divide by the number of elements
- $stats['max']['avg'] = $stats['max']['avg'] + $item['max'];
-
- //Get minimum
- if ($stats['max']['min'] == null) {
- $stats['max']['min'] = $item['max'];
- }
- else if ($item['max'] < $stats['max']['min']) {
- $stats['max']['min'] = $item['max'];
- }
-
- //Get maximum
- if ($stats['max']['max'] == null) {
- $stats['max']['max'] = $item['max'];
- }
- else if ($item['max'] > $stats['max']['max']) {
- $stats['max']['max'] = $item['max'];
- }
- }
-
- //Count elements
- $count++;
-
- //Get last data
- if ($count == $size) {
- if (isset($item['sum']) && $item['sum']) {
- $stats['sum']['last'] = $item['sum'];
- }
-
- if (isset($item['min']) && $item['min']) {
- $stats['min']['last'] = $item['min'];
- }
-
- if (isset($item['max']) && $item['max']) {
- $stats['max']['last'] = $item['max'];
- }
- }
- }
-
- //End the calculus for average
- if ($count > 0) {
-
- $stats['sum']['avg'] = $stats['sum']['avg'] / $count;
- $stats['min']['avg'] = $stats['min']['avg'] / $count;
- $stats['max']['avg'] = $stats['max']['avg'] / $count;
- }
-
- //Format stat data to display properly
- $stats['sum']['last'] = round($stats['sum']['last'], 2);
- $stats['sum']['avg'] = round($stats['sum']['avg'], 2);
- $stats['sum']['min'] = round($stats['sum']['min'], 2);
- $stats['sum']['max'] = round($stats['sum']['max'], 2);
-
- $stats['min']['last'] = round($stats['min']['last'], 2);
- $stats['min']['avg'] = round($stats['min']['avg'], 2);
- $stats['min']['min'] = round($stats['min']['min'], 2);
- $stats['min']['max'] = round($stats['min']['max'], 2);
-
- $stats['max']['last'] = round($stats['max']['last'], 2);
- $stats['max']['avg'] = round($stats['max']['avg'], 2);
- $stats['max']['min'] = round($stats['max']['min'], 2);
- $stats['max']['max'] = round($stats['max']['max'], 2);
-
- return $stats;
-}
-
function grafico_modulo_sparse_data_chart (
$agent_module_id,
$date_array,
@@ -2471,6 +2267,7 @@ function graph_event_module ($width = 300, $height = 200, $id_agent) {
// Fix: tag filters implemented! for tag functionality groups have to be all user_groups (propagate ACL funct!)
$groups = users_get_groups($config["id_user"]);
+
$tags_condition = tags_get_acl_tags($config['id_user'], array_keys($groups), 'ER', 'event_condition', 'AND');
$data = array ();
@@ -2623,382 +2420,6 @@ function graph_sla_slicebar ($id, $period, $sla_min, $sla_max, $date, $daysWeek
$config['fontpath'], $round_corner, $home_url, $ttl);
}
-/**
- * Print a pie graph with purge data of agent
- *
- * @param integer id_agent ID of agent to show
- * @param integer width pie graph width
- * @param integer height pie graph height
- */
-function grafico_db_agentes_purge ($id_agent, $width = 380, $height = 300) {
- global $config;
- global $graphic_type;
-
- $filter = array();
-
- if ($id_agent < 1) {
- $query = "";
- }
- else {
- $modules = agents_get_modules($id_agent);
- $module_ids = array_keys($modules);
-
- if (!empty($module_ids))
- $filter['id_agente_modulo'] = $module_ids;
- }
-
- // All data (now)
- $time_now = time();
-
- // 1 day ago
- $time_1day = $time_now - SECONDS_1DAY;
-
- // 1 week ago
- $time_1week = $time_now - SECONDS_1WEEK;
-
- // 1 month ago
- $time_1month = $time_now - SECONDS_1MONTH;
-
- // Three months ago
- $time_3months = $time_now - SECONDS_3MONTHS;
-
- $query_error = false;
-
- // Data from 1 day ago
- $num_1day = 0;
- $num_1day += (int) db_get_sql('SELECT COUNT(*)
- FROM tagente_datos
- WHERE utimestamp > ' . $time_1day);
- $num_1day += (int) db_get_sql('SELECT COUNT(*)
- FROM tagente_datos_string
- WHERE utimestamp > ' . $time_1day);
- $num_1day += (int) db_get_sql('SELECT COUNT(*)
- FROM tagente_datos_log4x
- WHERE utimestamp > ' . $time_1day);
- if ($num_1day >= 0) {
- // Data from 1 week ago
- $num_1week = 0;
- $num_1week += (int) db_get_sql('SELECT COUNT(*)
- FROM tagente_datos
- WHERE utimestamp > ' . $time_1week . '
- AND utimestamp < ' . $time_1day);
- $num_1week += (int) db_get_sql('SELECT COUNT(*)
- FROM tagente_datos_string
- WHERE utimestamp > ' . $time_1week . '
- AND utimestamp < ' . $time_1day);
- $num_1week += (int) db_get_sql('SELECT COUNT(*)
- FROM tagente_datos_log4x
- WHERE utimestamp > ' . $time_1week . '
- AND utimestamp < ' . $time_1day);
- if ($num_1week >= 0) {
- if ($num_1week > 0) {
- $num_1week = 0;
- $num_1week += (int) db_get_sql('SELECT COUNT(*)
- FROM tagente_datos
- WHERE utimestamp > ' . $time_1week);
- $num_1week += (int) db_get_sql('SELECT COUNT(*)
- FROM tagente_datos_string
- WHERE utimestamp > ' . $time_1week);
- $num_1week += (int) db_get_sql('SELECT COUNT(*)
- FROM tagente_datos_log4x
- WHERE utimestamp > ' . $time_1week);
- }
- // Data from 1 month ago
- $num_1month = 0;
- $num_1month += (int) db_get_sql('SELECT COUNT(*)
- FROM tagente_datos
- WHERE utimestamp > ' . $time_1month . '
- AND utimestamp < ' . $time_1week);
- $num_1month += (int) db_get_sql('SELECT COUNT(*)
- FROM tagente_datos_string
- WHERE utimestamp > ' . $time_1month . '
- AND utimestamp < ' . $time_1week);
- $num_1month += (int) db_get_sql('SELECT COUNT(*)
- FROM tagente_datos_log4x
- WHERE utimestamp > ' . $time_1month . '
- AND utimestamp < ' . $time_1week);
- if ($num_1month >= 0) {
- if ($num_1month > 0) {
- $num_1month = 0;
- $num_1month += (int) db_get_sql('SELECT COUNT(*)
- FROM tagente_datos
- WHERE utimestamp > ' . $time_1month);
- $num_1month += (int) db_get_sql('SELECT COUNT(*)
- FROM tagente_datos_string
- WHERE utimestamp > ' . $time_1month);
- $num_1month += (int) db_get_sql('SELECT COUNT(*)
- FROM tagente_datos_log4x
- WHERE utimestamp > ' . $time_1month);
- }
- // Data from 3 months ago
- $num_3months = 0;
- $num_3months += (int) db_get_sql('SELECT COUNT(*)
- FROM tagente_datos
- WHERE utimestamp > ' . $time_3months . '
- AND utimestamp < ' . $time_1month);
- $num_3months += (int) db_get_sql('SELECT COUNT(*)
- FROM tagente_datos
- WHERE utimestamp > ' . $time_3months . '
- AND utimestamp < ' . $time_1month);
- $num_3months += (int) db_get_sql('SELECT COUNT(*)
- FROM tagente_datos
- WHERE utimestamp > ' . $time_3months . '
- AND utimestamp < ' . $time_1month);
- if ($num_3months >= 0) {
- if ($num_3months > 0) {
- $num_3months = 0;
- $num_3months += (int) db_get_sql('SELECT COUNT(*)
- FROM tagente_datos
- WHERE utimestamp > ' . $time_3months);
- $num_3months += (int) db_get_sql('SELECT COUNT(*)
- FROM tagente_datos
- WHERE utimestamp > ' . $time_3months);
- $num_3months += (int) db_get_sql('SELECT COUNT(*)
- FROM tagente_datos
- WHERE utimestamp > ' . $time_3months);
- }
- // All data
- $num_all = 0;
- $num_all += (int) db_get_sql('SELECT COUNT(*)
- FROM tagente_datos
- WHERE utimestamp < ' . $time_3months);
- $num_all += (int) db_get_sql('SELECT COUNT(*)
- FROM tagente_datos
- WHERE utimestamp < ' . $time_3months);
- $num_all += (int) db_get_sql('SELECT COUNT(*)
- FROM tagente_datos
- WHERE utimestamp < ' . $time_3months);
- if ($num_all >= 0) {
- $num_older = $num_all - $num_3months;
- if ($config['history_db_enabled'] == 1) {
- // All data in common and history database
- $num_all_w_history = 0;
- $num_all_w_history += (int) db_get_sql('SELECT COUNT(*)
- FROM tagente_datos
- WHERE utimestamp < ' . $time_3months);
- $num_all_w_history += (int) db_get_sql('SELECT COUNT(*)
- FROM tagente_datos
- WHERE utimestamp < ' . $time_3months);
- $num_all_w_history += (int) db_get_sql('SELECT COUNT(*)
- FROM tagente_datos
- WHERE utimestamp < ' . $time_3months);
- if ($num_all_w_history >= 0) {
- $num_history = $num_all_w_history - $num_all;
- }
- }
- }
- }
- }
- }
- }
- else if (($num_1day == 0) && ($num_1week == 0) && ($num_1month == 0) && ($num_3months == 0) && ($num_all == 0)) {
- //If no data, returns empty
- $query_error = true;
- }
-
- // Error
- if ($query_error || $num_older < 0 || ($config['history_db_enabled'] == 1 && $num_history < 0)
- || (empty($num_1day) && empty($num_1week) && empty($num_1month)
- && empty($num_3months) && empty($num_all)
- && ($config['history_db_enabled'] == 1 && empty($num_all_w_history)))) {
- return html_print_image('images/image_problem_area_small.png', true);
- }
-
- // Data indexes
- $str_1day = __("Today");
- $str_1week = "1 ".__("Week");
- $str_1month = "1 ".__("Month");
- $str_3months = "3 ".__("Months");
- $str_older = "> 3 ".__("Months");
-
- // Filling the data array
- $data = array();
- if (!empty($num_1day))
- $data[$str_1day] = $num_1day;
- if (!empty($num_1week))
- $data[$str_1week] = $num_1week;
- if (!empty($num_1month))
- $data[$str_1month] = $num_1month;
- if (!empty($num_3months))
- $data[$str_3months] = $num_3months;
- if (!empty($num_older))
- $data[$str_older] = $num_older;
- if ($config['history_db_enabled'] == 1 && !empty($num_history)) {
- // In this pie chart only 5 elements are shown, so we need to remove
- // an element. With a history db enabled the >3 months element are dispensable
- if (count($data) >= 5 && isset($data[$str_3months]))
- unset($data[$str_3months]);
-
- $time_historic_db = time() - ((int)$config['history_db_days'] * SECONDS_1DAY);
- $date_human = human_time_comparation($time_historic_db);
- $str_history = "> $date_human (".__("History db").")";
- $data[$str_history] = $num_history;
- }
-
- $water_mark = array(
- 'file' => $config['homedir'] . "/images/logo_vertical_water.png",
- 'url' => ui_get_full_url("images/logo_vertical_water.png", false, false, false)
- );
-
- return pie3d_graph($config['flash_charts'], $data, $width, $height,
- __('Other'), '', $water_mark, $config['fontpath'], $config['font_size']);
-}
-
-/**
- * Print a horizontal bar graph with packets data of agents
- *
- * @param integer width pie graph width
- * @param integer height pie graph height
- */
-function grafico_db_agentes_paquetes($width = 380, $height = 300) {
- global $config;
- global $graphic_type;
-
-
- $data = array ();
- $legend = array ();
-
- $agents = agents_get_group_agents (array_keys (users_get_groups (false, 'RR')), false, "none");
- $count = agents_get_modules_data_count (array_keys ($agents));
- unset ($count["total"]);
- arsort ($count, SORT_NUMERIC);
- $count = array_slice ($count, 0, 8, true);
-
- foreach ($count as $agent_id => $value) {
- $data[$agents[$agent_id]]['g'] = $value;
- }
-
- if($config["fixed_graph"] == false){
- $water_mark = array('file' =>
- $config['homedir'] . "/images/logo_vertical_water.png",
- 'url' => ui_get_full_url("images/logo_vertical_water.png", false, false, false));
- }
-
- return hbar_graph($config['flash_charts'], $data, $width, $height, array(),
- $legend, "", "", true, "", $water_mark,
- $config['fontpath'], $config['font_size'], false, 1, $config['homeurl'],
- 'white',
- 'black');
-}
-
-/**
- * Print a horizontal bar graph with modules data of agents
- *
- * @param integer height graph height
- * @param integer width graph width
- */
-function graph_db_agentes_modulos($width, $height) {
- global $config;
- global $graphic_type;
-
-
- $data = array ();
-
- switch ($config['dbtype']) {
- case "mysql":
- case "postgresql":
- $modules = db_get_all_rows_sql ('
- SELECT COUNT(id_agente_modulo), id_agente
- FROM tagente_modulo
- WHERE delete_pending = 0
- GROUP BY id_agente
- ORDER BY 1 DESC LIMIT 10');
- break;
- case "oracle":
- $modules = db_get_all_rows_sql ('
- SELECT COUNT(id_agente_modulo), id_agente
- FROM tagente_modulo
- WHERE rownum <= 10
- AND delete_pending = 0
- GROUP BY id_agente
- ORDER BY 1 DESC');
- break;
- }
- if ($modules === false)
- $modules = array ();
-
- $data = array();
- foreach ($modules as $module) {
- $agent_name = agents_get_name ($module['id_agente'], "none");
-
- if (empty($agent_name)) {
- continue;
- }
- switch ($config['dbtype']) {
- case "mysql":
- case "postgresql":
- $data[$agent_name]['g'] = $module['COUNT(id_agente_modulo)'];
- break;
- case "oracle":
- $data[$agent_name]['g'] = $module['count(id_agente_modulo)'];
- break;
- }
- }
-
- if($config["fixed_graph"] == false){
- $water_mark = array('file' =>
- $config['homedir'] . "/images/logo_vertical_water.png",
- 'url' => ui_get_full_url("images/logo_vertical_water.png", false, false, false));
- }
-
- return hbar_graph($config['flash_charts'],
- $data, $width, $height, array(),
- array(), "", "", true, "",
- $water_mark,
- $config['fontpath'], $config['font_size'], false, 1, $config['homeurl'],
- 'white',
- 'black');
-}
-
-/**
- * Print a pie graph with users activity in a period of time
- *
- * @param integer width pie graph width
- * @param integer height pie graph height
- * @param integer period time period
- */
-function graphic_user_activity ($width = 350, $height = 230) {
- global $config;
- global $graphic_type;
-
- $data = array ();
- $max_items = 5;
- switch ($config['dbtype']) {
- case "mysql":
- case "postgresql":
- $sql = sprintf ('SELECT COUNT(id_usuario) n_incidents, id_usuario
- FROM tsesion
- GROUP BY id_usuario
- ORDER BY 1 DESC LIMIT %d', $max_items);
- break;
- case "oracle":
- $sql = sprintf ('SELECT COUNT(id_usuario) n_incidents, id_usuario
- FROM tsesion
- WHERE rownum <= %d
- GROUP BY id_usuario
- ORDER BY 1 DESC', $max_items);
- break;
- }
- $logins = db_get_all_rows_sql ($sql);
-
- if ($logins == false) {
- $logins = array();
- }
- foreach ($logins as $login) {
- $data[$login['id_usuario']] = $login['n_incidents'];
- }
-
- if($config["fixed_graph"] == false){
- $water_mark = array('file' =>
- $config['homedir'] . "/images/logo_vertical_water.png",
- 'url' => ui_get_full_url("images/logo_vertical_water.png", false, false, false));
- }
-
- return pie3d_graph($config['flash_charts'], $data, $width, $height,
- __('Other'), '', $water_mark,
- $config['fontpath'], $config['font_size']);
-}
-
/**
* Print a pie graph with priodity incident
*/
@@ -3425,70 +2846,6 @@ function grafico_eventos_grupo ($width = 300, $height = 200, $url = "", $meta =
$config['fontpath'], $config['font_size'], 1, 'bottom');
}
-function grafico_eventos_agente ($width = 300, $height = 200, $result = false, $meta = false, $history = false) {
- global $config;
- global $graphic_type;
-
- //It was urlencoded, so we urldecode it
- //$url = html_entity_decode (rawurldecode ($url), ENT_QUOTES);
- $data = array ();
- $loop = 0;
-
- if ($result === false) {
- $result = array();
- }
-
- $system_events = 0;
- $other_events = 0;
- $total = array();
- $i = 0;
-
- foreach ($result as $row) {
- if ($meta) {
- $count[] = $row["agent_name"];
- }
- else {
- if ($row["id_agente"] == 0) {
- $count[] = __('SYSTEM');
- }
- else
- $count[] = agents_get_alias($row["id_agente"]) ;
- }
-
- }
-
- $total = array_count_values($count);
-
- foreach ($total as $key => $total) {
- if ($meta) {
- $name = $key." (".$total.")";
- }
- else {
- $name = $key." (".$total.")";
- }
- $data[$name] = $total;
- }
-
- /*
- if ($other_events > 0) {
- $name = __('Other')." (".$other_events.")";
- $data[$name] = $other_events;
- }
- */
-
- // Sort the data
- arsort($data);
- if($config["fixed_graph"] == false){
- $water_mark = array('file' =>
- $config['homedir'] . "/images/logo_vertical_water.png",
- 'url' => ui_get_full_url("images/logo_vertical_water.png", false, false, false));
- }
-
- return pie3d_graph($config['flash_charts'], $data, $width, $height,
- __('Others'), '', $water_mark,
- $config['fontpath'], $config['font_size'], 1, 'bottom');
-}
-
/**
* Print a pie graph with events data in 320x200 size
*
@@ -3514,8 +2871,11 @@ function grafico_eventos_total($filter = "", $width = 320, $height = 200, $noWat
}
$sql = sprintf("SELECT criticity, COUNT(id_evento) events
- FROM tevento %s
- GROUP BY criticity ORDER BY events DESC", $where);
+ FROM tevento
+ LEFT JOIN tagent_secondary_group tasg
+ ON tevento.id_agente = tasg.id_agent
+ %s %s
+ GROUP BY criticity ORDER BY events DESC", $where , $filter);
$criticities = db_get_all_rows_sql ($sql, false, false);
@@ -4824,12 +4184,11 @@ function graph_monitor_wheel ($width = 550, $height = 600, $filter = false) {
if (!empty($agents)) {
$agents_id = array();
$agents_aux = array();
- foreach ($agents as $key => $agent) {
+ foreach ($agents as $key => $agent) {
$agents_aux[$agent['id_agente']] = $agent;
}
$agents = $agents_aux;
$agents_aux = null;
- $fields = array('id_agente_modulo', 'id_agente', 'id_module_group', 'nombre');
$module_groups = modules_get_modulegroups();
$module_groups[0] = __('Not assigned');
diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php
index 1349b6dadd..78cb1e8c96 100755
--- a/pandora_console/include/functions_modules.php
+++ b/pandora_console/include/functions_modules.php
@@ -142,14 +142,12 @@ function modules_copy_agent_module_to_agent ($id_agent_module, $id_destiny_agent
if ($forced_name !== false)
$module['nombre'] = $forced_name;
-
$modules = agents_get_modules ($id_destiny_agent, false,
array ('nombre' => $module['nombre'], 'disabled' => false));
// The module already exist in the target
if (! empty ($modules))
return array_pop (array_keys ($modules));
-
$modulesDisabled = agents_get_modules ($id_destiny_agent, false,
array ('nombre' => $module['nombre'], 'disabled' => true));
@@ -2782,33 +2780,38 @@ function modules_get_counter_by_states($state) {
return false;
}
-function modules_get_state_condition($state) {
+function modules_get_state_condition($state, $prefix = "tae") {
switch ($state) {
case AGENT_MODULE_STATUS_CRITICAL_ALERT:
case AGENT_MODULE_STATUS_CRITICAL_BAD:
return "(
- tae.estado = ".AGENT_MODULE_STATUS_CRITICAL_ALERT."
- OR tae.estado = ".AGENT_MODULE_STATUS_CRITICAL_BAD."
+ $prefix.estado = ".AGENT_MODULE_STATUS_CRITICAL_ALERT."
+ OR $prefix.estado = ".AGENT_MODULE_STATUS_CRITICAL_BAD."
)";
case AGENT_MODULE_STATUS_WARNING_ALERT:
case AGENT_MODULE_STATUS_WARNING:
return "(
- tae.estado = ".AGENT_MODULE_STATUS_WARNING_ALERT."
- OR tae.estado = ".AGENT_MODULE_STATUS_WARNING."
+ $prefix.estado = ".AGENT_MODULE_STATUS_WARNING_ALERT."
+ OR $prefix.estado = ".AGENT_MODULE_STATUS_WARNING."
)";
case AGENT_MODULE_STATUS_UNKNOWN:
- return "tae.estado = ".AGENT_MODULE_STATUS_UNKNOWN." ";
+ return "$prefix.estado = ".AGENT_MODULE_STATUS_UNKNOWN." ";
case AGENT_MODULE_STATUS_NO_DATA:
case AGENT_MODULE_STATUS_NOT_INIT:
return "(
- tae.estado = ".AGENT_MODULE_STATUS_NO_DATA."
- OR tae.estado = ".AGENT_MODULE_STATUS_NOT_INIT."
+ $prefix.estado = ".AGENT_MODULE_STATUS_NO_DATA."
+ OR $prefix.estado = ".AGENT_MODULE_STATUS_NOT_INIT."
)";
case AGENT_MODULE_STATUS_NORMAL_ALERT:
case AGENT_MODULE_STATUS_NORMAL:
return "(
- tae.estado = ".AGENT_MODULE_STATUS_NORMAL_ALERT."
- OR tae.estado = ".AGENT_MODULE_STATUS_NORMAL."
+ $prefix.estado = ".AGENT_MODULE_STATUS_NORMAL_ALERT."
+ OR $prefix.estado = ".AGENT_MODULE_STATUS_NORMAL."
+ )";
+ case AGENT_MODULE_STATUS_NOT_NORMAL:
+ return "(
+ $prefix.estado <> " . AGENT_MODULE_STATUS_NORMAL . "
+ AND $prefix.estado <> " . AGENT_MODULE_STATUS_NORMAL_ALERT . "
)";
}
// If the state is not an expected state, return no condition
diff --git a/pandora_console/include/functions_networkmap.php b/pandora_console/include/functions_networkmap.php
index eff9444824..35c0763c45 100644
--- a/pandora_console/include/functions_networkmap.php
+++ b/pandora_console/include/functions_networkmap.php
@@ -256,7 +256,7 @@ function networkmap_generate_dot ($pandora_name, $group = 0,
$relative = false, $text_filter = '', $ip_mask = null,
$dont_show_subgroups = false, $strict_user = false, $size_canvas = null,
$old_mode = false, $map_filter = array()) {
-
+
global $config;
$nooverlap = 1;
@@ -267,17 +267,8 @@ function networkmap_generate_dot ($pandora_name, $group = 0,
$filter['disabled'] = 0;
if (!empty($text_filter)) {
- switch ($config['dbtype']) {
- case "mysql":
- case "postgresql":
- $filter[] =
- '(nombre COLLATE utf8_general_ci LIKE "%' . $text_filter . '%")';
- break;
- case "oracle":
- $filter[] =
- '(upper(nombre) LIKE upper(\'%' . $text_filter . '%\'))';
- break;
- }
+ $filter[] =
+ '(nombre COLLATE utf8_general_ci LIKE "%' . $text_filter . '%")';
}
if ($group >= 1) {
@@ -301,33 +292,11 @@ function networkmap_generate_dot ($pandora_name, $group = 0,
//foreach loop are without parent (id_parent = 0)
// Get agents data
- if ($strict_user) {
- if ($dont_show_subgroups)
- $filter['id_group'] = $group;
- else {
- if (!empty($childrens)) {
- foreach ($childrens as $children) {
- $filter_id_groups[$children] = $children;
- }
- }
- $filter_id_groups[$group] = $group;
- $filter['id_group'] = implode(',', $filter_id_groups);
- }
-
- $filter['group_by'] = 'tagente.id_agente';
- $fields = array ('tagente.id_grupo, tagente.nombre, tagente.id_os, tagente.id_parent, tagente.id_agente,
- tagente.normal_count, tagente.warning_count, tagente.critical_count,
- tagente.unknown_count, tagente.total_count, tagente.notinit_count');
- $acltags = tags_get_user_groups_and_tags ($config['id_user'],'AR', $strict_user);
- $agents = tags_get_all_user_agents (false, $config['id_user'], $acltags, $filter, $fields, false, $strict_user, true);
- }
- else {
- $agents = agents_get_agents ($filter,
- array ('id_grupo, nombre, id_os, id_parent, id_agente,
- normal_count, warning_count, critical_count,
- unknown_count, total_count, notinit_count'), 'AR',
- array('field' => 'id_parent', 'order' => 'ASC'));
- }
+ $agents = agents_get_agents ($filter,
+ array ('id_grupo, nombre, id_os, id_parent, id_agente,
+ normal_count, warning_count, critical_count,
+ unknown_count, total_count, notinit_count'), 'AR',
+ array('field' => 'id_parent', 'order' => 'ASC'));
}
else if ($group == -666) {
$agents = false;
@@ -339,21 +308,11 @@ function networkmap_generate_dot ($pandora_name, $group = 0,
unknown_count, total_count, notinit_count'), $strict_user);
}
else {
- if ($strict_user) {
- $filter['group_by'] = 'tagente.id_agente';
- $fields = array ('tagente.id_grupo, tagente.nombre, tagente.id_os, tagente.id_parent, tagente.id_agente,
- tagente.normal_count, tagente.warning_count, tagente.critical_count,
- tagente.unknown_count, tagente.total_count, tagente.notinit_count');
- $acltags = tags_get_user_groups_and_tags ($config['id_user'],'AR', $strict_user);
- $agents = tags_get_all_user_agents (false, $config['id_user'], $acltags, $filter, $fields, false, $strict_user, true);
- }
- else {
- $agents = agents_get_agents ($filter,
- array ('id_grupo, nombre, id_os, id_parent, id_agente,
- normal_count, warning_count, critical_count,
- unknown_count, total_count, notinit_count'), 'AR',
- array('field' => 'id_parent', 'order' => 'ASC'));
- }
+ $agents = agents_get_agents ($filter,
+ array ('id_grupo, nombre, id_os, id_parent, id_agente,
+ normal_count, warning_count, critical_count,
+ unknown_count, total_count, notinit_count'), 'AR',
+ array('field' => 'id_parent', 'order' => 'ASC'));
}
if ($agents === false)
@@ -386,15 +345,10 @@ function networkmap_generate_dot ($pandora_name, $group = 0,
$filter = array();
$filter['disabled'] = 0;
-
+
// Get agent modules data
- if ($strict_user) {
- $modules = tags_get_agent_modules ($agent['id_agente'], false, $acltags, false, $filter, false);
- }
- else {
- $modules = agents_get_modules($agent['id_agente'], '*', $filter, true, true);
- }
-
+ $modules = agents_get_modules($agent['id_agente'], '*', $filter, true, true);
+
if ($modules === false)
$modules = array();
@@ -615,264 +569,6 @@ function networkmap_generate_dot ($pandora_name, $group = 0,
return $graph;
}
-// Generate a dot graph definition for graphviz with groups
-function networkmap_generate_dot_groups ($pandora_name, $group = 0,
- $simple = 0, $font_size = 12, $layout = 'radial', $nooverlap = 0,
- $zoom = 1, $ranksep = 2.5, $center = 0, $regen = 1, $pure = 0,
- $modwithalerts = 0, $module_group = 0, $hidepolicymodules = 0,
- $depth = 'all', $id_networkmap = 0, $dont_show_subgroups = 0,
- $text_filter = '', $strict_user = false, $size_canvas = null) {
-
- global $config;
-
- if ($strict_user) {
- $acltags = tags_get_user_groups_and_tags ($config['id_user'],'AR', $strict_user);
- }
- $parents = array();
- $orphans = array();
-
- $filter = array ();
- $filter['disabled'] = 0;
-
- if (!empty($text_filter)) {
- switch ($config['dbtype']) {
- case "mysql":
- case "postgresql":
- $filter[] =
- '(nombre COLLATE utf8_general_ci LIKE "%' . $text_filter . '%")';
- break;
- case "oracle":
- $filter[] =
- '(upper(nombre) LIKE upper(\'%' . $text_filter . '%\'))';
- break;
- }
- }
-
- // Get groups data
- if ($group > 0) {
- $groups = array();
- $id_groups = groups_get_id_recursive($group, true);
-
- foreach($id_groups as $id_group) {
- $add = false;
- if (check_acl($config["id_user"], $id_group, 'AR')) {
- $add = true;
- }
-
- if ($add) {
- $groups[] = db_get_row ('tgrupo', 'id_grupo', $id_group);
- }
- }
-
- $filter['id_grupo'] = $id_groups;
- }
- else {
- if ($strict_user) {
- $groups = users_get_groups ($config['id_user'],"AR", false, true);
- }
- else {
- $groups = db_get_all_rows_in_table ('tgrupo');
- }
- if ($groups === false) {
- $groups = array();
- }
- }
-
- // Open Graph
- $graph = networkmap_open_graph ($layout, $nooverlap, $pure, $zoom,
- $ranksep, $font_size, $size_canvas);
-
- $node_count = 0;
-
- // Parse groups
- $nodes = array ();
- $nodes_groups = array();
- foreach ($groups as $group2) {
- $node_count ++;
- $group2['type'] = 'group';
- $group2['id_node'] = $node_count;
-
- // Add node
- $nodes_groups[$group2['id_grupo']] = $group2;
- }
-
- $node_count = 0;
-
- $groups_hiden = array();
- foreach ($nodes_groups as $node_group) {
-
- $node_count++;
-
- // Save node parent information to define edges later
- if ($node_group['parent'] != "0" && $node_group['id_grupo'] != $group) {
- if ((!$dont_show_subgroups) || ($group == 0)) {
- $parents[$node_count] = $nodes_groups[$node_group['parent']]['id_node'];
- }
- else {
- $groups_hiden[$node_group['id_grupo']] = 1;
- continue;
- }
- }
- else {
- $orphans[$node_count] = 1;
- }
-
- $nodes[$node_count] = $node_group;
- }
-
- if ($depth != 'group') {
- if ($strict_user) {
- $filter['group_by'] = 'tagente.nombre';
- $filter['id_group'] = $filter['id_grupo'];
- $fields = array ('tagente.id_grupo, tagente.nombre, tagente.id_os, tagente.id_agente,
- tagente.normal_count, tagente.warning_count, tagente.critical_count,
- tagente.unknown_count, tagente.total_count, tagente.notinit_count');
- $agents = tags_get_all_user_agents (false, $config['id_user'], $acltags, $filter, $fields, false, $strict_user, true);
- unset($filter['id_group']);
- }
- else {
- // Get agents data
- $agents = agents_get_agents ($filter,
- array ('id_grupo, nombre, id_os, id_agente,
- normal_count, warning_count, critical_count,
- unknown_count, total_count, notinit_count'));
- }
- if ($agents === false)
- $agents = array();
-
- // Parse agents
- $nodes_agents = array();
- foreach ($agents as $agent) {
- if ($dont_show_subgroups) {
- if (!empty($groups_hiden[$agent['id_grupo']])) {
- continue;
- }
- }
-
- // If only agents with alerts => agents without alerts discarded
- $alert_agent = agents_get_alerts($agent['id_agente']);
-
- if ($modwithalerts and empty($alert_agent['simple'])) {
- continue;
- }
-
- $node_count ++;
- // Save node parent information to define edges later
- $parents[$node_count] = $agent['parent'] = $nodes_groups[$agent['id_grupo']]['id_node'];
-
- $agent['id_node'] = $node_count;
- $agent['type'] = 'agent';
- // Add node
- $nodes[$node_count] = $nodes_agents[$agent['id_agente']] = $agent;
-
- if ($depth == 'agent') {
- continue;
- }
-
- // Get agent modules data
- if ($strict_user) {
- $filter['disabled'] = 0;
- $modules = tags_get_agent_modules ($agent['id_agente'], false, $acltags, false, $filter, false);
- } else {
- $modules = agents_get_modules ($agent['id_agente'], false, array('disabled' => 0), true, false);
- }
-
- // Parse modules
- foreach ($modules as $key => $module) {
- $node_count ++;
- $agent_module = modules_get_agentmodule($key);
- $alerts_module = db_get_sql('SELECT count(*) AS num
- FROM talert_template_modules
- WHERE id_agent_module = ' . $key);
-
- if ($alerts_module == 0 && $modwithalerts) {
- continue;
- }
-
- if ($agent_module['id_module_group'] != $module_group &&
- $module_group != 0) {
- continue;
- }
-
- if ($hidepolicymodules && $config['enterprise_installed']) {
- enterprise_include_once('include/functions_policies.php');
- if (policies_is_module_in_policy($key)) {
- continue;
- }
- }
-
- // Save node parent information to define edges later
- $parents[$node_count] = $agent_module['parent'] = $agent['id_node'];
-
- $agent_module['id_node'] = $node_count;
-
- $agent_module['type'] = 'module';
- // Add node
- $nodes[$node_count] = $agent_module;
- }
- }
- }
-
- if (empty ($nodes)) {
- return false;
- }
-
- // Create void statistics array
- $stats = array();
-
- // Create nodes
- foreach ($nodes as $node_id => $node) {
- if ($center > 0 && ! networkmap_is_descendant ($node_id, $center, $parents)) {
- unset ($parents[$node_id]);
- unset ($orphans[$node_id]);
- unset ($nodes[$node_id]);
- continue;
- }
- switch ($node['type']) {
- case 'group':
- $graph .= networkmap_create_group_node ($node , $simple, $font_size, $metaconsole = false, null, $strict_user) .
- "\n\t\t";
- $stats['groups'][] = $node['id_grupo'];
- break;
- case 'agent':
- $graph .= networkmap_create_agent_node ($node , $simple, $font_size, true, true) .
- "\n\t\t";
- $stats['agents'][] = $node['id_agente'];
- break;
- case 'module':
- $graph .= networkmap_create_module_node ($node , $simple, $font_size) .
- "\n\t\t";
- $stats['modules'][] = $node['id_agente_modulo'];
- break;
- }
- }
- // Define edges
- foreach ($parents as $node => $parent_id) {
- // Verify that the parent is in the graph
- if (isset ($nodes[$parent_id])) {
- $graph .= networkmap_create_edge ($node, $parent_id, $layout, $nooverlap, $pure, $zoom, $ranksep, $simple, $regen, $font_size, $group, 'operation/agentes/networkmap', 'groups', $id_networkmap);
- }
- else {
- $orphans[$node] = 1;
- }
- }
-
- // Create a central node if orphan nodes exist
- if (count ($orphans)) {
- $graph .= networkmap_create_pandora_node ($pandora_name, $font_size, $simple, $stats);
- }
-
- // Define edges for orphan nodes
- foreach (array_keys($orphans) as $node) {
- $graph .= networkmap_create_edge ('0', $node, $layout, $nooverlap, $pure, $zoom, $ranksep, $simple, $regen, $font_size, $group, 'operation/agentes/networkmap', 'groups', $id_networkmap);
- }
-
- // Close graph
- $graph .= networkmap_close_graph ();
-
- return $graph;
-}
-
// Returns an edge definition
function networkmap_create_edge ($head, $tail, $layout, $nooverlap, $pure, $zoom, $ranksep, $simple, $regen, $font_size, $group, $sec2 = 'operation/agentes/networkmap', $tab = 'topology', $id_networkmap = 0) {
if (defined("METACONSOLE")) {
diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php
index 1f019934e9..668e576c64 100755
--- a/pandora_console/include/functions_reporting.php
+++ b/pandora_console/include/functions_reporting.php
@@ -1800,7 +1800,6 @@ function reporting_agent_module($report, $content) {
$row = array();
$row['agent_status'][$agent] = agents_get_status($agent);
$row['agent_name'] = agents_get_alias($agent);
-
$agent_modules = agents_get_modules($agent);
$row['modules'] = array();
@@ -3079,7 +3078,6 @@ function reporting_alert_report_agent($report, $content) {
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text($report, $content);
$return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : '';
-
$module_list = agents_get_modules($content['id_agent']);
$data = array();
@@ -3669,7 +3667,6 @@ function reporting_agent_configuration($report, $content) {
$agent_configuration['description'] = $agent_data['comentarios'];
$agent_configuration['enabled'] = (int)!$agent_data['disabled'];
$agent_configuration['group'] = $report["group"];
-
$modules = agents_get_modules ($content['id_agent']);
$agent_configuration['modules'] = array();
@@ -8293,11 +8290,10 @@ function reporting_get_agentmodule_ttr ($id_agent_module, $period = 0, $date = 0
* Get a detailed report of the modules of the agent
*
* @param int $id_agent Agent id to get the report for.
- * @param string $filter filter for get partial modules.
*
* @return array An array
*/
-function reporting_get_agent_module_info ($id_agent, $filter = false) {
+function reporting_get_agent_module_info ($id_agent) {
global $config;
$return = array ();
@@ -8313,12 +8309,7 @@ function reporting_get_agent_module_info ($id_agent, $filter = false) {
return $return;
}
- if ($filter != '') {
- $filter = 'AND ';
- }
-
- $filter = 'disabled = 0';
-
+ $filter = array('disabled' => 0);
$modules = agents_get_modules($id_agent, false, $filter, true, false);
if ($modules === false) {
@@ -8416,33 +8407,6 @@ function reporting_tiny_stats ($counts_info, $return = false, $type = 'agent', $
break;
}
- if ($strict_user && $type == 'agent') {
-
- $acltags = tags_get_user_groups_and_tags ($config['id_user'],'AR', $strict_user);
- $filter['disabled'] = 0;
- $id_agent = $counts_info['id_agente'];
-
- $counts_info = array();
- $counts_info['normal_count'] = count(tags_get_agent_modules ($id_agent, false, $acltags, false, $filter, false, AGENT_MODULE_STATUS_NORMAL));
- $counts_info['warning_count'] = count(tags_get_agent_modules ($id_agent, false, $acltags, false, $filter, false, AGENT_MODULE_STATUS_WARNING));
- $counts_info['critical_count'] = count(tags_get_agent_modules ($id_agent, false, $acltags, false, $filter, false, AGENT_MODULE_STATUS_CRITICAL_BAD));
- $counts_info['notinit_count'] = count(tags_get_agent_modules ($id_agent, false, $acltags, false, $filter, false, AGENT_MODULE_STATUS_NOT_INIT));
- $counts_info['unknown_count'] = count(tags_get_agent_modules ($id_agent, false, $acltags, false, $filter, false, AGENT_MODULE_STATUS_UNKNOWN));
- $counts_info['total_count'] = $counts_info['normal_count'] + $counts_info['warning_count'] + $counts_info['critical_count'] + $counts_info['unknown_count'] + $counts_info['notinit_count'];
-
- $all_agent_modules = tags_get_agent_modules ($id_agent, false, $acltags, false, $filter);
- if (!empty($all_agent_modules)) {
- $mod_clause = "(".implode(',', array_keys($all_agent_modules)).")";
-
- $counts_info['fired_count'] = (int) db_get_sql ("SELECT COUNT(times_fired)
- FROM talert_template_modules
- WHERE times_fired != 0 AND id_agent_module IN ".$mod_clause);
- }
- else {
- $counts_info['fired_count'] = 0;
- }
- }
-
// Store the counts in a data structure to print hidden divs with titles
$stats = array();
diff --git a/pandora_console/include/functions_tags.php b/pandora_console/include/functions_tags.php
index ba031c0cff..b10457cc5e 100644
--- a/pandora_console/include/functions_tags.php
+++ b/pandora_console/include/functions_tags.php
@@ -192,11 +192,13 @@ function tags_get_modules_count ($id) {
* @return int Local module tag's count.
*/
function tags_get_local_modules_count ($id) {
- $field = 'COUNT(id_tag)';
+ $field = 'COUNT(DISTINCT(tagente_modulo.id_agente_modulo))';
$filter = array('id_tag' => $id);
-
- $num_modules = (int) db_get_value_filter($field, 'ttag_module', $filter);
-
+ $num_modules = (int) db_get_value_filter(
+ $field,
+ 'ttag_module INNER JOIN tagente_modulo ON ttag_module.id_agente_modulo = tagente_modulo.id_agente_modulo',
+ $filter
+ );
return $num_modules;
}
@@ -457,7 +459,7 @@ function tags_get_module_tags ($id, $policy = false) {
$tags = db_get_all_rows_filter('ttag_module',
array('id_agente_modulo' => $id), false);
}
-
+
if ($tags === false)
return array();
@@ -722,124 +724,37 @@ function tags_get_acl_tags_module_condition($acltags, $modules_table = '') {
$condition = '';
$group_conditions = array();
-
+
+ $without_tags = array();
+ $has_secondary = enterprise_hook('agents_is_using_secondary_groups');
// The acltags array contains the groups with the acl propagation applied
// after the changes done into the 'tags_get_user_groups_and_tags' function.
foreach ($acltags as $group_id => $group_tags) {
$tag_join = '';
if (!empty($group_tags)) {
- $tag_join = sprintf('INNER JOIN ttag_module ttmc
- ON tamc.id_agente_modulo = ttmc.id_agente_modulo
- AND ttmc.id_tag IN (%s)',
- is_array($group_tags) ? implode(',', $group_tags) : $group_tags);
+ $tag_join = sprintf('AND ttag_module.id_tag IN (%s)',is_array($group_tags) ? implode(',', $group_tags) : $group_tags);
+ if($has_secondary){
+ $agent_condition = sprintf('((tagente.id_grupo = %d OR tasg.id_group = %d) %s)',$group_id,$group_id,$tag_join);
+ } else {
+ $agent_condition = sprintf('((tagente.id_grupo = %d %s))',$group_id,$tag_join);
+ }
+ $group_conditions[] = $agent_condition;
+ } else {
+ $without_tags[] = $group_id;
}
- // FIXME: Not properly way to increse performance
- if(enterprise_hook('agents_is_using_secondary_groups')){
- $agent_condition = sprintf('SELECT tamc.id_agente_modulo
- FROM tagente_modulo tamc
- %s
- INNER JOIN tagente tac
- ON tamc.id_agente = tac.id_agente
- LEFT JOIN tagent_secondary_group tasg
- ON tasg.id_agent = tac.id_agente
- WHERE (tac.id_grupo = %d OR tasg.id_group = %d)',
- $tag_join, $group_id, $group_id);
- }
- else{
- $agent_condition = sprintf('SELECT tamc.id_agente_modulo
- FROM tagente_modulo tamc
- %s
- INNER JOIN tagente tac
- ON tamc.id_agente = tac.id_agente
- AND tac.id_grupo = %d',
- $tag_join, $group_id);
- }
-
- $sql_condition = sprintf('(%sid_agente_modulo IN (%s))', $modules_table, $agent_condition);
-
- $group_conditions[] = $sql_condition;
-
- $i++;
}
- if (!empty($group_conditions))
+ if (!empty($group_conditions)) {
$condition = implode(' OR ', $group_conditions);
- $condition = !empty($condition) ? "($condition)" : '';
-
- return $condition;
-}
-
-// The old function will be keeped to serve as reference of the changes done
-/**
- * Transform the acl_groups data into a SQL condition
- *
- * @param mixed acl_groups data calculated in tags_get_acl_tags function
- *
- * @return string SQL condition for tagente_module
- */
-function tags_get_acl_tags_module_condition_old($acltags, $modules_table = '') {
- if (!empty($modules_table)) {
- $modules_table .= '.';
}
-
- $condition = '';
-
- // Fix: Wrap SQL expression with "()" to avoid bad SQL sintax that makes Pandora retrieve all modules without taking care of id_agent => id_agent = X AND (sql_tag_expression)
- $i = 0;
- foreach ($acltags as $group_id => $group_tags) {
- if ($condition != '') {
+ if (!empty($without_tags)) {
+ if (!empty($condition)) {
$condition .= ' OR ';
}
-
- // Fix: Wrap SQL expression with "()" to avoid bad SQL sintax that makes Pandora retrieve all modules without taking care of id_agent => id_agent = X AND (sql_tag_expression)
- if ($i == 0)
- $condition .= ' ( ' . "\n";
-
- // Group condition (The module belongs to an agent of the group X)
- // Juanma (08/05/2014) Fix: Now group and tag is checked at the same time, before only tag was checked due to a bad condition
- if (!array_key_exists(0, $acltags)) {
- // Juanma (08/05/2014) Fix: get all groups recursively (Acl proc func!)
- $group_condition = sprintf('%sid_agente IN (SELECT id_agente FROM tagente WHERE id_grupo IN (%s))', $modules_table, implode(',', array_values(groups_get_id_recursive($group_id))));
- }
- else {
- //Avoid the user profiles with all group access.
- $group_condition = " 1 = 1 ";
- }
-
- //When the acl is only group without tags
- if (empty($group_tags)) {
- $condition .= "($group_condition)\n";
- }
- else {
- if (is_array($group_tags)) {
- $group_tags_query = implode(',',$group_tags);
- } else {
- $group_tags_query = $group_tags;
- }
- // Tags condition (The module has at least one of the restricted tags)
- $tags_condition = sprintf('%sid_agente_modulo IN (SELECT id_agente_modulo FROM ttag_module WHERE id_tag IN (%s))', $modules_table, $group_tags_query);
-
- $condition .=
- " ( \n" .
- " $group_condition \n" .
- " AND \n" .
- " $tags_condition \n" .
- " )\n";
- }
-
- $i++;
- }
-
- // Fix: Wrap SQL expression with "()" to avoid bad SQL sintax that makes Pandora retrieve all modules without taking care of id_agent => id_agent = X AND (sql_tag_expression)
- if (!empty($acltags))
- $condition .= ' ) ';
-
- //Avoid the user profiles with all group access.
- //if (!empty($condition)) {
- if (!empty($condition) &&
- !array_key_exists(0, array_keys($acltags))) {
- $condition = sprintf("\n((%s) OR %sid_agente NOT IN (SELECT id_agente FROM tagente WHERE id_grupo IN (%s)))", $condition, $modules_table, implode(',',array_keys($acltags)));
+ $in_group = implode(",",$without_tags);
+ $condition .= sprintf('(tagente.id_grupo IN (%s) OR tasg.id_group IN (%s))',$in_group,$in_group);
}
+ $condition = !empty($condition) ? "($condition)" : '';
return $condition;
}
@@ -859,102 +774,54 @@ function tags_get_acl_tags_event_condition($acltags, $meta = false, $force_group
// Get all tags of the system
$all_tags = tags_get_all_tags(false);
-
- // Juanma (08/05/2014) Fix : Will have all groups retrieved (also propagated ones)
- $_groups_not_in = '';
+ $without_tags = array();
foreach ($acltags as $group_id => $group_tags) {
- // Group condition (The module belongs to an agent of the group X)
- $group_condition = sprintf('id_grupo IN (%s)', implode(',', array_values(groups_get_id_recursive($group_id, true))));
- //$_groups_not_in .= implode(',', array_values(groups_get_id_recursive($group_id))) . ',';
-
- // Tags condition (The module has at least one of the restricted tags)
- $tags_condition = '';
+ // NO check if there is not tag associated with groups
if (empty($group_tags)) {
- // FIXME: Not properly way to increse performance
- if(enterprise_hook('agents_is_using_secondary_groups')){
- $tags_condition = "id_grupo = ".$group_id . " OR id_group = " . $group_id;
- }
- else{
- $tags_condition = "id_grupo = ".$group_id;
- }
- }
- else {
- if (!is_array($group_tags)) {
- $group_tags = explode(',', $group_tags);
- }
-
- foreach ($group_tags as $tag) {
- // If the tag ID doesnt exist, ignore
- if (!isset($all_tags[$tag])) {
- continue;
- }
-
- if ($tags_condition != '') {
- $tags_condition .= " OR \n";
- }
-
- //~ // Add as condition all the posibilities of the serialized tags
- //~ $tags_condition .= sprintf('tags LIKE "%s,%%"',io_safe_input($all_tags[$tag]));
- //~ $tags_condition .= sprintf(' OR tags LIKE "%%,%s,%%"',io_safe_input($all_tags[$tag]));
- //~ $tags_condition .= sprintf(' OR tags LIKE "%%,%s"',io_safe_input($all_tags[$tag]));
- //~ $tags_condition .= sprintf(' OR tags LIKE "%s %%"',io_safe_input($all_tags[$tag]));
- //~ $tags_condition .= sprintf(' OR tags LIKE "%%,%s %%"',io_safe_input($all_tags[$tag]));
-
- if ($force_group_and_tag) {
- if (!empty($all_tags[$tag])) {
- if ($force_equal) {
- $tags_condition .= sprintf('(tags = "%s"',io_safe_input($all_tags[$tag]));
- } else {
- $tags_condition .= "(tags LIKE '%".io_safe_input($all_tags[$tag])."%'";
- }
- $childrens = groups_get_childrens($group_id, null, true);
-
- if (empty($childrens)) {
- $tags_condition .= sprintf(' AND id_grupo = %d )', $group_id);
- } else {
- $childrens_ids[] = $group_id;
- foreach ($childrens as $child) {
- $childrens_ids[] = (int)$child['id_grupo'];
- }
- $ids_str = implode(',', $childrens_ids);
-
- $tags_condition .= sprintf(' AND id_grupo IN (%s) )', $ids_str);
- }
- } else {
- $tags_condition .= "id_grupo = ".$group_id;
- }
- } else {
- if ($force_equal) {
- $tags_condition .= sprintf('tags = "%s"',io_safe_input($all_tags[$tag]));
- } else {
- $tags_condition .= "tags LIKE '%".io_safe_input($all_tags[$tag])."%'";
- }
- }
- }
- }
-
- // If there is not tag condition ignore
- if (empty($tags_condition)) {
+ $without_tags []= $group_id;
continue;
}
-
- if ($condition != '') {
- $condition .= ' OR ';
+
+ // Group condition (The module belongs to an agent of the group X)
+ //$group_condition = sprintf('id_grupo IN (%s)', implode(',', array_values(groups_get_id_recursive($group_id, true))));
+ $group_condition = "(id_grupo = $group_id OR id_group = $group_id)";
+
+ // Tags condition (The module has at least one of the restricted tags)
+ $tags_condition = '';
+ $tags_condition_array = array();
+
+ foreach ($group_tags as $tag) {
+ // If the tag ID doesnt exist, ignore
+ if (!isset($all_tags[$tag])) continue;
+
+ $tags_condition_array[] = $force_equal
+ ? sprintf('tags = "%s"',io_safe_input($all_tags[$tag]))
+ : "tags LIKE '%".io_safe_input($all_tags[$tag])."%'";
}
- $condition .= "($tags_condition)\n";
+ // If there is not tag currently in Pandora, block the group info
+ if (empty($tags_condition_array)) {
+ $tags_condition_array[] = "1=0";
+ }
+
+ $tags_condition = $group_condition . " AND (" . implode(" OR ", $tags_condition_array) . ")";
+ $condition[] = "($tags_condition)\n";
}
-
- //Commented because ACLs propagation don't work
-/*
if (!empty($condition)) {
- // Juanma (08/05/2014) Fix : Also add events of other groups (taking care of propagate ACLs func!)
- if (!empty($_groups_not_in))
- $condition = sprintf("\n((%s) OR id_grupo NOT IN (%s))", $condition, rtrim($_groups_not_in, ','));
+ $condition = implode(' OR ', $condition);
}
-*/
-
+
+ if (!empty($without_tags)) {
+ if (!empty($condition)) {
+ $condition .= ' OR ';
+ }
+ $in_group = implode(",",$without_tags);
+ $condition .= sprintf('(id_grupo IN (%s) OR id_group IN (%s))',$in_group,$in_group);
+ }
+
+ $condition = !empty($condition) ? "($condition)" : '';
+
return $condition;
}
@@ -975,15 +842,14 @@ function tags_has_user_acl_tags($id_user = false) {
if(is_user_admin($id_user)) {
return false;
}
-
- $query = sprintf("SELECT count(*)
- FROM tusuario_perfil, tperfil
- WHERE tperfil.id_perfil = tusuario_perfil.id_perfil AND
- tusuario_perfil.id_usuario = '%s' AND tags != ''",
- $id_user);
-
+
+ $query = "SELECT count(*)
+ FROM tusuario_perfil
+ WHERE tusuario_perfil.id_usuario = '$id_user'
+ AND tags != '' AND tags !='0'";
+
$user_tags = db_get_value_sql($query);
-
+
return (bool)$user_tags;
}
@@ -1150,7 +1016,7 @@ function tags_get_tags_for_module_search($id_user = false, $access = 'AR') {
//--------------------------------------------------------------
return false;
}
- // Get the tags of the required access flag for each group
+ // Get the tags of the required access flag for each group
$tags = tags_get_acl_tags($id_user, 0, $access, 'data');
// If there are wrong parameters or fail ACL check, return false
if ($tags_user === ERR_WRONG_PARAMETERS || $tags_user === ERR_ACL) {
@@ -1186,252 +1052,27 @@ function tags_check_acl_by_module($id_module = 0, $id_user = false,
$access = 'AW') {
global $config;
- $return = false;
-
- if (!empty($id_module)) {
- $tags = tags_get_module_tags($id_module);
- $groups = modules_get_agent_groups($id_module);
-
- if ($id_user === false) {
- $id_user = $config["id_user"];
- }
-
- foreach ($groups as $group) {
- if (tags_check_acl($id_user, $group, $access, $tags, true)) {
- return true;
- }
- }
- }
-
- return $return;
-}
-
-/**
- * Check the ACLs with tags
- *
- * @param string ID of the user (with false the user will be taked from config)
- * @param string id of the group (0 means for at least one)
- * @param string access flag (AR,AW...)
- * @param mixed tags to be checked (array() means for at least one)
- *
- * @return bool true if the acl check has success, false otherwise
- */
-function tags_check_acl($id_user, $id_group, $access, $tags = array(), $flag_id_tag = false) {
- global $config;
-
+ if (empty($id_module)) return false;
if ($id_user === false) {
- $id_user = $config['id_user'];
+ $id_user = $config["id_user"];
}
-
- // Get parents to check in propagate ACL cases
- if (!is_array($id_group) && $id_group != 0) {
- $id_group = array($id_group);
- $group = db_get_row_filter('tgrupo',
- array('id_grupo' => $id_group));
- $parents = groups_get_parents($group['parent'], true);
-
- foreach ($parents as $parent) {
- $id_group[] = $parent['id_grupo'];
- }
- }
-
- $acls = tags_get_acl_tags($id_user, $id_group, $access, 'data');
-
- // If there are wrong parameters or fail ACL check, return false
- if ($acls === ERR_WRONG_PARAMETERS || $acls === ERR_ACL) {
- return false;
- }
-
- // If there are not tags restrictions or tags passed, check the group access
- if (empty($acls) || empty($tags)) {
- if (!is_array($id_group))
- $group_id_array = array($id_group);
-
- foreach ($id_group as $group) {
- if (check_acl($id_user, $group, $access))
- return true;
- }
- }
-
- # Fix: If user profile has more than one group, due to ACL propagation then id_group can be an array
- if (is_array($id_group)) {
-
- foreach ($id_group as $group) {
- if ($group > 0) {
- if (array_key_exists(0, $acls)) {
- //There is a All group
-
- foreach ($tags as $tag) {
- if (in_array($tag, $acls[0])) {
- return true;
- }
- else {
- return false;
- }
- }
- }
- else if (isset($acls[$group])) {
- foreach ($tags as $tag) {
- if (!$flag_id_tag)
- $tag = tags_get_id($tag);
-
- if (in_array($tag, $acls[$group])) {
- return true;
- } else if (empty($acls[$group])) {
- return true;
- }
- }
- }
- else {
- return false;
- }
- }
- else {
-
- foreach ($acls as $acl_tags) {
- foreach ($tags as $tag) {
- if (!$flag_id_tag)
- $tag = tags_get_id($tag);
-
- if (in_array($tag, $acl_tags)) {
- return true;
- }
- }
- }
- }
- }
- }
- else {
- if ($id_group > 0) {
- if (isset($acls[$id_group])) {
- foreach ($tags as $tag) {
- if (!$flag_id_tag)
- $tag = tags_get_id($tag);
-
- if (in_array($tag, $acls[$id_group])) {
- return true;
- }
- }
- }
- else {
- return false;
- }
- }
- else {
- foreach ($acls as $acl_tags) {
- foreach ($tags as $tag) {
- if (!$flag_id_tag)
- $tag = tags_get_id($tag);
-
- if (in_array($tag, $acl_tags)) {
- return true;
- }
- }
- }
- }
- }
-
- return false;
-}
-function tags_check_acl_event($id_user, $id_group, $access, $tags = array(),$p = false) {
- global $config;
-
- if($id_user === false) {
- $id_user = $config['id_user'];
- }
-
- $acls = tags_get_acl_tags($id_user, $id_group, $access, 'data');
-
- // If there are wrong parameters or fail ACL check, return false
- if($acls === ERR_WRONG_PARAMETERS || $acls === ERR_ACL) {
- return false;
- }
-
- // If there are not tags restrictions or tags passed, check the group access
- if (empty($acls) || empty($tags)) {
- if (!is_array($id_group))
- $group_id_array = array($id_group);
-
- foreach ($id_group as $group) {
- if (check_acl($id_user, $group, $access))
- return true;
- }
- }
-
- # Fix: If user profile has more than one group, due to ACL propagation then id_group can be an array
- if (is_array($id_group)) {
-
- foreach ($id_group as $group) {
- if ($group > 0) {
- if (isset($acls[$group])) {
- foreach ($tags as $tag) {
- $tag = tags_get_id($tag);
- if (in_array($tag, $acls[$group])) {
- return true;
- }
- }
- }
- else {
- //return false;
- $return = false;
- }
- }
- else {
- foreach ($acls as $acl_tags) {
- foreach ($tags as $tag) {
- $tag = tags_get_id($tag);
- if (in_array($tag, $acl_tags)) {
- return true;
- }
- }
- }
- }
-
- }
-
- }
- else {
- if ($id_group > 0) {
- if (isset($acls[$id_group])) {
- foreach ($tags as $tag) {
- $tag = tags_get_id($tag);
-
- if (in_array($tag, $acls[$id_group])) {
- return true;
- }
- }
- }
- else {
- //return false;
- $return = false;
- }
- }
- else {
- foreach ($acls as $acl_tags) {
- foreach ($tags as $tag) {
- $tag = tags_get_id($tag);
- if (in_array($tag, $acl_tags)) {
- return true;
- }
- }
- }
- }
- }
- //return false;
- $return = false;
-
- if ($return == false) {
- $parent = db_get_value('parent','tgrupo','id_grupo',$id_group);
-
- if ($parent !== 0) {
- $propagate = db_get_value('propagate','tgrupo','id_grupo',$parent);
- if ($propagate == 1) {
- $acl_parent = tags_check_acl_event($id_user, $parent, $access, $tags,$p);
- return $acl_parent;
- }
- }
+ $tags = tags_get_module_tags($id_module);
+ $groups = modules_get_agent_groups($id_module);
+ $user_groups = users_get_groups($id_user, $acces, false, true);
+
+ $acl_column = get_acl_column($access);
+ foreach ($groups as $group) {
+ // If user has not permission for this group,go to next group
+ if (!isset($user_groups[$group])) continue;
+ // No tags means user can see all tags for this group
+ if (!isset($user_groups[$group]["tags"][$acl_column])) return true;
+ // Check acl
+ $intersection = array_intersect($tags, $user_groups[$group]["tags"][$acl_column]);
+ if(!empty($intersection)) return true;
}
+
+ return false;
}
/* This function checks event ACLs */
@@ -2446,7 +2087,9 @@ function tags_get_user_groups_and_tags ($id_user = false, $access = 'AR', $stric
$return = array();
foreach ($acls as $acl) {
- $return[$acl["id_grupo"]] = $acl["tags"];
+ $return[$acl["id_grupo"]] = isset($acl["tags"][get_acl_column($access)])
+ ? implode(",",$acl["tags"][get_acl_column($access)])
+ : "";
}
return $return;
@@ -2701,4 +2344,41 @@ function tags_get_module_policy_tags($id_tag, $id_module) {
return $id_module_policy;
}
+
+/**
+ * Get all tags configured to user associated to the agent.
+ *
+ * @param int $id_agent Agent to extract tags
+ * @param string $access Access to check
+ *
+ * @return mixed
+ * false if user has not permission on agent groups
+ * true if there is not any tag restriction
+ * array with all tags if there are tags configured
+ */
+function tags_get_user_applied_agent_tags ($id_agent, $access = "AR") {
+ global $config;
+
+ $agent_groups = agents_get_all_groups_agent($id_agent);
+ $user_groups = users_get_groups(false, 'AR', false, true);
+ // Check global agent permissions
+ if (!check_acl_one_of_groups($config['id_user'], $agent_groups, $access)) {
+ return false;
+ }
+
+ $acl_column = get_acl_column($access);
+ $tags = array();
+ foreach ($agent_groups as $group) {
+ // If user has not permission to a single group, continue
+ if (!isset($user_groups[$group])) continue;
+ $group_tags = $user_groups[$group]["tags"][$acl_column];
+ if (!empty($group_tags)) {
+ $tags = array_merge($tags, $group_tags);
+ } else {
+ // If an agent
+ return true;
+ }
+ }
+ return empty($tags) ? true : $tags;
+}
?>
diff --git a/pandora_console/include/functions_treeview.php b/pandora_console/include/functions_treeview.php
index 20d1f577bc..2f2e899143 100755
--- a/pandora_console/include/functions_treeview.php
+++ b/pandora_console/include/functions_treeview.php
@@ -745,16 +745,7 @@ function treeview_printTable($id_agente, $server_data = array(), $no_head = fals
foreach ($network_interfaces as $interface_name => $interface) {
if (!empty($interface['traffic'])) {
- $permission = false;
-
- if ($strict_user) {
- if (tags_check_acl_by_module($interface['traffic']['in'], $config['id_user'], 'RR') === true
- && tags_check_acl_by_module($interface['traffic']['out'], $config['id_user'], 'RR') === true)
- $permission = true;
- }
- else {
- $permission = check_acl($config['id_user'], $agent["id_grupo"], "RR");
- }
+ $permission = check_acl($config['id_user'], $agent["id_grupo"], "RR");
if ($permission) {
$params = array(
diff --git a/pandora_console/include/functions_users.php b/pandora_console/include/functions_users.php
index 43603663a1..e368a52b4a 100755
--- a/pandora_console/include/functions_users.php
+++ b/pandora_console/include/functions_users.php
@@ -208,23 +208,13 @@ function groups_combine_acl($acl_group_a, $acl_group_b){
"tags" => 1,
);
+ foreach ($acl_group_a['tags'] as $key => $value) {
+ $acl_group_b['tags'][$key] = array_merge($value, $acl_group_b['tags'][$key]);
+ }
+
foreach ($acl_list as $acl => $aux) {
- if($acl == "tags") {
- // Mix tags
-
- if (isset($acl_group_a[$acl]) && ($acl_group_a[$acl] != "")) {
- if (isset($acl_group_b[$acl]) && ($acl_group_b[$acl] != "")) {
- if ($acl_group_b[$acl] != ($acl_group_a[$acl])) {
- $acl_group_b[$acl] = $acl_group_a[$acl] . "," . $acl_group_b[$acl];
- }
- }
- else {
- $acl_group_b[$acl] = $acl_group_a[$acl];
- }
- }
- continue;
- }
+ if($acl == "tags") continue;
// propagate ACL
$acl_group_b[$acl] = $acl_group_a[$acl] || $acl_group_b[$acl];
}
@@ -286,6 +276,8 @@ function users_get_groups ($id_user = false, $privilege = "AR", $returnAllGroup
foreach ($raw_forest as $g) {
// XXX, following code must be remade (TAG)
+ users_get_explode_tags($g);
+
if (!isset($forest_acl[$g["id_grupo"]] )) {
$forest_acl[$g["id_grupo"]] = $g;
}
@@ -314,6 +306,7 @@ function users_get_groups ($id_user = false, $privilege = "AR", $returnAllGroup
}
else {
// add group to user ACL forest
+ users_get_explode_tags($group);
$tmp = groups_combine_acl($forest_acl[$parent], $group);
}
if ($tmp !== null) {
@@ -1069,4 +1062,27 @@ function users_get_strict_mode_groups($id_user, $return_group_all) {
return $return_user_groups;
}
+function users_get_explode_tags(&$group) {
+
+ if (empty($group['tags'])) {
+ $group['tags'] = array();
+ $group['tags']['agent_view'] = array();
+ $group['tags']['agent_edit'] = array();
+ $group['tags']['agent_disable'] = array();
+ $group['tags']['event_view'] = array();
+ $group['tags']['event_edit'] = array();
+ $group['tags']['event_management'] = array();
+ } else {
+ $aux = explode(',', $group['tags']);
+ $group['tags'] = array();
+ $group['tags']['agent_view'] = ($group['agent_view']) ? $aux : array();
+ $group['tags']['agent_edit'] = ($group['agent_edit']) ? $aux : array();
+ $group['tags']['agent_disable'] = ($group['agent_disable']) ? $aux : array();
+ $group['tags']['event_view'] = ($group['event_view']) ? $aux : array();
+ $group['tags']['event_edit'] = ($group['event_edit']) ? $aux : array();
+ $group['tags']['event_management'] = ($group['event_management']) ? $aux : array();
+ }
+
+}
+
?>
diff --git a/pandora_console/include/javascript/functions_pandora_networkmap.js b/pandora_console/include/javascript/functions_pandora_networkmap.js
index 7edc029f68..83418f97c1 100644
--- a/pandora_console/include/javascript/functions_pandora_networkmap.js
+++ b/pandora_console/include/javascript/functions_pandora_networkmap.js
@@ -3958,26 +3958,6 @@ function get_status_module() {
});
}
-function check_changes_num_modules() {
- var params = [];
- params.push("check_changes_num_modules=1");
- params.push("id=" + id_agent);
- params.push("page=operation/agentes/pandora_networkmap.view");
- jQuery.ajax({
- data: params.join("&"),
- dataType: 'json',
- type: 'POST',
- url: action = "../../../ajax.php",
- success: function (data) {
- if (data['correct']) {
- if (module_count != data['count']) {
- //location.reload(true);
- }
- }
- }
- });
-}
-
function show_networkmap_node(id_agent_param, refresh_state) {
id_agent = id_agent_param;
diff --git a/pandora_console/include/javascript/pandora.js b/pandora_console/include/javascript/pandora.js
index 7a23b2a36c..0788f43c70 100644
--- a/pandora_console/include/javascript/pandora.js
+++ b/pandora_console/include/javascript/pandora.js
@@ -65,58 +65,6 @@ Array.prototype.in_array = function () {
return false;
};
-/**
- * Fill up select box with id "module" with modules after agent has been selected
- *
- * @param event that has been triggered
- * @param id_agent Agent ID that has been selected
- * @param selected Which module(s) have to be selected
- */
-function agent_changed (event, id_agent, selected) {
- if (id_agent == undefined)
- id_agent = this.value;
- $('#module').attr ('disabled', 1);
- $('#module').empty ();
- $('#module').append ($('
').html ("Loading...").attr ("value", 0));
- jQuery.post ('ajax.php',
- {"page": "operation/agentes/ver_agente",
- "get_agent_modules_json": 1,
- "id_agent": id_agent
- },
- function (data) {
-
- $('#module').empty ();
-
- if (typeof($(document).data('text_for_module')) != 'undefined') {
- $('#module').append ($('
').html ($(document).data('text_for_module')).attr("value", 0).prop('selected', true));
- }
- else {
- if (typeof(data['any_text']) != 'undefined') {
- $('#module').append ($('
').html (data['any_text']).attr ("value", 0).prop('selected', true));
- }
- else {
- var anyText = $("#any_text").html(); //Trick for catch the translate text.
-
- if (anyText == null) {
- anyText = 'Any';
- }
-
- $('#module').append ($('
').html (anyText).attr ("value", 0).prop('selected', true));
- }
- }
- jQuery.each (data, function (i, val) {
- s = js_html_entity_decode (val['nombre']);
- $('#module').append ($('
').html (s).attr ("value", val['id_agente_modulo']));
- $('#module').fadeIn ('normal');
- });
- if (selected != undefined)
- $('#module').attr ('value', selected);
- $('#module').removeAttr('disabled');
- },
- "json"
- );
-}
-
/**
* Util for check is empty object
*
diff --git a/pandora_console/include/javascript/pandora_events.js b/pandora_console/include/javascript/pandora_events.js
index 16d2ad4e0c..02eac5553c 100644
--- a/pandora_console/include/javascript/pandora_events.js
+++ b/pandora_console/include/javascript/pandora_events.js
@@ -540,7 +540,6 @@ function show_events_group_agent (id_insert, id_agent, server_id) {
data: parameter,
dataType: 'html',
success: function (data) {
- console.log(data);
$("#"+id_insert).html(data);
$("#"+id_insert).toggle();
}
diff --git a/pandora_console/mobile/operation/modules.php b/pandora_console/mobile/operation/modules.php
index 8971334eea..f54b8009d3 100644
--- a/pandora_console/mobile/operation/modules.php
+++ b/pandora_console/mobile/operation/modules.php
@@ -281,8 +281,7 @@ class Modules {
$modules = array();
$modules_db = array();
- $sql_conditions_base = " WHERE tagente.id_agente = tagente_modulo.id_agente
- AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo";
+ $sql_conditions_base = " WHERE 1=1";
// Part SQL for the id_agent
@@ -400,7 +399,14 @@ class Modules {
$sql_total = "SELECT count(*)";
- $sql = " FROM tagente, tagente_modulo, tagente_estado" .
+ $sql = " FROM tagente INNER JOIN tagente_modulo
+ ON tagente_modulo.id_agente = tagente.id_agente
+ INNER JOIN tagente_estado
+ ON tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
+ LEFT JOIN tagent_secondary_group tasg
+ ON tagente.id_agente = tasg.id_agent
+ LEFT JOIN ttag_module
+ ON ttag_module.id_agente_modulo = tagente_modulo.id_agente_modulo" .
$sql_conditions_all;
$sql_limit = "ORDER BY tagente.nombre ASC ";
diff --git a/pandora_console/operation/agentes/estado_generalagente.php b/pandora_console/operation/agentes/estado_generalagente.php
index 6dbb229c8b..64b2a2f212 100755
--- a/pandora_console/operation/agentes/estado_generalagente.php
+++ b/pandora_console/operation/agentes/estado_generalagente.php
@@ -273,7 +273,6 @@ $table_data->head_colspan[0] = 3;
$data = array();
$data[0] = '
' . __('Group') . '';
$data[1] = '
'.groups_get_name ($agent["id_grupo"]).'';
-
// ACCESS RATE GRAPH
$access_agent = db_get_value_sql("SELECT COUNT(id_agent)
FROM tagent_access
@@ -550,6 +549,7 @@ if (!empty($network_interfaces)) {
else {
$group_array = $user_groups_ids;
}
+
$acl_tags = tags_get_acl_tags($config['id_user'], $group_array, 'ER',
'event_condition', 'AND', '', true, array(), true);
diff --git a/pandora_console/operation/agentes/estado_monitores.php b/pandora_console/operation/agentes/estado_monitores.php
index 3fceedda4e..d3baf170e5 100755
--- a/pandora_console/operation/agentes/estado_monitores.php
+++ b/pandora_console/operation/agentes/estado_monitores.php
@@ -138,17 +138,14 @@ echo "";
ob_start();
-
print_form_filter_monitors($id_agente, $status_filter_monitor, $status_text_monitor, $status_hierachy_mode);
echo "
" .
html_print_image('images/spinner.gif', true) .
'
';
echo "
" .
-
"
";
-
$html_toggle = ob_get_clean();
ui_toggle($html_toggle,
__('List of modules'),
diff --git a/pandora_console/operation/agentes/exportdata.php b/pandora_console/operation/agentes/exportdata.php
index e30001fd3c..579dbe8382 100644
--- a/pandora_console/operation/agentes/exportdata.php
+++ b/pandora_console/operation/agentes/exportdata.php
@@ -37,21 +37,8 @@ ui_print_page_header (__("Export data"), "images/server_export_mc.png");
$group = get_parameter_post ('group', 0);
$agentName = get_parameter_post ('agent', 0);
-
-switch ($config["dbtype"]) {
- case "mysql":
- $agents = agents_get_agents(
- array('nombre LIKE "' . $agentName . '"'), array ('id_agente'));
- break;
- case "postgresql":
- $agents = agents_get_agents(
- array('nombre LIKE \'' . $agentName . '\''), array ('id_agente'));
- break;
- case "oracle":
- $agents = agents_get_agents(
- array('nombre LIKE \'%' . $agentName . '%\''), array ('id_agente'));
- break;
-}
+$agents = agents_get_agents(
+ array('nombre LIKE "' . $agentName . '"'), array ('id_agente'));
$agent = $agents[0]['id_agente'];
$module = (array) get_parameter_post ('module_arr', array ());
diff --git a/pandora_console/operation/agentes/graphs.php b/pandora_console/operation/agentes/graphs.php
index eaf9b4af3d..4c9a546798 100644
--- a/pandora_console/operation/agentes/graphs.php
+++ b/pandora_console/operation/agentes/graphs.php
@@ -47,7 +47,6 @@ $option_type = get_parameter('option_type', 0);
// - others
//----------------------------------------------------------------------
$list_modules = array();
-
$modules_networkmap_no_proc = agents_get_modules(
$id_agente, false, array(
'id_modulo' => 2, // networkmap type
@@ -62,7 +61,6 @@ $modules_networkmap_no_proc = agents_get_modules(
));
if (empty($modules_networkmap_no_proc))
$modules_networkmap_no_proc = array();
-
$modules_others = agents_get_modules(
$id_agente, false, array(
'id_tipo_modulo' => array(
@@ -77,7 +75,6 @@ $modules_others = agents_get_modules(
if (empty($modules_others))
$modules_others = array();
-
$modules_boolean = agents_get_modules(
$id_agente, false, array(
'id_tipo_modulo' => array(
diff --git a/pandora_console/operation/agentes/pandora_networkmap.view.php b/pandora_console/operation/agentes/pandora_networkmap.view.php
index 32225b9ad1..738f9ed5df 100644
--- a/pandora_console/operation/agentes/pandora_networkmap.view.php
+++ b/pandora_console/operation/agentes/pandora_networkmap.view.php
@@ -563,8 +563,6 @@ if (is_ajax ()) {
$get_status_node = (bool)get_parameter('get_status_node', false);
$get_status_module = (bool)get_parameter('get_status_module',
false);
- $check_changes_num_modules = (bool)get_parameter(
- 'check_changes_num_modules', false);
if ($get_status_node) {
$id = (int)get_parameter('id', 0);
@@ -593,20 +591,6 @@ if (is_ajax ()) {
return;
}
- if ($check_changes_num_modules) {
- $id = (int)get_parameter('id', 0);
-
- $modules = agents_get_modules($id);
-
- $return = array();
- $return['correct'] = true;
- $return['count'] = count($modules);
-
- echo json_encode($return);
-
- return;
- }
-
if ($update_node_alert) {
$map_id = (int)get_parameter('map_id', 0);
diff --git a/pandora_console/operation/agentes/status_monitor.php b/pandora_console/operation/agentes/status_monitor.php
index 61b4375d25..5ae0748599 100644
--- a/pandora_console/operation/agentes/status_monitor.php
+++ b/pandora_console/operation/agentes/status_monitor.php
@@ -87,16 +87,25 @@ if ($id_module) {
enterprise_hook('open_meta_frame');
// Get Groups and profiles from user
-$user_groups = implode (',', array_keys (users_get_groups ()));
+$user_groups = implode (',', array_keys (users_get_groups (false,'AR',false)));
////////////////////////////////////
// Begin Build SQL sentences
-$sql_from = ' FROM ttipo_modulo,tagente LEFT JOIN tagent_secondary_group tasg ON tagente.id_agente = tasg.id_agent, tagente_modulo, tagente_estado,tmodule ';
+$sql_from = " FROM tagente_modulo
+ INNER JOIN tagente
+ ON tagente_modulo.id_agente = tagente.id_agente
+ LEFT JOIN tagent_secondary_group tasg
+ ON tagente.id_agente = tasg.id_agent
+ INNER JOIN tagente_estado
+ ON tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
+ INNER JOIN tmodule
+ ON tmodule.id_module = tagente_modulo.id_modulo
+ INNER JOIN ttipo_modulo
+ ON tagente_modulo.id_tipo_modulo = ttipo_modulo.id_tipo
+ LEFT JOIN ttag_module
+ ON tagente_modulo.id_agente_modulo = ttag_module.id_agente_modulo";
-$sql_conditions_base = ' WHERE tagente.id_agente = tagente_modulo.id_agente
- AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND tagente_modulo.id_tipo_modulo = ttipo_modulo.id_tipo AND tmodule.id_module = tagente_modulo.id_modulo';
-
-$sql_conditions = ' AND tagente.disabled = 0';
+$sql_conditions = ' WHERE tagente.disabled = 0';
if (is_numeric($ag_group)) {
$id_ag_group = 0;
@@ -149,8 +158,7 @@ else if ($modulegroup > -1) {
// Module name selector
if ($ag_modulename != '') {
- $sql_conditions .= sprintf (' AND tagente_modulo.nombre = \'%s\'',
- $ag_modulename);
+ $sql_conditions .= " AND tagente_modulo.nombre LIKE '%" .$ag_modulename. "%'";
}
if ($module_option !== 0) {
@@ -261,8 +269,7 @@ if (!users_is_admin()) {
}
// Two modes of filter. All the filters and only ACLs filter
-$sql_conditions_all = $sql_conditions_base . $sql_conditions . $sql_conditions_group . $sql_conditions_tags . $sql_conditions_custom_fields;
-$sql_conditions_acl = $sql_conditions_base . $sql_conditions_group . $sql_conditions_tags . $sql_conditions_custom_fields;
+$sql_conditions_all = $sql_conditions . $sql_conditions_group . $sql_conditions_tags . $sql_conditions_custom_fields;
// Get count to paginate
if (!defined('METACONSOLE'))
@@ -336,22 +343,16 @@ $table->data[0][5] = html_print_select($rows_select, 'modulegroup', $modulegroup
$table->rowspan[0][6] = 2;
$table->data[0][6] = html_print_submit_button (__('Show'), 'uptbutton',
false, 'class="sub search" style="margin-top:0px;"',true);
-$modules = array();
-$modules = modules_get_modules_name ($sql_from , $sql_conditions_acl, is_metaconsole());
$table->data[1][0] = __('Module name');
-$table->data[1][1] = html_print_select (index_array ($modules, 'nombre', 'nombre'), 'ag_modulename',
- $ag_modulename, '', __('All'), '', true, false, true, '', false, 'width: 150px;');
+$table->data[1][1] = html_print_autocomplete_modules('ag_modulename',
+ $ag_modulename, false, true, '', array(), true);
$table->data[1][2] = __('Search');
$table->data[1][3] = html_print_input_text ('ag_freestring', $ag_freestring, '', 20, 30, true);
-if (!is_metaconsole())
- $table->data[1][4] = __('Tags') .
- ui_print_help_tip(__('Only it is show tags in use.'), true);
-else
- $table->data[1][4] = __('Tags') .
- ui_print_help_tip(__('Only it is show tags in use.'), true);
+$table->data[1][4] = __('Tags') .
+ ui_print_help_tip(__('Only it is show tags in use.'), true);
$tags = array();
$tags = tags_get_user_tags();
diff --git a/pandora_console/operation/agentes/tactical.php b/pandora_console/operation/agentes/tactical.php
index 578c0c6af4..dd2472d7bc 100755
--- a/pandora_console/operation/agentes/tactical.php
+++ b/pandora_console/operation/agentes/tactical.php
@@ -177,15 +177,14 @@ echo '
1";
if (!empty($tags_condition)) {
- $events = events_print_event_table ("estado<>1 AND ($tags_condition)", 10, "100%",true,false,true);
- ui_toggle($events, __('Latest events'),false,false);
+ $event_filter .= " AND ($tags_condition)";
}
+ $events = events_print_event_table ($event_filter, 10, "100%",true,false,true);
+ ui_toggle($events, __('Latest events'),false,false);
}
// ---------------------------------------------------------------------
diff --git a/pandora_console/operation/agentes/ver_agente.php b/pandora_console/operation/agentes/ver_agente.php
index 444b72fbbe..f98af59772 100644
--- a/pandora_console/operation/agentes/ver_agente.php
+++ b/pandora_console/operation/agentes/ver_agente.php
@@ -29,13 +29,13 @@ ui_require_javascript_file('openlayers.pandora');
enterprise_include_once ('operation/agentes/ver_agente.php');
check_login ();
-
if (is_ajax ()) {
$get_agent_json = (bool) get_parameter ('get_agent_json');
$get_agent_modules_json = (bool) get_parameter ('get_agent_modules_json');
$get_agent_status_tooltip = (bool) get_parameter ("get_agent_status_tooltip");
$get_agents_group_json = (bool) get_parameter ("get_agents_group_json");
$get_modules_group_json = (bool) get_parameter ("get_modules_group_json");
+ $get_modules_group_value_name_json = (bool) get_parameter ("get_modules_group_value_name_json");
$get_agent_modules_json_for_multiple_agents = (bool) get_parameter("get_agent_modules_json_for_multiple_agents");
$get_agent_modules_alerts_json_for_multiple_agents = (bool) get_parameter("get_agent_modules_alerts_json_for_multiple_agents");
$get_agent_modules_multiple_alerts_json_for_multiple_agents = (bool) get_parameter("get_agent_modules_multiple_alerts_json_for_multiple_agents");
@@ -183,12 +183,23 @@ if (is_ajax ()) {
}
if ($get_modules_group_json) {
- $id_group = (int) get_parameter('id_module_group');
+ $id_group = (int) get_parameter('id_module_group', 0);
$id_agents = get_parameter('id_agents');
$selection = get_parameter('selection');
select_modules_for_agent_group($id_group, $id_agents, $selection);
}
+
+ if ($get_modules_group_value_name_json) {
+ $id_agents = get_parameter('id_agents');
+ $selection = get_parameter('selection');
+
+ // No filter by module group
+ $modules = select_modules_for_agent_group(0, $id_agents, $selection, false, true);
+ echo json_encode($modules);
+ return;
+
+ }
if ($get_agent_json) {
$id_agent = (int) get_parameter ('id_agent');
@@ -218,61 +229,17 @@ if (is_ajax ()) {
if ($get_agents_json_for_multiple_modules) {
$nameModules = get_parameter('module_name');
- $selection_mode = get_parameter('selection_mode','common');
+ $selection_mode = get_parameter('selection_mode','common') == "all";
$status_modulo = (int) get_parameter ('status_module', -1);
-
- $groups = users_get_groups ($config["id_user"], "AW", false);
- $group_id_list = ($groups ? join(",",array_keys($groups)):"0");
-
- $sql = 'SELECT DISTINCT(t1.nombre) as name, t1.alias
- FROM tagente t1, tagente_modulo t2
- WHERE t1.id_agente = t2.id_agente
- AND t1.id_grupo IN (' . $group_id_list .')
- AND t2.nombre IN (\'' . implode('\',\'', $nameModules) . '\')';
-
- // Status selector
- if ($status_modulo == AGENT_MODULE_STATUS_NORMAL) { //Normal
- $sql_conditions .= ' estado = 0 AND utimestamp > 0)
- OR (t2.id_tipo_modulo IN(21,22,23,100)) ';
- }
- elseif ($status_modulo == AGENT_MODULE_STATUS_CRITICAL_BAD) { //Critical
- $sql_conditions .= ' estado = 1 AND utimestamp > 0 )';
- }
- elseif ($status_modulo == AGENT_MODULE_STATUS_WARNING) { //Warning
- $sql_conditions .= ' estado = 2 AND utimestamp > 0 )';
- }
- elseif ($status_modulo == AGENT_MODULE_STATUS_NOT_NORMAL) { //Not normal
- $sql_conditions .= ' estado <> 0';
- }
- elseif ($status_modulo == AGENT_MODULE_STATUS_UNKNOWN) { //Unknown
- $sql_conditions .= ' estado = 3 AND utimestamp <> 0 )';
- }
- elseif ($status_modulo == AGENT_MODULE_STATUS_NOT_INIT) { //Not init
- $sql_conditions .= ' utimestamp = 0 )
- AND t2.id_tipo_modulo NOT IN (21,22,23,100)';
- }
-
- if ($status_modulo != -1) {
- $sql .= ' AND t2.id_agente_modulo IN (SELECT id_agente_modulo FROM tagente_estado where ' . $sql_conditions;
- }
-
- if ($selection_mode == 'common') {
- $sql .= 'AND (
- SELECT count(t3.nombre)
- FROM tagente t3, tagente_modulo t4
- WHERE t3.id_agente = t4.id_agente AND t1.nombre = t3.nombre
- AND t4.nombre IN (\'' . implode('\',\'', $nameModules) . '\')) = '.count($nameModules);
- }
- $sql .= ' ORDER BY t1.alias';
-
- $nameAgents = db_get_all_rows_sql($sql);
-
- if ($nameAgents == false)
- $nameAgents = array();
-
- foreach ($nameAgents as $nameAgent)
- $names[$nameAgent['name']] = io_safe_output($nameAgent['alias']);
+ $names = select_agents_for_module_group(
+ $nameModules,
+ $selection_mode,
+ array (
+ 'status' => $status_modulo
+ ),
+ "AW"
+ );
echo json_encode($names);
return;
@@ -390,17 +357,7 @@ if (is_ajax ()) {
$filter .= ' AND t1.id_tipo_modulo NOT IN (' . implode($module_types_excluded) . ')';
if (!empty($module_name)) {
- switch ($config['dbtype']) {
- case "mysql":
- $filter .= " AND t1.nombre COLLATE utf8_general_ci LIKE '%$module_name%'";
- break;
- case "postgresql":
- $filter .= " AND t1.nombre LIKE '%$module_name%'";
- break;
- case "oracle":
- $filter .= " AND UPPER(t1.nombre) LIKE UPPER('%$module_name%')";
- break;
- }
+ $filter .= " AND t1.nombre COLLATE utf8_general_ci LIKE '%$module_name%'";
}
// Status selector
@@ -690,7 +647,7 @@ if (is_ajax ()) {
}
if ($status_modulo != -1) {
- $filter['id_agente_modulo IN'] = ' (SELECT id_agente_modulo FROM tagente_estado where ' . $sql_conditions;
+ $filter['tagente_modulo.id_agente_modulo IN'] = ' (SELECT id_agente_modulo FROM tagente_estado where ' . $sql_conditions;
}
@@ -702,7 +659,7 @@ if (is_ajax ()) {
if ($get_id_and_name)
$fields = array('id_agente_modulo', 'nombre');
if ($get_distinct_name)
- $fields = array('DISTINCT(nombre)');
+ $fields = array('DISTINCT(tagente_modulo.nombre)');
$indexed = (bool) get_parameter ('indexed', true);
$agentName = (string) get_parameter ('agent_name', null);
@@ -734,7 +691,6 @@ if (is_ajax ()) {
$id_agent = array_keys(
agents_get_group_agents(
array_keys (users_get_groups ()), $search, "none"));
-
$agent_modules = agents_get_modules ($id_agent, $fields, $filter, $indexed, true, false, $tags);
}
// Restore db connection
@@ -747,7 +703,6 @@ if (is_ajax ()) {
$id_agent = array_keys(
agents_get_group_agents(
array_keys(users_get_groups ()), $search, "none"));
-
$agent_modules = agents_get_modules ($id_agent, $fields, $filter, $indexed, true, false, $tags);
}
diff --git a/pandora_console/operation/events/events.build_query.php b/pandora_console/operation/events/events.build_query.php
index 936d933143..c06d2ac6c9 100755
--- a/pandora_console/operation/events/events.build_query.php
+++ b/pandora_console/operation/events/events.build_query.php
@@ -158,7 +158,7 @@ if ($user_comment != '') {
}
if ($source != '') {
- $sql_post .= " AND source LIKE '$source'";
+ $sql_post .= " AND source LIKE '%$source%'";
}
// In metaconsole mode the agent search is performed by name
@@ -310,6 +310,7 @@ if ($id_group > 0 && in_array ($id_group, array_keys ($groups))) {
else {
$group_array = array_keys($groups);
}
+
if (check_acl ($id_user, 0, "ER"))
$tags_acls_condition = tags_get_acl_tags($id_user, $group_array, 'ER',
'event_condition', 'AND', '', $meta, array(), true); //FORCE CHECK SQL "(TAG = tag1 AND id_grupo = 1)"
diff --git a/pandora_console/operation/events/events_list.php b/pandora_console/operation/events/events_list.php
index 2add378167..068011f796 100644
--- a/pandora_console/operation/events/events_list.php
+++ b/pandora_console/operation/events/events_list.php
@@ -666,9 +666,8 @@ $table->data[] = $data;
$table->rowclass[] = '';
$data = array();
-$sources = events_get_all_source();
$data[0] = __('Source') . $jump;
-$data[0] .= html_print_select ($sources, 'source', $source, '', '', '', true);
+$data[0] .= html_print_input_text ('source', $source, '', 35, 255, true);
$data[1] = __('Extra ID') . $jump;
$data[1] .= html_print_input_text ('id_extra', $id_extra, '', 11, 255, true);
$data[2] = __("Comment") . $jump;
@@ -975,7 +974,7 @@ $(document).ready( function() {
if (i == 'id_group_filter')
$("#id_group_filter").val(val);
if (i == 'source')
- $("#source").val(val);
+ $("#text-source").val(val);
if (i == 'id_extra')
$("#text-id_extra").val(val);
if (i == 'user_comment')
@@ -1018,7 +1017,7 @@ $(document).ready( function() {
$("#pagination").val(20);
$("#update_from_filter_table").val(1);
$("#text_id_agent").val("");
- $("#source").val('');
+ $("#text-source").val('');
$("#text-id_extra").val('');
$("#text-user_comment").val('');
@@ -1090,7 +1089,7 @@ $(document).ready( function() {
}
}
if (i == 'source')
- $("#source").val(val);
+ $("#text-source").val(val);
if (i == 'id_extra')
$("#text-id_extra").val(val);
if (i == 'user_comment')
@@ -1161,7 +1160,7 @@ $(document).ready( function() {
"id_group_filter": $("#id_group_filter").val(),
"date_from": $("#text-date_from").val(),
"date_to": $("#text-date_to").val(),
- "source": $("#source").val(),
+ "source": $("#text-source").val(),
"id_extra": $("#text-id_extra").val(),
"user_comment": $("#text-user_comment").val()
},
@@ -1261,7 +1260,7 @@ $(document).ready( function() {
"id_group_filter": $("#id_group_filter").val(),
"date_from": $("#text-date_from").val(),
"date_to": $("#text-date_to").val(),
- "source": $("#source").val(),
+ "source": $("#text-source").val(),
"id_extra": $("#text-id_extra").val(),
"user_comment": $("#text-user_comment").val()
},
|