diff --git a/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.mysql.sql index 05977d3052..23ba9562fa 100755 --- a/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.mysql.sql @@ -49,3 +49,7 @@ CREATE TABLE IF NOT EXISTS `tuser_double_auth` ( -- ---------------------------------------------------------------------- INSERT INTO `ttipo_modulo` VALUES (5,'generic_data_inc_abs',0,'Generic numeric incremental (absolute)','mod_data_inc_abs.png'); +-- --------------------------------------------------------------------- +-- Table `tusuario` +-- --------------------------------------------------------------------- +ALTER TABLE `tusuario` ADD COLUMN `strict_acl` tinyint(1) DEFAULT 0; diff --git a/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.oracle.sql b/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.oracle.sql index dcf223f6cc..0f2d7a21f8 100755 --- a/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.oracle.sql +++ b/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.oracle.sql @@ -36,3 +36,8 @@ CREATE OR REPLACE TRIGGER tuser_double_auth_inc BEFORE INSERT ON tuser_double_au -- Table `ttipo_modulo` -- ---------------------------------------------------------------------- INSERT INTO ttipo_modulo VALUES (5,'generic_data_inc_abs',0,'Generic numeric incremental (absolute)','mod_data_inc_abs.png'); + +-- --------------------------------------------------------------------- +-- Table `tusuario` +-- --------------------------------------------------------------------- +ALTER TABLE tusuario ADD COLUMN strict_acl NUMBER(5,0) DEFAULT 0; diff --git a/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.postgreSQL.sql b/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.postgreSQL.sql index a0b2640837..f6fd488be9 100755 --- a/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.postgreSQL.sql +++ b/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.postgreSQL.sql @@ -34,3 +34,8 @@ CREATE TABLE "tuser_double_auth" ( -- Table `ttipo_modulo` -- ---------------------------------------------------------------------- INSERT INTO "ttipo_modulo" VALUES (5,'generic_data_inc_abs',0,'Generic numeric incremental (absolute)','mod_data_inc_abs.png'); + +-- --------------------------------------------------------------------- +-- Table `tusuario` +-- --------------------------------------------------------------------- +ALTER TABLE "tusuario" ADD COLUMN "strict_acl" SMALLINT NOT NULL default 0; diff --git a/pandora_console/godmode/users/configure_user.php b/pandora_console/godmode/users/configure_user.php index 66fa34af2a..9558f40003 100644 --- a/pandora_console/godmode/users/configure_user.php +++ b/pandora_console/godmode/users/configure_user.php @@ -123,6 +123,7 @@ if ($new_user && $config['admin_can_add_user']) { $user_info['is_admin'] = 0; $user_info['language'] = 'default'; $user_info["not_login"] = false; + $user_info["strict_acl"] = false; if ($isFunctionSkins !== ENTERPRISE_NOT_HOOK) { $user_info['id_skin'] = ''; } @@ -172,6 +173,7 @@ if ($create_user) { } } $values["not_login"] = (bool)get_parameter ('not_login', false); + $values["strict_acl"] = (bool)get_parameter ('strict_acl', false); if ($id == '') { ui_print_error_message (__('User ID cannot be empty')); @@ -235,6 +237,11 @@ if ($create_user) { $password_confirm = ''; if($result) { + if ($values["strict_acl"]) { + if ($values['is_admin']) { + ui_print_info_message (__('Strict ACL is not recommended for admin users because performance could be affected.')); + } + } $user_info = get_user_info ($id); $new_user = false; } @@ -269,6 +276,7 @@ if ($update_user) { $values['metaconsole_access_node'] = get_parameter ('metaconsole_access_node', '0'); } $values["not_login"] = (bool)get_parameter ('not_login', false); + $values["strict_acl"] = (bool)get_parameter ('strict_acl', false); $res1 = update_user ($id, $values); @@ -336,6 +344,25 @@ if ($update_user) { __('Error updating user info (no change?)')); } + if ($values['strict_acl']) { + $count_groups = 0; + $count_tags = 0; + + $profiles = db_get_all_rows_field_filter ("tusuario_perfil", "id_usuario", $id); + if ($profiles === false) { + $profiles = array (); + } + foreach ($profiles as $profile) { + $count_groups = $count_groups+1; + $arr_tags = explode(',', $profile['tags']); + $count_tags = $count_tags + count($arr_tags); + } + + if (($count_groups > 3) && ($count_tags > 10)) { + ui_print_info_message(__('Strict ACL is not recommended for this user. Performance could be affected.')); + } + } + $user_info = $values; } @@ -496,6 +523,10 @@ $table->data[13][0] = __('Not Login'); $table->data[13][0] .= ui_print_help_tip(__('The user with not login set only can access to API.'), true); $table->data[13][1] = html_print_checkbox('not_login', 1, $user_info["not_login"], true); +$table->data[14][0] = __('Strict ACL'); +$table->data[14][0] .= ui_print_help_tip(__('With this option enabled, the user will can access to accurate information. It is not recommended for admin users because performance could be affected'), true); +$table->data[14][1] = html_print_checkbox('strict_acl', 1, $user_info["strict_acl"], true); + if($meta) { enterprise_include('include/functions_metaconsole.php'); $data = array(); diff --git a/pandora_console/include/ajax/template_wizard.ajax.php b/pandora_console/include/ajax/template_wizard.ajax.php new file mode 100644 index 0000000000..46e4da34f0 --- /dev/null +++ b/pandora_console/include/ajax/template_wizard.ajax.php @@ -0,0 +1,65 @@ + $v) { + $agents_aux[$keys_prefix . $k] = $v; + //unset($agents[$k]); + } + } + $agents = $agents_aux; + } + + echo json_encode ($agents); + return; +} +?> diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index c7e5fcc551..72d37f44a2 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -114,8 +114,7 @@ function agents_create_agent ($name, $id_group, $interval, $ip_address, $values * @return array All simple alerts defined for an agent. Empty array if no * alerts found. */ -function agents_get_alerts_simple ($id_agent = false, $filter = '', $options = false, $where = '', - $allModules = false, $orderby = false, $idGroup = false, $count = false) { +function agents_get_alerts_simple ($id_agent = false, $filter = '', $options = false, $where = '', $allModules = false, $orderby = false, $idGroup = false, $count = false, $strict_user = false, $tag = false) { global $config; if (is_array($filter)) { @@ -149,7 +148,10 @@ function agents_get_alerts_simple ($id_agent = false, $filter = '', $options = f $filter .= ''; break; } - + + if ($tag) { + $filter .= ' AND (id_agent_module IN (SELECT id_agente_modulo FROM ttag_module WHERE id_tag IN ('.$tag.')))'; + } if (is_array ($options)) { $filter .= db_format_array_where_clause_sql ($options); } @@ -157,7 +159,7 @@ function agents_get_alerts_simple ($id_agent = false, $filter = '', $options = f if (($id_agent !== false) && ($idGroup !== false)) { $groups = users_get_groups($config["id_user"]); - $where_tags = tags_get_acl_tags($config['id_user'], $groups, 'AR', 'module_condition', 'AND', 'tagente_modulo'); + //$where_tags = tags_get_acl_tags($config['id_user'], $groups, 'AR', 'module_condition', 'AND', 'tagente_modulo'); if ($idGroup != 0) { //All group $subQuery = 'SELECT id_agente_modulo FROM tagente_modulo @@ -168,12 +170,15 @@ function agents_get_alerts_simple ($id_agent = false, $filter = '', $options = f FROM tagente_modulo WHERE delete_pending = 0'; } - // 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; + if ($strict_user) { + $where_tags = tags_get_acl_tags($config['id_user'], $groups, 'AR', 'module_condition', 'AND', 'tagente_modulo'); + // 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 ($id_agent === false) { diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index 97b4dc0145..44feff82a0 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -1521,8 +1521,8 @@ function get_alert_fires_in_period ($id_alert_module, $period, $date = 0) { */ function get_group_alerts($id_group, $filter = '', $options = false, $where = '', $allModules = false, $orderby = false, - $idGroup = false, $count = false) { - + $idGroup = false, $count = false, $strict_user = false, $tag = false) { + global $config; $group_query = ''; @@ -1561,18 +1561,20 @@ function get_group_alerts($id_group, $filter = '', $options = false, $filter .= ''; break; } - + + if ($tag) { + $filter .= ' AND (id_agent_module IN (SELECT id_agente_modulo FROM ttag_module WHERE id_tag IN ('.$tag.')))'; + } if (is_array ($options)) { $filter .= db_format_array_where_clause_sql ($options); } if ($id_group !== false) { - $groups = users_get_groups($config["id_user"]); - - $where_tags = tags_get_acl_tags($config['id_user'], - array_keys($groups), 'AR', 'module_condition', 'AND', 'tagente_modulo'); - + $groups = users_get_groups($config["id_user"], "AR"); + + //$where_tags = tags_get_acl_tags($config['id_user'], array_keys($groups), 'AR', 'module_condition', 'AND', 'tagente_modulo'); + if ($id_group != 0) { if (is_array($id_group)) { if (in_array(0, $id_group)) { @@ -1609,13 +1611,23 @@ function get_group_alerts($id_group, $filter = '', $options = false, $subQuery = 'SELECT id_agente_modulo 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; + // 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 { diff --git a/pandora_console/include/functions_groups.php b/pandora_console/include/functions_groups.php index c07aae0ae0..e5ee57fc7c 100644 --- a/pandora_console/include/functions_groups.php +++ b/pandora_console/include/functions_groups.php @@ -1125,7 +1125,7 @@ function groups_create_group($group_name, $rest_values){ // Get agents NOT INIT -function groups_agent_not_init ($group_array) { +function groups_agent_not_init ($group_array, $strict_user = false, $id_group_strict = false) { // If there are not groups to query, we jump to nextone @@ -1140,14 +1140,28 @@ function groups_agent_not_init ($group_array) { $group_clause = implode (",", $group_array); $group_clause = "(" . $group_clause . ")"; - $count = db_get_sql ("SELECT COUNT(*) - FROM tagente - WHERE disabled = 0 - AND critical_count = 0 - AND warning_count = 0 - AND unknown_count = 0 - AND (notinit_count > 0 OR total_count = 0) - AND id_grupo IN $group_clause"); + if ($strict_user) { + $tags_clause = " AND tagente.id_agente IN (SELECT id_agente FROM tagente_modulo + WHERE id_agente_modulo NOT IN (SELECT id_agente_modulo FROM ttag_module))"; + $sql = "SELECT COUNT(*) FROM tagente WHERE tagente.disabled=0 + AND id_grupo=$id_group_strict + AND critical_count = 0 + AND warning_count = 0 + AND unknown_count = 0 + AND (notinit_count > 0 OR total_count = 0) + $tags_clause"; + + $count = db_get_sql ($sql); + } else { + $count = db_get_sql ("SELECT COUNT(*) + FROM tagente + WHERE disabled = 0 + AND critical_count = 0 + AND warning_count = 0 + AND unknown_count = 0 + AND (notinit_count > 0 OR total_count = 0) + AND id_grupo IN $group_clause"); + } return $count > 0 ? $count : 0; } @@ -1155,7 +1169,7 @@ function groups_agent_not_init ($group_array) { // Get unknown agents by using the status code in modules. -function groups_agent_unknown ($group_array) { +function groups_agent_unknown ($group_array, $strict_user = false, $id_group_strict = false) { if (empty ($group_array)) { return 0; @@ -1167,12 +1181,24 @@ function groups_agent_unknown ($group_array) { $group_clause = implode (",", $group_array); $group_clause = "(" . $group_clause . ")"; - $count = db_get_sql ("SELECT COUNT(*) FROM tagente WHERE tagente.disabled=0 AND critical_count=0 AND warning_count=0 AND unknown_count>0 AND id_grupo IN $group_clause"); + if ($strict_user) { + $tags_clause = " AND tagente.id_agente IN (SELECT id_agente FROM tagente_modulo + WHERE id_agente_modulo NOT IN (SELECT id_agente_modulo FROM ttag_module))"; + $sql = "SELECT COUNT(*) FROM tagente WHERE tagente.disabled=0 + AND id_grupo=$id_group_strict + AND critical_count=0 + AND warning_count=0 AND unknown_count>0 + $tags_clause"; + + $count = db_get_sql ($sql); + } else { + $count = db_get_sql ("SELECT COUNT(*) FROM tagente WHERE tagente.disabled=0 AND critical_count=0 AND warning_count=0 AND unknown_count>0 AND id_grupo IN $group_clause"); + } return $count > 0 ? $count : 0; } -function groups_agent_total($group_array) { +function groups_agent_total($group_array, $strict_user = false, $id_group_strict = false) { if (empty ($group_array)) { return 0; @@ -1184,19 +1210,30 @@ function groups_agent_total($group_array) { $group_clause = implode (",", $group_array); $group_clause = "(" . $group_clause . ")"; - $count = db_get_sql ("SELECT COUNT(*) + if ($strict_user) { + + $tags_clause = " AND tagente.id_agente IN (SELECT id_agente FROM tagente_modulo + WHERE id_agente_modulo NOT IN (SELECT id_agente_modulo FROM ttag_module))"; + $sql = "SELECT COUNT(*) FROM tagente + WHERE tagente.disabled = 0 + AND id_grupo = ".$id_group_strict . + $tags_clause; + + $count = db_get_sql($sql); + + } else { + $count = db_get_sql ("SELECT COUNT(*) FROM tagente WHERE tagente.disabled = 0 - AND id_grupo IN $group_clause"); - - + AND id_grupo IN $group_clause"); + } return $count > 0 ? $count : 0; } // Get ok agents by using the status code in modules. -function groups_agent_ok ($group_array) { +function groups_agent_ok ($group_array, $strict_user = false, $id_group_strict = false) { if (empty ($group_array)) { return 0; @@ -1209,20 +1246,30 @@ function groups_agent_ok ($group_array) { $group_clause = implode (",", $group_array); $group_clause = "(" . $group_clause . ")"; - $count = db_get_sql ("SELECT COUNT(*) - FROM tagente - WHERE tagente.disabled = 0 - AND normal_count = total_count - AND id_grupo IN $group_clause"); - - - + if ($strict_user) { + $tags_clause = " AND tagente.id_agente IN (SELECT id_agente FROM tagente_modulo + WHERE id_agente_modulo NOT IN (SELECT id_agente_modulo FROM ttag_module))"; + $sql = "SELECT COUNT(*) FROM tagente WHERE tagente.disabled=0 + AND id_grupo=$id_group_strict + AND critical_count=0 + AND warning_count=0 AND normal_count = total_count + $tags_clause"; + + $count = db_get_sql ($sql); + } else { + $count = db_get_sql ("SELECT COUNT(*) + FROM tagente + WHERE tagente.disabled = 0 + AND normal_count = total_count + AND id_grupo IN $group_clause"); + } + return $count > 0 ? $count : 0; } // Get critical agents by using the status code in modules. -function groups_agent_critical ($group_array) { +function groups_agent_critical ($group_array, $strict_user = false, $id_group_strict = false) { if (empty ($group_array)) { return 0; @@ -1236,14 +1283,26 @@ function groups_agent_critical ($group_array) { $group_clause = "(" . $group_clause . ")"; //TODO REVIEW ORACLE AND POSTGRES - $count = db_get_sql ("SELECT COUNT(*) FROM tagente WHERE tagente.disabled=0 AND critical_count>0 AND id_grupo IN $group_clause"); + + if ($strict_user) { + $tags_clause = " AND tagente.id_agente IN (SELECT id_agente FROM tagente_modulo + WHERE id_agente_modulo NOT IN (SELECT id_agente_modulo FROM ttag_module))"; + $sql = "SELECT COUNT(*) FROM tagente WHERE tagente.disabled=0 + AND id_grupo=$id_group_strict + AND critical_count>0 + $tags_clause"; + + $count = db_get_sql ($sql); + } else { + $count = db_get_sql ("SELECT COUNT(*) FROM tagente WHERE tagente.disabled=0 AND critical_count>0 AND id_grupo IN $group_clause"); + } return $count > 0 ? $count : 0; } // Get warning agents by using the status code in modules. -function groups_agent_warning ($group_array) { +function groups_agent_warning ($group_array, $strict_user = false, $id_group_strict = false) { if (empty ($group_array)) { return 0; @@ -1256,7 +1315,19 @@ function groups_agent_warning ($group_array) { $group_clause = implode (",", $group_array); $group_clause = "(" . $group_clause . ")"; - $count = db_get_sql ("SELECT COUNT(*) FROM tagente WHERE tagente.disabled=0 AND critical_count=0 AND warning_count>0 AND id_grupo IN $group_clause"); + if ($strict_user) { + $tags_clause = " AND tagente.id_agente IN (SELECT id_agente FROM tagente_modulo + WHERE id_agente_modulo NOT IN (SELECT id_agente_modulo FROM ttag_module))"; + $sql = "SELECT COUNT(*) FROM tagente WHERE tagente.disabled=0 + AND id_grupo=$id_group_strict + AND critical_count=0 + AND warning_count>0 + $tags_clause"; + + $count = db_get_sql ($sql); + } else { + $count = db_get_sql ("SELECT COUNT(*) FROM tagente WHERE tagente.disabled=0 AND critical_count=0 AND warning_count>0 AND id_grupo IN $group_clause"); + } return $count > 0 ? $count : 0; } @@ -1264,7 +1335,7 @@ function groups_agent_warning ($group_array) { // Get monitor NOT INIT, except disabled AND async modules -function groups_monitor_not_init ($group_array) { +function groups_monitor_not_init ($group_array, $strict_user = false, $id_group_strict = false) { // If there are not groups to query, we jump to nextone @@ -1279,15 +1350,29 @@ function groups_monitor_not_init ($group_array) { $group_clause = implode (",", $group_array); $group_clause = "(" . $group_clause . ")"; - //TODO REVIEW ORACLE AND POSTGRES - $count = db_get_sql ("SELECT SUM(notinit_count) FROM tagente WHERE disabled = 0 AND id_grupo IN $group_clause"); + if ($strict_user) { + + $tags_clause = "AND tagente_modulo.id_agente_modulo NOT IN (SELECT id_agente_modulo FROM ttag_module)"; + + $count = db_get_sql ("SELECT COUNT(*) FROM tagente_modulo, tagente_estado + WHERE tagente_modulo.id_agente_modulo=tagente_estado.id_agente_modulo + AND tagente_estado.estado = 5 + AND tagente_modulo.id_agente IN ( SELECT id_agente FROM tagente + WHERE disabled = 0 + AND tagente.id_grupo = $id_group_strict + ) ". $tags_clause); + + } else { + //TODO REVIEW ORACLE AND POSTGRES + $count = db_get_sql ("SELECT SUM(notinit_count) FROM tagente WHERE disabled = 0 AND id_grupo IN $group_clause"); + } return $count > 0 ? $count : 0; } // Get monitor OK, except disabled and non-init -function groups_monitor_ok ($group_array) { +function groups_monitor_ok ($group_array, $strict_user = false, $id_group_strict = false) { // If there are not groups to query, we jump to nextone @@ -1302,15 +1387,28 @@ function groups_monitor_ok ($group_array) { $group_clause = implode (",", $group_array); $group_clause = "(" . $group_clause . ")"; - //TODO REVIEW ORACLE AND POSTGRES - $count = db_get_sql ("SELECT SUM(normal_count) FROM tagente WHERE disabled = 0 AND id_grupo IN $group_clause"); + + if ($strict_user) { + $tags_clause = "AND tagente_modulo.id_agente_modulo NOT IN (SELECT id_agente_modulo FROM ttag_module)"; + + $count = db_get_sql ("SELECT COUNT(*) FROM tagente_modulo, tagente_estado + WHERE tagente_modulo.id_agente_modulo=tagente_estado.id_agente_modulo + AND tagente_estado.estado = 0 + AND tagente_modulo.id_agente IN ( SELECT id_agente FROM tagente + WHERE disabled = 0 + AND tagente.id_grupo = $id_group_strict + ) ". $tags_clause); + } else { + //TODO REVIEW ORACLE AND POSTGRES + $count = db_get_sql ("SELECT SUM(normal_count) FROM tagente WHERE disabled = 0 AND id_grupo IN $group_clause"); + } return $count > 0 ? $count : 0; } // Get monitor CRITICAL, except disabled and non-init -function groups_monitor_critical ($group_array) { +function groups_monitor_critical ($group_array, $strict_user = false, $id_group_strict = false) { // If there are not groups to query, we jump to nextone @@ -1325,15 +1423,28 @@ function groups_monitor_critical ($group_array) { $group_clause = implode (",", $group_array); $group_clause = "(" . $group_clause . ")"; - //TODO REVIEW ORACLE AND POSTGRES - $count = db_get_sql ("SELECT SUM(critical_count) FROM tagente WHERE disabled = 0 AND id_grupo IN $group_clause"); + + if ($strict_user) { + + $tags_clause = "AND tagente_modulo.id_agente_modulo NOT IN (SELECT id_agente_modulo FROM ttag_module)"; + $count = db_get_sql ("SELECT COUNT(*) FROM tagente_modulo, tagente_estado + WHERE tagente_modulo.id_agente_modulo=tagente_estado.id_agente_modulo + AND tagente_estado.estado = 1 + AND tagente_modulo.id_agente IN ( SELECT id_agente FROM tagente + WHERE disabled = 0 + AND tagente.id_grupo = $id_group_strict + ) ". $tags_clause); + } else { + //TODO REVIEW ORACLE AND POSTGRES + $count = db_get_sql ("SELECT SUM(critical_count) FROM tagente WHERE disabled = 0 AND id_grupo IN $group_clause"); + } return $count > 0 ? $count : 0; } // Get monitor WARNING, except disabled and non-init -function groups_monitor_warning ($group_array) { +function groups_monitor_warning ($group_array, $strict_user = false, $id_group_strict = false) { // If there are not groups to query, we jump to nextone @@ -1348,15 +1459,27 @@ function groups_monitor_warning ($group_array) { $group_clause = implode (",", $group_array); $group_clause = "(" . $group_clause . ")"; - //TODO REVIEW ORACLE AND POSTGRES - $count = db_get_sql ("SELECT SUM(warning_count) FROM tagente WHERE disabled = 0 AND id_grupo IN $group_clause"); + if ($strict_user) { + + $tags_clause = "AND tagente_modulo.id_agente_modulo NOT IN (SELECT id_agente_modulo FROM ttag_module)"; + $count = db_get_sql ("SELECT COUNT(*) FROM tagente_modulo, tagente_estado + WHERE tagente_modulo.id_agente_modulo=tagente_estado.id_agente_modulo + AND tagente_estado.estado = 2 + AND tagente_modulo.id_agente IN ( SELECT id_agente FROM tagente + WHERE disabled = 0 + AND tagente.id_grupo = $id_group_strict + ) ". $tags_clause); + } else { + //TODO REVIEW ORACLE AND POSTGRES + $count = db_get_sql ("SELECT SUM(warning_count) FROM tagente WHERE disabled = 0 AND id_grupo IN $group_clause"); + } return $count > 0 ? $count : 0; } // Get monitor UNKNOWN, except disabled and non-init -function groups_monitor_unknown ($group_array) { +function groups_monitor_unknown ($group_array, $strict_user = false, $id_group_strict = false) { // If there are not groups to query, we jump to nextone @@ -1371,15 +1494,27 @@ function groups_monitor_unknown ($group_array) { $group_clause = implode (",", $group_array); $group_clause = "(" . $group_clause . ")"; - //TODO REVIEW ORACLE AND POSTGRES - $count = db_get_sql ("SELECT SUM(unknown_count) FROM tagente WHERE disabled = 0 AND id_grupo IN $group_clause"); + if ($strict_user) { + + $tags_clause = "AND tagente_modulo.id_agente_modulo NOT IN (SELECT id_agente_modulo FROM ttag_module)"; + $count = db_get_sql ("SELECT COUNT(*) FROM tagente_modulo, tagente_estado + WHERE tagente_modulo.id_agente_modulo=tagente_estado.id_agente_modulo + AND tagente_estado.estado = 3 + AND tagente_modulo.id_agente IN ( SELECT id_agente FROM tagente + WHERE disabled = 0 + AND tagente.id_grupo = $id_group_strict + ) ". $tags_clause); + } else { + //TODO REVIEW ORACLE AND POSTGRES + $count = db_get_sql ("SELECT SUM(unknown_count) FROM tagente WHERE disabled = 0 AND id_grupo IN $group_clause"); + } return $count > 0 ? $count : 0; } // Get alerts defined for a given group, except disabled -function groups_monitor_alerts ($group_array) { +function groups_monitor_alerts ($group_array, $strict_user = false, $id_group_strict = false) { // If there are not groups to query, we jump to nextone @@ -1394,20 +1529,36 @@ function groups_monitor_alerts ($group_array) { $group_clause = implode (",", $group_array); $group_clause = "(" . $group_clause . ")"; - //TODO REVIEW ORACLE AND POSTGRES - - return db_get_sql ("SELECT COUNT(talert_template_modules.id) - FROM talert_template_modules, tagente_modulo, tagente_estado, tagente - WHERE tagente.id_grupo IN $group_clause AND tagente_modulo.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente_modulo.disabled = 0 AND tagente.disabled = 0 - AND talert_template_modules.disabled = 0 - AND talert_template_modules.id_agent_module = tagente_modulo.id_agente_modulo"); + if ($strict_user) { + + $tags_clause = "AND tagente_modulo.id_agente_modulo NOT IN (SELECT id_agente_modulo FROM ttag_module)"; + $sql = "SELECT COUNT(talert_template_modules.id) + FROM talert_template_modules, tagente_modulo, tagente_estado, tagente + WHERE tagente.id_grupo = $id_group_strict AND tagente_modulo.id_agente = tagente.id_agente + AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo + AND tagente_modulo.disabled = 0 AND tagente.disabled = 0 + AND talert_template_modules.disabled = 0 + AND talert_template_modules.id_agent_module = tagente_modulo.id_agente_modulo + $tags_clause"; + $count = db_get_sql ($sql); + return $count; + + } else { + + //TODO REVIEW ORACLE AND POSTGRES + return db_get_sql ("SELECT COUNT(talert_template_modules.id) + FROM talert_template_modules, tagente_modulo, tagente_estado, tagente + WHERE tagente.id_grupo IN $group_clause AND tagente_modulo.id_agente = tagente.id_agente + AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo + AND tagente_modulo.disabled = 0 AND tagente.disabled = 0 + AND talert_template_modules.disabled = 0 + AND talert_template_modules.id_agent_module = tagente_modulo.id_agente_modulo"); + } } // Get alert configured currently FIRED, except disabled -function groups_monitor_fired_alerts ($group_array) { +function groups_monitor_fired_alerts ($group_array, $strict_user = false, $id_group_strict = false) { // If there are not groups to query, we jump to nextone @@ -1422,16 +1573,33 @@ function groups_monitor_fired_alerts ($group_array) { $group_clause = implode (",", $group_array); $group_clause = "(" . $group_clause . ")"; - //TODO REVIEW ORACLE AND POSTGRES - - return db_get_sql ("SELECT COUNT(talert_template_modules.id) + if ($strict_user) { + + $tags_clause = "AND tagente_modulo.id_agente_modulo NOT IN (SELECT id_agente_modulo FROM ttag_module)"; + + $sql = "SELECT COUNT(talert_template_modules.id) FROM talert_template_modules, tagente_modulo, tagente_estado, tagente - WHERE tagente.id_grupo IN $group_clause AND tagente_modulo.id_agente = tagente.id_agente + WHERE tagente.id_grupo = $id_group_strict AND tagente_modulo.id_agente = tagente.id_agente AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND tagente_modulo.disabled = 0 AND tagente.disabled = 0 AND talert_template_modules.disabled = 0 AND talert_template_modules.id_agent_module = tagente_modulo.id_agente_modulo - AND times_fired > 0"); + AND times_fired > 0 ".$tags_clause; + + $count = db_get_sql ($sql); + return $count; + } else { + //TODO REVIEW ORACLE AND POSTGRES + return db_get_sql ("SELECT COUNT(talert_template_modules.id) + FROM talert_template_modules, tagente_modulo, tagente_estado, tagente + WHERE tagente.id_grupo IN $group_clause AND tagente_modulo.id_agente = tagente.id_agente + AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo + AND tagente_modulo.disabled = 0 AND tagente.disabled = 0 + AND talert_template_modules.disabled = 0 + AND talert_template_modules.id_agent_module = tagente_modulo.id_agente_modulo + AND times_fired > 0"); + } + } /** @@ -1630,8 +1798,6 @@ function groups_get_tree(&$groups, $parent = false) { return $return; } - - function groups_get_all_hierarchy_group ($id_group, $hierarchy = array()) { global $config; @@ -1646,12 +1812,10 @@ function groups_get_all_hierarchy_group ($id_group, $hierarchy = array()) { $propagate = db_get_value('propagate','tgrupo','id_grupo',$parent); if ($propagate == 1) { - //$childrens_ids_parent = array($parent); $hierarchy[] = $parent; $childrens = groups_get_childrens($parent); if (!empty($childrens)) { foreach ($childrens as $child) { - //$childrens_ids_parent[] = (int)$child['id_grupo']; $hierarchy[] = (int)$child['id_grupo']; } } @@ -1662,4 +1826,325 @@ function groups_get_all_hierarchy_group ($id_group, $hierarchy = array()) { } return $hierarchy; } + +function group_get_data ($id_user = false, $user_strict = false, $acltags, $returnAllGroup = false, $mode = 'group') { + global $config; + + if ($id_user == false) { + $id_user = $config['id_user']; + } + + $user_groups = array(); + $user_tags = array(); + foreach ($acltags as $group => $tags) { + if ($user_strict) { //Remove groups with tags + if ($tags == '') { + $groups_without_tags[$group] = $group; + } + } + $user_groups[$group] = groups_get_name($group); + if ($tags != '') { + $tags_group = explode(',', $tags); + + foreach ($tags_group as $tag) { + $user_tags[$tag] = tags_get_name($tag); + } + } + } + + if ($user_strict) { + $user_groups_ids = implode(',',array_keys($groups_without_tags)); + } else { + $user_groups_ids = implode(',',array_keys($acltags)); + } + + if ($user_groups_ids == '') { + $user_groups_ids == -1; + } + + switch ($config["dbtype"]) { + case "mysql": + $list_groups = db_get_all_rows_sql(" + SELECT * + FROM tgrupo + WHERE id_grupo IN (" . $user_groups_ids . ") + ORDER BY nombre COLLATE utf8_general_ci ASC"); + + break; + case "postgresql": + $list_groups = db_get_all_rows_sql(" + SELECT * + FROM tgrupo + WHERE id_grupo IN (" . $user_groups_ids . ") + ORDER BY nombre ASC"); + break; + case "oracle": + $list_groups = db_get_all_rows_sql(" + SELECT * + FROM tgrupo + WHERE id_grupo IN (" . $user_groups_ids . ") + ORDER BY nombre COLLATE utf8_general_ci ASC"); + break; + } + + if ($list_groups == false) { + $list_groups = array(); + } + + if ($returnAllGroup) { + $i = 1; + $list[0]['_id_'] = 0; + $list[0]['_name_'] = __('All'); + } else { + $i = 0; + } + foreach ($list_groups as $key => $item) { + $id = $item['id_grupo']; + + if (($config["realtimestats"] == 0) && !$user_strict) { + $group_stat = db_get_all_rows_sql ("SELECT * + FROM tgroup_stat, tgrupo + WHERE tgrupo.id_grupo = tgroup_stat.id_group + AND tgroup_stat.id_group = $id + ORDER BY nombre"); + + $list[$i]['_id_'] = $id; + $list[$i]['_name_'] = $item['nombre']; + $list[$i]['_iconImg_'] = html_print_image ("images/groups_small/" . groups_get_icon($item['id_grupo']).".png", true, array ("style" => 'vertical-align: middle;')); + + $list[$i]['_agents_unknown_'] = $group_stat[0]["unknown"]; + $list[$i]['_monitors_alerts_fired_'] = $group_stat[0]["alerts_fired"]; + $list[$i]['_total_agents_'] = $group_stat[0]["agents"]; + + if ($mode == 'tactical') { + $list[$i]['_agents_ok_'] = $group_stat[0]["normal"]; + $list[$i]['_agents_warning_'] = $group_stat[0]["warning"]; + $list[$i]['_agents_critical_'] = $group_stat[0]["critical"]; + $list[$i]['_monitors_alerts_'] = $group_stat[0]["alerts"]; + } + + // This fields are not in database + $list[$i]['_monitors_ok_'] = groups_monitor_ok($id, $user_strict, $id); + $list[$i]['_monitors_critical_'] = groups_monitor_critical($id, $user_strict, $id); + $list[$i]['_monitors_warning_'] = groups_monitor_warning($id, $user_strict, $id); + $list[$i]['_monitors_unknown_'] = groups_monitor_unknown($id, $user_strict, $id); + $list[$i]['_monitors_not_init_'] = groups_monitor_not_init($id, $user_strict, $id); + $list[$i]['_agents_not_init_'] = groups_agent_not_init ($id, $user_strict, $id); + + if ($returnAllGroup) { + $list[0]['_agents_unknown_'] += $group_stat[0]["unknown"]; + $list[0]['_monitors_alerts_fired_'] += $group_stat[0]["alerts_fired"]; + $list[0]['_total_agents_'] += $group_stat[0]["agents"]; + $list[0]['_monitors_ok_'] += $list[$i]['_monitors_ok_']; + $list[0]['_monitors_critical_'] += $list[$i]['_monitors_critical_']; + $list[0]['_monitors_warning_'] += $list[$i]['_monitors_warning_']; + $list[0]['_monitors_unknown_'] += $list[$i]['_monitors_unknown_']; + $list[0]['_monitors_not_init_'] += $list[$i]['_monitors_not_init_']; + $list[0]['_agents_not_init'] += $list[$i]['_agents_not_init']; + + if ($mode == 'tactical') { + $list[0]['_agents_ok_'] += $group_stat[0]["normal"]; + $list[0]['_agents_warning_'] += $group_stat[0]["warning"]; + $list[0]['_agents_critical_'] += $group_stat[0]["critical"]; + $list[0]['_monitors_alerts_'] += $group_stat[0]["alerts"]; + } + } + + if ($mode == 'group') { + if (! defined ('METACONSOLE')) { + if (($list[$i]['_agents_unknown_'] == 0) && ($list[$i]['_monitors_alerts_fired_'] == 0) && ($list[$i]['_total_agents_'] == 0) && ($list[$i]['_monitors_ok_'] == 0) && ($list[$i]['_monitors_critical_'] == 0) && ($list[$i]['_monitors_warning_'] == 0) && ($list[$i]['_monitors_unknown_'] == 0) && ($list[$i]['_monitors_not_init_'] == 0) && ($list[$i]['_agents_not_init_'] == 0)) { + unset($list[$i]); + } + } else { + if (($list[$i]['_agents_unknown_'] == 0) && ($list[$i]['_monitors_alerts_fired_'] == 0) && ($list[$i]['_total_agents_'] == 0) && ($list[$i]['_monitors_ok_'] == 0) && ($list[$i]['_monitors_critical_'] == 0) && ($list[$i]['_monitors_warning_'] == 0)) { + unset($list[$i]); + } + } + } + + } else { + $list[$i]['_id_'] = $id; + $list[$i]['_name_'] = $item['nombre']; + $list[$i]['_iconImg_'] = html_print_image ("images/groups_small/" . groups_get_icon($item['id_grupo']).".png", true, array ("style" => 'vertical-align: middle;')); + + $list[$i]['_monitors_ok_'] = groups_monitor_ok($id, $user_strict, $id); + $list[$i]['_monitors_critical_'] = groups_monitor_critical($id, $user_strict, $id); + $list[$i]['_monitors_warning_'] = groups_monitor_warning($id, $user_strict, $id); + $list[$i]['_agents_unknown_'] = groups_agent_unknown ($id, $user_strict, $id); + $list[$i]['_monitors_alerts_fired_'] = groups_monitor_fired_alerts ($id, $user_strict, $id); + $list[$i]['_total_agents_'] = groups_agent_total ($id, $user_strict, $id); + $list[$i]['_monitors_unknown_'] = groups_monitor_unknown($id, $user_strict, $id); + $list[$i]['_monitors_not_init_'] = groups_monitor_not_init($id, $user_strict, $id); + $list[$i]['_agents_not_init_'] = groups_agent_not_init ($id, $user_strict, $id); + + if ($mode == 'tactical') { + $list[$i]['_agents_ok_'] = groups_agent_ok ($id, $user_strict, $id); + $list[$i]['_agents_warning_'] = groups_agent_warning ($id, $user_strict, $id); + $list[$i]['_agents_critical_'] = groups_agent_critical ($id, $user_strict, $id); + $list[$i]['_monitors_alerts_'] = groups_monitor_alerts ($id, $user_strict, $id); + } + + if ($returnAllGroup) { + $list[0]['_agents_unknown_'] += $list[$i]['_agents_unknown_']; + $list[0]['_monitors_alerts_fired_'] += $list[$i]['_monitors_alerts_fired_']; + $list[0]['_total_agents_'] += $list[$i]['_total_agents_']; + $list[0]['_monitors_ok_'] += $list[$i]['_monitors_ok_']; + $list[0]['_monitors_critical_'] += $list[$i]['_monitors_critical_']; + $list[0]['_monitors_warning_'] += $list[$i]['_monitors_warning_']; + $list[0]['_monitors_unknown_'] += $list[$i]['_monitors_unknown_']; + $list[0]['_monitors_not_init_'] = $list[$i]['_monitors_not_init_']; + $list[0]['_agents_not_init_'] += $list[$i]['_agents_not_init']; + + if ($mode == 'tactical') { + $list[0]['_agents_ok_'] += $list[$i]['_agents_ok_']; + $list[0]['_agents_warning_'] += $list[$i]['_agents_warning_']; + $list[0]['_agents_critical_'] += $list[$i]['_agents_critical_']; + $list[0]['_monitors_alerts_'] += $list[$i]['_monitors_alerts_']; + } + } + + if ($mode == 'group') { + if (! defined ('METACONSOLE')) { + if (($list[$i]['_agents_unknown_'] == 0) && ($list[$i]['_monitors_alerts_fired_'] == 0) && ($list[$i]['_total_agents_'] == 0) && ($list[$i]['_monitors_ok_'] == 0) && ($list[$i]['_monitors_critical_'] == 0) && ($list[$i]['_monitors_warning_'] == 0) && ($list[$i]['_monitors_unknown_'] == 0) && ($list[$i]['_monitors_not_init_'] == 0) && ($list[$i]['_agents_not_init_'] == 0)) { + unset($list[$i]); + } + } else { + if (($list[$i]['_agents_unknown_'] == 0) && ($list[$i]['_monitors_alerts_fired_'] == 0) && ($list[$i]['_total_agents_'] == 0) && ($list[$i]['_monitors_ok_'] == 0) && ($list[$i]['_monitors_critical_'] == 0) && ($list[$i]['_monitors_warning_'] == 0)) { + unset($list[$i]); + } + } + } + } + $i++; + } + + if ($user_strict) { + foreach ($user_tags as $group_id => $tag_name) { + $id = db_get_value('id_tag', 'ttag', 'name', $tag_name); + + $list[$i]['_id_'] = $id; + $list[$i]['_name_'] = $tag_name; + $list[$i]['_iconImg_'] = html_print_image ("images/tag_red.png", true, array ("style" => 'vertical-align: middle;')); + $list[$i]['_is_tag_'] = 1; + + $list[$i]['_total_agents_'] = tags_total_agents ($id, $acltags); + $list[$i]['_agents_unknown_'] = tags_get_unknown_agents ($id, $acltags); + $list[$i]['_monitors_ok_'] = tags_monitors_ok ($id, $acltags); + $list[$i]['_monitors_critical_'] = tags_monitors_critical ($id, $acltags); + $list[$i]['_monitors_warning_'] = tags_monitors_warning ($id, $acltags); + $list[$i]['_monitors_alerts_fired_'] = tags_monitors_fired_alerts($id, $acltags); + + if ($mode == 'tactical') { + $list[$i]['_agents_ok_'] = tags_agent_ok ($id, $acltags); + $list[$i]['_agents_warning_'] = tags_agent_warning ($id, $acltags); + $list[$i]['_agents_critical_'] = tags_get_critical_agents ($id, $acltags); + $list[$i]['_monitors_alerts_'] = tags_get_monitors_alerts ($id, $acltags); + } + + + if ($returnAllGroup) { + $list[0]['_agents_unknown_'] += $list[$i]['_agents_unknown_']; + $list[0]['_monitors_alerts_fired_'] += $list[$i]['_monitors_alerts_fired_']; + $list[0]['_total_agents_'] += $list[$i]['_total_agents_']; + $list[0]['_monitors_ok_'] += $list[$i]['_monitors_ok_']; + $list[0]['_monitors_critical_'] += $list[$i]['_monitors_critical_']; + $list[0]['_monitors_warning_'] += $list[$i]['_monitors_warning_']; + $list[0]['_monitors_unknown_'] += $list[$i]['_monitors_unknown_']; + $list[0]['_monitors_not_init_'] = $list[$i]['_monitors_not_init_']; + + if ($mode == 'tactical') { + $list[0]['_agents_ok_'] += $list[$i]['_agents_ok_']; + $list[0]['_agents_warning_'] += $list[$i]['_agents_warning_']; + $list[0]['_agents_critical_'] += $list[$i]['_agents_critical_']; + $list[0]['_monitors_alerts_'] += $list[$i]['_monitors_alerts_']; + } + } + + if ($mode == 'group') { + if (! defined ('METACONSOLE')) { + if (($list[$i]['_agents_unknown_'] == 0) && ($list[$i]['_monitors_alerts_fired_'] == 0) && ($list[$i]['_total_agents_'] == 0) && ($list[$i]['_monitors_ok_'] == 0) && ($list[$i]['_monitors_critical_'] == 0) && ($list[$i]['_monitors_warning_'] == 0) && ($list[$i]['_monitors_unknown_'] == 0) && ($list[$i]['_monitors_not_init_'] == 0) && ($list[$i]['_agents_not_init_'] == 0)) { + unset($list[$i]); + } + } else { + if (($list[$i]['_agents_unknown_'] == 0) && ($list[$i]['_monitors_alerts_fired_'] == 0) && ($list[$i]['_total_agents_'] == 0) && ($list[$i]['_monitors_ok_'] == 0) && ($list[$i]['_monitors_critical_'] == 0) && ($list[$i]['_monitors_warning_'] == 0)) { + unset($list[$i]); + } + } + } + $i++; + } + } + + return $list; +} + +function group_get_groups_list($id_user = false, $user_strict = false, $access = 'AR', $force_group_and_tag = true, $returnAllGroup = false, $mode = 'group') { + global $config; + + if ($id_user == false) { + $id_user = $config['id_user']; + } + + $acltags = tags_get_user_module_and_tags ($id_user, $access, $user_strict); + + if (! defined ('METACONSOLE')) { + $result_list = group_get_data ($id_user, $user_strict, $acltags, $returnAllGroup, $mode); + return $result_list; + } else { + $servers = db_get_all_rows_sql (" + SELECT * + FROM tmetaconsole_setup + WHERE disabled = 0"); + + if ($servers === false) { + $servers = array(); + } + + $result_list = array (); + foreach ($servers as $server) { + if (metaconsole_connect($server) != NOERR) { + continue; + } + $server_list = group_get_data ($id_user, $user_strict, $acltags, $returnAllGroup, $mode); + + foreach ($server_list as $server_item) { + if (! isset ($result_list[$server_item['_name_']])) { + $result_list[$server_item['_name_']] = $server_item; + } + else { + $result_list[$server_item['_name_']]['_monitors_ok_'] += $server_item['_monitors_ok_']; + $result_list[$server_item['_name_']]['_monitors_critical_'] += $server_item['_monitors_critical_']; + $result_list[$server_item['_name_']]['_monitors_warning_'] += $server_item['_monitors_warning_']; + $result_list[$server_item['_name_']]['_agents_unknown_'] += $server_item['_agents_unknown_']; + $result_list[$server_item['_name_']]['_total_agents_'] += $server_item['_total_agents_']; + $result_list[$server_item['_name_']]['_monitors_alerts_fired_'] += $server_item['_monitors_alerts_fired_']; + + if ($mode == 'tactical') { + $result_list[$server_item['_name_']]['_agents_ok_'] += $server_item['_agents_ok_']; + $result_list[$server_item['_name_']]['_agents_critical_'] += $server_item['_agents_critical_']; + $result_list[$server_item['_name_']]['_agents_warning_'] += $server_item['_agents_warning_']; + $result_list[$server_item['_name_']]['_monitors_alerts_'] += $server_item['_monitors_alerts_']; + } + } + } + metaconsole_restore_db(); + + } + + return $result_list; + } +} + +function groups_get_group_deep ($id_group) { + global $config; + $parents = groups_get_parents($id_group, false); + + if (empty($parents)) { + $deep = ""; + } else { + $deep = str_repeat("    ", count($parents)); + } + + return $deep; +} ?> diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 4360409e56..357a1f54c6 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -368,13 +368,36 @@ function html_print_select_groups($id_user = false, $privilege = "AR", $nothing = '', $nothing_value = 0, $return = false, $multiple = false, $sort = true, $class = '', $disabled = false, $style = false, $option_style = false, $id_group = false, - $keys_field = 'id_grupo') { + $keys_field = 'id_grupo', $strict_user = false) { global $config; $fields = users_get_groups_for_select($id_user, $privilege, $returnAllGroup, true, $id_group, $keys_field); - + + if ($strict_user) { + foreach ($fields as $id => $group_name) { + $sql = "SELECT tags FROM tusuario_perfil WHERE id_usuario = '$id_user' AND id_grupo = $id"; + $group_has_tag = db_get_value_sql ($sql); + if (!$group_has_tag) { + + $sql_parent = "SELECT parent FROM tgrupo WHERE id_grupo = $id AND propagate = 1"; + $id_parent = db_get_value_sql($sql_parent); + + if ($id_parent) { + $sql_parent_aux = "SELECT tags FROM tusuario_perfil WHERE id_usuario = '$id_user' AND id_grupo = $id_parent"; + $parent_has_tag = db_get_value_sql ($sql_parent_aux); + + if ($parent_has_tag) { + unset($fields[$id]); + } + } + } else { + unset($fields[$id]); + } + } + } + $output = html_print_select ($fields, $name, $selected, $script, $nothing, $nothing_value, $return, $multiple, false, $class, $disabled, $style, $option_style); @@ -1466,22 +1489,13 @@ function html_print_table (&$table, $return = false) { if (!isset ($style[$key])) { $style[$key] = ''; } - - $output .= '' . - $item . '' . "\n"; + + $output .= ''. $item .''."\n"; } - $output .= '' . "\n"; + $output .= ''."\n"; } } - $output .= '' . "\n"; + $output .= ''."\n"; if ($return) return $output; diff --git a/pandora_console/include/functions_tags.php b/pandora_console/include/functions_tags.php index 33eefb3d3c..ba74a5f6cc 100644 --- a/pandora_console/include/functions_tags.php +++ b/pandora_console/include/functions_tags.php @@ -62,18 +62,40 @@ function tags_agent_unknown ($id_tag) { * * @return mixed Returns count of agents with this tag or false if they aren't. */ -function tags_total_agents ($id_tag) { +function tags_total_agents ($id_tag, $groups_and_tags = array()) { // Avoid mysql error if (empty($id_tag)) return; + $groups_clause = ""; + if (!empty($groups_and_tags)) { + $i = 0; + foreach ($groups_and_tags as $group_id => $tags) { + if ($tags != "") { + $tags_arr = explode(',', $tags); + foreach ($tags_arr as $tag) { + if ($tag == $id_tag) { + if ($i == 0) { + $groups_id = $group_id; + } else { + $groups_id .= ','.$group_id; + } + $i++; + } + } + } + } + $groups_clause = " AND tagente.id_grupo IN ($groups_id)"; + } + $total_agents = "SELECT COUNT(DISTINCT tagente.id_agente) FROM tagente, tagente_modulo, ttag_module WHERE tagente.id_agente = tagente_modulo.id_agente - AND tagente_modulo.id_agente_modulo = ttag_module.id_agente_modulo - AND ttag_module.id_tag = " . $id_tag; - + AND tagente_modulo.id_agente_modulo = ttag_module.id_agente_modulo + AND ttag_module.id_tag = " . $id_tag . + $groups_clause; + return db_get_sql ($total_agents); } @@ -84,15 +106,37 @@ function tags_total_agents ($id_tag) { * * @return mixed Returns count of agents in normal status or false if they aren't. */ -function tags_agent_ok ($id_tag) { +function tags_agent_ok ($id_tag, $groups_and_tags = array()) { + $groups_clause = ""; + if (!empty($groups_and_tags)) { + $i = 0; + foreach ($groups_and_tags as $group_id => $tags) { + if ($tags != "") { + $tags_arr = explode(',', $tags); + foreach ($tags_arr as $tag) { + if ($tag == $id_tag) { + if ($i == 0) { + $groups_id = $group_id; + } else { + $groups_id .= ','.$group_id; + } + $i++; + } + } + } + } + $groups_clause = " AND tagente.id_grupo IN ($groups_id)"; + } + return db_get_sql ("SELECT COUNT(*) FROM tagente, tagente_modulo, ttag_module WHERE tagente.id_agente = tagente_modulo.id_agente AND tagente.disabled=0 AND tagente_modulo.id_agente_modulo = ttag_module.id_agente_modulo AND ttag_module.id_tag = $id_tag - AND normal_count=total_count"); + AND normal_count=total_count + $groups_clause"); } /** @@ -102,7 +146,7 @@ function tags_agent_ok ($id_tag) { * * @return mixed Returns count of agents in warning status or false if they aren't. */ -function tags_agent_warning ($id_tag) { +function tags_agent_warning ($id_tag, $groups_and_tags = array()) { return db_get_sql ("SELECT COUNT(*) FROM tagente, tagente_modulo, ttag_module @@ -197,13 +241,13 @@ function tags_create_tag($values) { if (empty($values)) { return false; } - - //No create tag if the tag exists + + //No create tag if the tag exists if (tags_get_id($values["name"])) { return false; } - return db_process_sql_insert('ttag', $values); + return db_process_sql_insert('ttag',$values); } /** @@ -657,10 +701,7 @@ function tags_get_tags_formatted ($tags_array, $get_url = true) { * @return mixed/string Tag ids */ -function tags_get_acl_tags($id_user, $id_group, $access = 'AR', - $return_mode = 'module_condition', $query_prefix = '', - $query_table = '', $meta = false, $childrens_ids = array(), - $force_group_and_tag = false) { +function tags_get_acl_tags($id_user, $id_group, $access = 'AR', $return_mode = 'module_condition', $query_prefix = '', $query_table = '', $meta = false, $childrens_ids = array(), $force_group_and_tag = false) { global $config; @@ -680,6 +721,10 @@ function tags_get_acl_tags($id_user, $id_group, $access = 'AR', } } + if ($id_group[0] != 0) { + $id_group = groups_get_all_hierarchy_group ($id_group[0]); + } + if ((string)$id_group === "0") { $id_group = array_keys(users_get_groups($id_user, $access, false)); @@ -694,10 +739,6 @@ function tags_get_acl_tags($id_user, $id_group, $access = 'AR', $id_group = (array) $id_group; } - if ($id_group[0] != 0) { - $id_group = groups_get_all_hierarchy_group ($id_group[0]); - } - $acl_column = get_acl_column($access); if (empty($acl_column)) { @@ -712,7 +753,7 @@ function tags_get_acl_tags($id_user, $id_group, $access = 'AR', (tusuario_perfil.id_grupo IN (%s) OR tusuario_perfil.id_grupo = 0) ORDER BY id_grupo", $id_user, $acl_column, implode(',',$id_group)); $tags = db_get_all_rows_sql($query); - + // If not profiles returned, the user havent acl permissions if (empty($tags)) { return ERR_ACL; @@ -777,7 +818,7 @@ function tags_get_acl_tags($id_user, $id_group, $access = 'AR', break; case 'module_condition': // Return the condition of the tags for tagente_modulo table - $condition = tags_get_acl_tags_module_condition($acltags, $query_table); + $condition = tags_get_acl_tags_module_condition($acltags, $query_table, true); if (!empty($condition)) { return " $query_prefix " . $condition; } @@ -818,11 +859,7 @@ function tags_get_acl_tags_module_condition($acltags, $modules_table = '') { // 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 .= ' ( '; - - - - + $condition .= ' ( '; // 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 @@ -834,21 +871,22 @@ function tags_get_acl_tags_module_condition($acltags, $modules_table = '') { //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, implode(',',$group_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 .= "($group_condition AND \n$tags_condition)\n"; - } - - - + } $i++; } @@ -896,6 +934,10 @@ function tags_get_acl_tags_event_condition($acltags, $meta = false, $force_group if (empty($group_tags)) { $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])) { @@ -1001,14 +1043,14 @@ function tags_has_user_acl_tags($id_user = false) { */ function tags_get_user_tags($id_user = false, $access = 'AR') { global $config; - + if ($id_user === false) { $id_user = $config['id_user']; } // Get all tags to have the name of all of them $all_tags = tags_get_all_tags(); - + // If at least one of the profiles of this access flag hasent // tags restrictions, the user can see all tags $acl_column = get_acl_column($access); @@ -1021,18 +1063,18 @@ function tags_get_user_tags($id_user = false, $access = 'AR') { FROM tusuario_perfil, tperfil WHERE tperfil.id_perfil = tusuario_perfil.id_perfil AND tusuario_perfil.id_usuario = '%s' AND - tperfil.%s = 1 AND tags = ''", + tperfil.%s = 1 AND tags <> ''", $id_user, $acl_column); $profiles_without_tags = db_get_value_sql($query); - - if ($profiles_without_tags > 0) { + + if ($profiles_without_tags == 0) { return $all_tags; } - + // Get the tags of the required access flag for each group - $tags = tags_get_acl_tags($id_user, 0, $access, 'data'); - + $tags = tags_get_acl_tags($id_user, 0, $access, 'data','','', true, array(), true); + // Merge the tags to get an array with all of them $user_tags_id = array(); @@ -1053,8 +1095,7 @@ function tags_get_user_tags($id_user = false, $access = 'AR') { } $user_tags[$id] = $all_tags[$id]; } - - + return $user_tags; } @@ -1351,4 +1392,430 @@ function tags_checks_event_acl($id_user, $id_group, $access, $tags = array(), $c return false; } + +/** + * Get unknown agents filtering by id_tag. + * + * @param int $id_tag Id of the tag to search unknown agents + * + * @return mixed Returns count of unknown agents with this tag or false if they aren't. + */ +function tags_get_unknown_agents ($id_tag, $groups_and_tags = array()) { + + // Avoid mysql error + if (empty($id_tag)) + return; + + $groups_clause = ""; + if (!empty($groups_and_tags)) { + $i = 0; + foreach ($groups_and_tags as $group_id => $tags) { + if ($tags != "") { + $tags_arr = explode(',', $tags); + foreach ($tags_arr as $tag) { + if ($tag == $id_tag) { + if ($i == 0) { + $groups_id = $group_id; + } else { + $groups_id .= ','.$group_id; + } + $i++; + } + } + } + } + $groups_clause = " AND tagente.id_grupo IN ($groups_id)"; + } + + $total_agents = "SELECT COUNT(DISTINCT tagente.id_agente) + FROM tagente, tagente_modulo, ttag_module + WHERE tagente.id_agente = tagente_modulo.id_agente + AND tagente_modulo.id_agente_modulo = ttag_module.id_agente_modulo + AND ttag_module.id_tag = " . $id_tag . " + AND tagente.critical_count=0 + AND tagente.warning_count=0 + AND tagente.unknown_count>0 + $groups_clause"; + + return db_get_sql ($total_agents); +} + +function tags_monitors_ok ($id_tag, $groups_and_tags = array()) { + + // Avoid mysql error + if (empty($id_tag)) + return; + + $groups_clause = ""; + if (!empty($groups_and_tags)) { + $i = 0; + foreach ($groups_and_tags as $group_id => $tags) { + if ($tags != "") { + $tags_arr = explode(',', $tags); + foreach ($tags_arr as $tag) { + if ($tag == $id_tag) { + if ($i == 0) { + $groups_id = $group_id; + } else { + $groups_id .= ','.$group_id; + } + $i++; + } + } + } + } + $groups_clause = " AND id_grupo IN ($groups_id)"; + } + + $sql = "SELECT COUNT(*) FROM tagente_modulo, tagente_estado + WHERE tagente_modulo.id_agente_modulo=tagente_estado.id_agente_modulo + AND tagente_estado.estado = 0 + AND tagente_modulo.id_agente IN (SELECT id_agente FROM tagente + WHERE disabled = 0 + $groups_clause) + AND tagente_modulo.id_agente_modulo IN (SELECT id_agente_modulo FROM ttag_module + WHERE ttag_module.id_tag = " . $id_tag .")"; + + $count = db_get_sql ($sql); + + return $count; +} + +function tags_monitors_critical ($id_tag, $groups_and_tags = array()) { + + // Avoid mysql error + if (empty($id_tag)) + return; + + $groups_clause = ""; + if (!empty($groups_and_tags)) { + $i = 0; + foreach ($groups_and_tags as $group_id => $tags) { + if ($tags != "") { + $tags_arr = explode(',', $tags); + foreach ($tags_arr as $tag) { + if ($tag == $id_tag) { + if ($i == 0) { + $groups_id = $group_id; + } else { + $groups_id .= ','.$group_id; + } + $i++; + } + } + } + } + $groups_clause = " AND id_grupo IN ($groups_id)"; + } + + $sql = "SELECT COUNT(*) FROM tagente_modulo, tagente_estado + WHERE tagente_modulo.id_agente_modulo=tagente_estado.id_agente_modulo + AND tagente_estado.estado = 1 + AND tagente_modulo.id_agente IN (SELECT id_agente FROM tagente + WHERE disabled = 0 + $groups_clause) + AND tagente_modulo.id_agente_modulo IN (SELECT id_agente_modulo FROM ttag_module + WHERE ttag_module.id_tag = " . $id_tag .")"; + + $count = db_get_sql ($sql); + + return $count; +} + +function tags_monitors_warning ($id_tag, $groups_and_tags = array()) { + + // Avoid mysql error + if (empty($id_tag)) + return; + + $groups_clause = ""; + if (!empty($groups_and_tags)) { + $i = 0; + foreach ($groups_and_tags as $group_id => $tags) { + if ($tags != "") { + $tags_arr = explode(',', $tags); + foreach ($tags_arr as $tag) { + if ($tag == $id_tag) { + if ($i == 0) { + $groups_id = $group_id; + } else { + $groups_id .= ','.$group_id; + } + $i++; + } + } + } + } + $groups_clause = " AND id_grupo IN ($groups_id)"; + } + + $sql = "SELECT COUNT(*) FROM tagente_modulo, tagente_estado + WHERE tagente_modulo.id_agente_modulo=tagente_estado.id_agente_modulo + AND tagente_estado.estado = 2 + AND tagente_modulo.id_agente IN (SELECT id_agente FROM tagente + WHERE disabled = 0 + $groups_clause) + AND tagente_modulo.id_agente_modulo IN (SELECT id_agente_modulo FROM ttag_module + WHERE ttag_module.id_tag = " . $id_tag .")"; + + $count = db_get_sql ($sql); + + return $count; +} + +function tags_monitors_fired_alerts ($id_tag, $groups_and_tags = array()) { + + // Avoid mysql error + if (empty($id_tag)) + return; + + $groups_clause = ""; + if (!empty($groups_and_tags)) { + $i = 0; + foreach ($groups_and_tags as $group_id => $tags) { + if ($tags != "") { + $tags_arr = explode(',', $tags); + foreach ($tags_arr as $tag) { + if ($tag == $id_tag) { + if ($i == 0) { + $groups_id = $group_id; + } else { + $groups_id .= ','.$group_id; + } + $i++; + } + } + } + } + $groups_clause = " AND tagente.id_grupo IN ($groups_id)"; + } + + $sql = "SELECT COUNT(talert_template_modules.id) + FROM talert_template_modules, tagente_modulo, tagente_estado, tagente + WHERE tagente_modulo.id_agente = tagente.id_agente + AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo + AND tagente_modulo.disabled = 0 AND tagente.disabled = 0 + AND talert_template_modules.disabled = 0 + AND talert_template_modules.id_agent_module = tagente_modulo.id_agente_modulo + AND times_fired > 0 + AND tagente_modulo.id_agente_modulo IN (SELECT id_agente_modulo FROM ttag_module WHERE id_tag = $id_tag) + $groups_clause"; + + $count = db_get_sql ($sql); + + return $count; +} + +/* Return array with groups and their tags */ +function tags_get_user_module_and_tags ($id_user = false, $access = 'AR', $strict_user = false) { + + global $config; + + if ($id_user == false) { + $id_user = $config['id_user']; + } + + $acl_column = get_acl_column($access); + + $query = sprintf("SELECT tags, id_grupo + FROM tusuario_perfil, tperfil + WHERE tperfil.id_perfil = tusuario_perfil.id_perfil AND + tusuario_perfil.id_usuario = '%s' AND + tperfil.%s = 1 + ORDER BY id_grupo", $id_user, $acl_column); + $tags_and_groups = db_get_all_rows_sql($query); + + if ($tags_and_groups == false) { + $tags_and_groups = array(); + } + + $acltags = array(); + + if ((count($tags_and_groups) == 1) && ($tags_and_groups[0]['id_grupo'] == 0) && ($tags_and_groups[0]['tags'] == '')){ //user with all groups without tags + $all_groups = groups_get_all(); + + foreach ($all_groups as $id => $name) { + $acltags[$id] = ''; + } + } else { + foreach ($tags_and_groups as $group_tag) { + $acltags[$group_tag['id_grupo']] = $group_tag['tags']; + $propagate = db_get_value('propagate', 'tgrupo', 'id_grupo', $group_tag['id_grupo']); + + if ($propagate) { + $sql = "SELECT id_grupo FROM tgrupo WHERE parent = " .$group_tag['id_grupo']; + $children = db_get_all_rows_sql($sql); + + if ($children == false) { + $children = array(); + } + foreach ($children as $group) { + $acltags[$group['id_grupo']] = $group_tag['tags']; + } + } + } + } + + return $acltags; +} + +/** + * Get unknown agents filtering by id_tag. + * + * @param int $id_tag Id of the tag to search unknown agents + * + * @return mixed Returns count of unknown agents with this tag or false if they aren't. + */ +function tags_get_critical_agents ($id_tag, $groups_and_tags = array()) { + + // Avoid mysql error + if (empty($id_tag)) + return; + + $groups_clause = ""; + if (!empty($groups_and_tags)) { + $i = 0; + foreach ($groups_and_tags as $group_id => $tags) { + if ($tags != "") { + $tags_arr = explode(',', $tags); + foreach ($tags_arr as $tag) { + if ($tag == $id_tag) { + if ($i == 0) { + $groups_id = $group_id; + } else { + $groups_id .= ','.$group_id; + } + $i++; + } + } + } + } + $groups_clause = " AND tagente.id_grupo IN ($groups_id)"; + } + + $total_agents = "SELECT COUNT(DISTINCT tagente.id_agente) + FROM tagente, tagente_modulo, ttag_module + WHERE tagente.id_agente = tagente_modulo.id_agente + AND tagente_modulo.id_agente_modulo = ttag_module.id_agente_modulo + AND ttag_module.id_tag = " . $id_tag . " + AND tagente.critical_count>0 + $groups_clause"; + + return db_get_sql ($total_agents); +} + +function tags_get_monitors_alerts ($id_tag, $groups_and_tags = array()) { + + // Avoid mysql error + if (empty($id_tag)) + return; + + $groups_clause = ""; + if (!empty($groups_and_tags)) { + $i = 0; + foreach ($groups_and_tags as $group_id => $tags) { + if ($tags != "") { + $tags_arr = explode(',', $tags); + foreach ($tags_arr as $tag) { + if ($tag == $id_tag) { + if ($i == 0) { + $groups_id = $group_id; + } else { + $groups_id .= ','.$group_id; + } + $i++; + } + } + } + } + $groups_clause = " AND tagente.id_grupo IN ($groups_id)"; + } + + $sql = "SELECT COUNT(talert_template_modules.id) + FROM talert_template_modules, tagente_modulo, tagente_estado, tagente + WHERE tagente_modulo.id_agente = tagente.id_agente + AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo + AND tagente_modulo.disabled = 0 AND tagente.disabled = 0 + AND talert_template_modules.disabled = 0 + AND talert_template_modules.id_agent_module = tagente_modulo.id_agente_modulo + AND tagente_modulo.id_agente_modulo IN (SELECT id_agente_modulo FROM ttag_module WHERE id_tag = $id_tag) + $groups_clause"; + + $count = db_get_sql ($sql); + + return $count; +} + +/** + * Get agents filtering by id_tag. + * + * @param int $id_tag Id of the tag to search total agents + * + * @return mixed Returns count of agents with this tag or false if they aren't. + */ +function tags_get_all_user_agents ($id_tag, $id_user = false, $groups_and_tags = array(), $filter = false, $fields = false, $meta = true, $strict_user = true) { + + global $config; + + // Avoid mysql error + if (empty($id_tag)) + return; + + if (empty($id_user)) { + $id_user = $config['id_user']; + } + + if (!is_array ($fields)) { + $fields = array (); + $fields[0] = "id_agente"; + $fields[1] = "nombre"; + } + $select_fields = implode(',',$fields); + + $groups_clause = ""; + if ($strict_user) { + if (!empty($groups_and_tags)) { + $groups_clause = " AND ".tags_get_acl_tags_module_condition($groups_and_tags, "tagente_modulo"); + } + } else { + $groups_clause = " AND tagente.id_grupo IN (".implode(',',$groups_and_tags).")"; + } + + $search_sql = ""; + $void_agents = ""; + if ($filter) { + if (($filter['search']) != "") { + $string = io_safe_input ($filter['search']); + $search_sql = ' AND (tagente.nombre COLLATE utf8_general_ci LIKE "%'.$string.'%")'; + } + + if (isset($filter['show_void_agents'])) { + if (!$filter['show_void_agents']) { + $void_agents = " AND tagente_modulo.delete_pending = 0"; + } + } + } + + $user_agents_sql = "SELECT ".$select_fields ." + FROM tagente, tagente_modulo, ttag_module + WHERE tagente.id_agente = tagente_modulo.id_agente + AND tagente_modulo.id_agente_modulo = ttag_module.id_agente_modulo + AND ttag_module.id_tag = " . $id_tag . + $groups_clause . $search_sql . $void_agents . + " ORDER BY tagente.nombre ASC"; + + $user_agents = db_get_all_rows_sql($user_agents_sql); + + if (!$meta){ + $user_agents_aux = array(); + if ($user_agents === false) { + $user_agents = array(); + } + foreach ($user_agents as $ua) { + $user_agents_aux[$ua['id_agente']] = $ua['nombre']; + } + return $user_agents_aux; + } + return $user_agents; +} ?> diff --git a/pandora_console/include/functions_users.php b/pandora_console/include/functions_users.php index 04d992d16f..3808debb93 100644 --- a/pandora_console/include/functions_users.php +++ b/pandora_console/include/functions_users.php @@ -140,13 +140,13 @@ function users_get_groups_for_select($id_user, $privilege = "AR", $returnAllGro function users_get_groups ($id_user = false, $privilege = "AR", $returnAllGroup = true, $returnAllColumns = false, $id_groups = null, $keys_field = 'id_grupo') { if (empty ($id_user)) { global $config; - + $id_user = null; if (isset($config['id_user'])) { $id_user = $config['id_user']; } } - + if (isset($id_groups)) { //Get recursive id groups $list_id_groups = array(); @@ -161,11 +161,12 @@ function users_get_groups ($id_user = false, $privilege = "AR", $returnAllGroup else { $groups = db_get_all_rows_in_table ('tgrupo', 'parent, nombre'); } - + $user_groups = array (); - if (!$groups) + if (!$groups) { return $user_groups; + } if ($returnAllGroup) { //All group if ($returnAllColumns) { @@ -180,7 +181,7 @@ function users_get_groups ($id_user = false, $privilege = "AR", $returnAllGroup // Add the All group to the beginning to be always the first array_unshift($groups, $groupall); } - + foreach ($groups as $group) { if ($privilege === false) { if ($returnAllColumns) { @@ -199,7 +200,7 @@ function users_get_groups ($id_user = false, $privilege = "AR", $returnAllGroup } } } - + return $user_groups; } diff --git a/pandora_console/operation/agentes/alerts_status.functions.php b/pandora_console/operation/agentes/alerts_status.functions.php index d60cbb1379..fd3dbca8a7 100755 --- a/pandora_console/operation/agentes/alerts_status.functions.php +++ b/pandora_console/operation/agentes/alerts_status.functions.php @@ -34,13 +34,17 @@ function validateAlert() { } } -function printFormFilterAlert($id_group, $filter, $free_search, $url, $filter_standby = false, $return = false) { +function printFormFilterAlert($id_group, $filter, $free_search, $url, $filter_standby = false, $tag_filter = false, $return = false, $strict_user = false) { + + global $config; + require_once ($config['homedir'] . "/include/functions_tags.php"); + $table->width = '100%'; $table->data = array (); $table->style = array (); $table->data[0][0] = __('Group'); - $table->data[0][1] = html_print_select_groups(false, "AR", true, "ag_group", $id_group, '', '', '', true); + $table->data[0][1] = html_print_select_groups($config['id_user'], "AR", true, "ag_group", $id_group, '', '', '', true, false, false, '', false, '', false, false, 'id_grupo', $strict_user); $alert_status_filter = array(); $alert_status_filter['all_enabled'] = __('All (Enabled)'); @@ -56,7 +60,18 @@ function printFormFilterAlert($id_group, $filter, $free_search, $url, $filter_st $table->data[0][2] = __('Status'); $table->data[0][3] = html_print_select ($alert_status_filter, "filter", $filter, '', '', '', true); - $table->data[0][4] = ''; + + $table->data[0][4] = __('Tags') . ui_print_help_tip(__('Only it is show tags in use.'), true); + + $tags = tags_get_user_tags(); + + if (empty($tags)) { + $table->data[0][4] .= __('No tags'); + } + else { + $table->data[0][4] .= html_print_select ($tags, "tag_filter", $tag_filter, '', __('All'), '', true, false, true, '', false, 'width: 150px;'); + } + $table->data[1][0] = __('Free text for search') . ui_print_help_tip( __("Filter by agent name, module name, template name or action name"), diff --git a/pandora_console/operation/agentes/alerts_status.php b/pandora_console/operation/agentes/alerts_status.php index 7c367e26c5..b4e02e65b8 100755 --- a/pandora_console/operation/agentes/alerts_status.php +++ b/pandora_console/operation/agentes/alerts_status.php @@ -38,11 +38,19 @@ require_once ($config['homedir'] . '/include/functions_users.php'); $isFunctionPolicies = enterprise_include_once ('include/functions_policies.php'); +$strict_user = db_get_value('strict_acl', 'tusuario', 'id_user', $config['id_user']); + $filter = get_parameter ("filter", "all_enabled"); $filter_standby = get_parameter ("filter_standby", "all"); $offset_simple = (int) get_parameter_get ("offset_simple", 0); $id_group = (int) get_parameter ("ag_group", 0); //0 is the All group (selects all groups) $free_search = get_parameter("free_search", ''); +$tag_filter = get_parameter("tag_filter", 0); +if ($tag_filter) { + if ($id_group && $strict_user) { + $tag_filter = 0; + } +} $sec2 = get_parameter_get ('sec2'); $sec2 = safe_url_extraclean ($sec2); @@ -58,7 +66,7 @@ $refr = (int)get_parameter('refr', 0); $pure = get_parameter('pure', 0); $url = 'index.php?sec=' . $sec . '&sec2=' . $sec2 . '&refr=' . $refr . '&filter=' . $filter . '&filter_standby=' . $filter_standby . - '&ag_group=' . $id_group; + '&ag_group=' . $id_group .'&tag_filter=' .$tag_filter; if ($flag_alert == 1 && check_acl($config['id_user'], $id_group, "AW")) { forceExecution($id_group); @@ -325,48 +333,33 @@ else { if (defined('METACONSOLE')) { require_once ($config['homedir'] . '/enterprise/meta/include/functions_alerts_meta.php'); if ($idAgent != 0) { - $alerts['alerts_simple'] = alerts_meta_get_alerts ($agents, - $filter_alert, $options_simple, $whereAlertSimple, false, false, - $idGroup); + $alerts['alerts_simple'] = alerts_meta_get_alerts ($agents, $filter_alert, $options_simple, $whereAlertSimple, false, false, $idGroup, false, $strict_user); + + $countAlertsSimple = alerts_meta_get_alerts ($agents, $filter_alert, false, $whereAlertSimple, false, false, $idGroup, true, $strict_user); - - $countAlertsSimple = alerts_meta_get_alerts ($agents, $filter_alert, - false, $whereAlertSimple, false, false, $idGroup, true); } else { $id_groups = array_keys( users_get_groups($config["id_user"], 'AR', false)); - $alerts['alerts_simple'] = alerts_meta_get_group_alerts($id_groups, - $filter_alert, $options_simple, $whereAlertSimple, false, - false, $idGroup); + $alerts['alerts_simple'] = alerts_meta_get_group_alerts($id_groups, $filter_alert, $options_simple, $whereAlertSimple, false, false, $idGroup, false, $strict_user, $tag_filter); - $countAlertsSimple = alerts_meta_get_group_alerts($id_groups, - $filter_alert, false, $whereAlertSimple, false, false, - $idGroup, true); + $countAlertsSimple = alerts_meta_get_group_alerts($id_groups, $filter_alert, false, $whereAlertSimple, false, false, $idGroup, true, $strict_user, $tag_filter); } } else { if ($idAgent != 0) { - $alerts['alerts_simple'] = agents_get_alerts_simple ($idAgent, - $filter_alert, $options_simple, $whereAlertSimple, false, false, - $idGroup); + $alerts['alerts_simple'] = agents_get_alerts_simple ($idAgent, $filter_alert, $options_simple, $whereAlertSimple, false, false, $idGroup, false, $strict_user, $tag_filter); - $countAlertsSimple = agents_get_alerts_simple ($idAgent, - $filter_alert, false, $whereAlertSimple, false, false, - $idGroup, true); + $countAlertsSimple = agents_get_alerts_simple ($idAgent, $filter_alert, false, $whereAlertSimple, false, false, $idGroup, true, $strict_user, $tag_filter); } else { $id_groups = array_keys( users_get_groups($config["id_user"], 'AR', false)); - $alerts['alerts_simple'] = get_group_alerts($id_groups, - $filter_alert, $options_simple, $whereAlertSimple, false, - false, $idGroup); + $alerts['alerts_simple'] = get_group_alerts($id_groups, $filter_alert, $options_simple, $whereAlertSimple, false, false, $idGroup, false, $strict_user, $tag_filter); - $countAlertsSimple = get_group_alerts($id_groups, - $filter_alert, false, $whereAlertSimple, false, false, - $idGroup, true); + $countAlertsSimple = get_group_alerts($id_groups, $filter_alert, false, $whereAlertSimple, false, false, $idGroup, true, $strict_user, $tag_filter); } } @@ -381,10 +374,7 @@ if ($pure) { // Filter form if ($print_agent) { echo '
'; - ui_toggle( - printFormFilterAlert( - $id_group, $filter, $free_search, $url, $filter_standby, true), - __('Alert control filter'), __('Toggle filter(s)')); + ui_toggle(printFormFilterAlert($id_group, $filter, $free_search, $url, $filter_standby, $tag_filter, true, $strict_user),__('Alert control filter'), __('Toggle filter(s)')); } $table->width = '100%'; @@ -428,26 +418,14 @@ if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK) { // Sort buttons are only for normal console if (!defined('METACONSOLE')) { $table->head[3] .= ' ' . - '' . - html_print_image("images/sort_up.png", true, - array("style" => $selectAgentUp)) . '' . - '' . - html_print_image("images/sort_down.png", true, - array("style" => $selectAgentDown)) . ''; + '' . html_print_image("images/sort_up.png", true, array("style" => $selectAgentUp)) . '' . + '' . html_print_image("images/sort_down.png", true, array("style" => $selectAgentDown)) . ''; $table->head[4] .= ' ' . - '' . - html_print_image("images/sort_up.png", true, - array("style" =>$selectModuleUp)) . '' . - '' . - html_print_image("images/sort_down.png", true, - array("style" => $selectModuleDown)) . ''; + '' . html_print_image("images/sort_up.png", true, array("style" =>$selectModuleUp)) . '' . + '' . html_print_image("images/sort_down.png", true, array("style" => $selectModuleDown)) . ''; $table->head[5] .= ' ' . - '' . - html_print_image("images/sort_up.png", true, - array("style" =>$selectTemplateUp)) . '' . - '' . - html_print_image("images/sort_down.png", true, - array("style" => $selectTemplateDown)) . ''; + '' . html_print_image("images/sort_up.png", true, array("style" =>$selectTemplateUp)) . '' . + '' . html_print_image("images/sort_down.png", true, array("style" => $selectTemplateDown)) . ''; } } else { @@ -477,19 +455,11 @@ if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK) { // Sort buttons are only for normal console if (!defined('METACONSOLE')) { $table->head[3] .= ' ' . - '' . - html_print_image("images/sort_up.png", true, - array("style" => $selectModuleUp)) . '' . - '' . - html_print_image("images/sort_down.png", true, - array("style" => $selectModuleDown)) . ''; + '' . html_print_image("images/sort_up.png", true, array("style" => $selectModuleUp)) . '' . + '' . html_print_image("images/sort_down.png", true, array("style" => $selectModuleDown)) . ''; $table->head[4] .= ' ' . - '' . - html_print_image("images/sort_up.png", true, - array("style" => $selectTemplateUp)) . '' . - '' . - html_print_image("images/sort_down.png", true, - array("style" => $selectTemplateDown)) . ''; + '' . html_print_image("images/sort_up.png", true, array("style" => $selectTemplateUp)) . '' . + '' . html_print_image("images/sort_down.png", true, array("style" => $selectTemplateDown)) . ''; } } } @@ -599,6 +569,17 @@ else { echo '
'.__('No alerts found').'
'; } +//strict user hidden +echo ''; + enterprise_hook('close_meta_frame'); @@ -615,5 +596,32 @@ $(document).ready (function () { }).click (function () { return false; }); + + if ($('#ag_group').val() != 0) { + $("#tag_filter").css('display', 'none'); + $("#table2-0-4").css('display', 'none'); + } +}); + + +$('#ag_group').change (function (){ + strict_user = $("#text-strict_user_hidden").val(); + is_meta = $("#text-is_meta_hidden").val(); + + if (($("#ag_group").val() != 0) && (strict_user != 0)) { + $("#tag_filter").css('display', 'none'); + if (is_meta) { + $("#table1-0-4").css('display', 'none'); + } else { + $("#table2-0-4").css('display', 'none'); + } + } else { + $("#tag_filter").css('display', ''); + if (is_meta) { + $("#table1-0-4").css('display', ''); + } else { + $("#table2-0-4").css('display', ''); + } + } }); diff --git a/pandora_console/operation/agentes/status_monitor.php b/pandora_console/operation/agentes/status_monitor.php index 15c81ec908..755ee8e2a3 100644 --- a/pandora_console/operation/agentes/status_monitor.php +++ b/pandora_console/operation/agentes/status_monitor.php @@ -34,6 +34,8 @@ enterprise_include_once ('include/functions_metaconsole.php'); $isFunctionPolicies = enterprise_include_once ('include/functions_policies.php'); +$strict_user = db_get_value('strict_acl', 'tusuario', 'id_user', $config['id_user']); + if (! defined ('METACONSOLE')) { //Header ui_print_page_header (__("Monitor detail"), "images/brick.png", false); @@ -43,8 +45,6 @@ else { ui_meta_print_header(__("Monitor view")); } - - $ag_freestring = get_parameter ('ag_freestring'); $ag_modulename = (string) get_parameter ('ag_modulename'); if (!defined('METACONSOLE')) { @@ -68,6 +68,11 @@ $offset = (int) get_parameter ('offset', 0); $status = (int) get_parameter ('status', 4); $modulegroup = get_parameter ('modulegroup', -1); $tag_filter = get_parameter('tag_filter', 0); +if ($tag_filter) { + if ($ag_group && $strict_user) { + $tag_filter = 0; + } +} $refr = get_parameter('refr', 0); // Sort functionality @@ -108,6 +113,7 @@ else { $id_ag_group = db_get_value('id_grupo', 'tgrupo', 'nombre', $ag_group); } + // Agent group selector if (!defined('METACONSOLE')) { if ($ag_group > 0 && check_acl ($config["id_user"], $ag_group, "AR")) { @@ -119,8 +125,9 @@ if (!defined('METACONSOLE')) { } } else { + if ($ag_group != "0" && check_acl ($config["id_user"], $id_ag_group, "AR")) { - $sql_conditions_group = sprintf (" AND tagente.id_grupo IN ( SELECT id_grupo FROM tgrupo where nombre = '%s') ", $ag_group); + $sql_conditions_group = sprintf (" AND tagente.id_grupo IN (%s) ", $ag_group); } elseif ($user_groups != '') { // User has explicit permission on group 1 ? @@ -200,7 +207,7 @@ if ($tag_filter !== 0) { $sql_conditions .= " AND tagente_modulo.id_agente_modulo IN ( SELECT ttag_module.id_agente_modulo FROM ttag_module - WHERE ttag_module.id_tag IN (SELECT id_tag FROM ttag where name LIKE '%" . $tag_filter . "%') + WHERE ttag_module.id_tag IN ($tag_filter) )"; } else { @@ -213,14 +220,13 @@ if ($tag_filter !== 0) { } } -if (defined('METACONSOLE') && $ag_group !== 0) { - $ag_group = groups_get_id($ag_group); -} - // Fix: for tag functionality groups have to be all user_groups (propagate ACL funct!) $groups = users_get_groups($config["id_user"]); - -$sql_conditions_tags = tags_get_acl_tags($config['id_user'], array_keys($groups), 'AR', 'module_condition', 'AND', 'tagente_modulo'); +if ($ag_group !== 0) { + $sql_conditions_tags = tags_get_acl_tags($config['id_user'], $ag_group, 'AR', 'module_condition', 'AND', 'tagente_modulo', true, array(), true); +} else { + $sql_conditions_tags = tags_get_acl_tags($config['id_user'], array_keys($groups), 'AR', 'module_condition', 'AND', 'tagente_modulo', true, array(), true); +} if (is_numeric($sql_conditions_tags)) { $sql_conditions_tags = ' AND 1 = 0'; @@ -230,6 +236,11 @@ if (is_numeric($sql_conditions_tags)) { $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; +if (!$strict_user) { + $sql_conditions_all = $sql_conditions_base . $sql_conditions . $sql_conditions_group . $sql_conditions_custom_fields; + $sql_conditions_acl = $sql_conditions_base . $sql_conditions_group . $sql_conditions_custom_fields; +} + // Get count to paginate if (!defined('METACONSOLE')) $count = db_get_sql ("SELECT COUNT(tagente_modulo.id_agente_modulo) " . $sql_from . $sql_conditions_all); @@ -334,22 +345,7 @@ if (defined('METACONSOLE')) { // Get all info for filters of all nodes $modules_temp = db_get_all_rows_sql($sql); - - # Fix : only user tags have to be shown in these component - $_tags = tags_get_user_tags(); - - - if (!empty($_tags)) { - foreach ($_tags as $_tag) { - - $tags_temp[]['name'] = $_tag; - - } - - } - - $rows_temp = db_get_all_rows_sql("SELECT distinct name FROM tmodule_group ORDER BY name"); @@ -377,8 +373,6 @@ if (defined('METACONSOLE')) { if (!empty($modules_temp)) $modules = array_merge($modules, $modules_temp); - if (!empty($tags_temp)) - $tags = array_merge($tags, $tags_temp); metaconsole_restore_db(); } @@ -388,28 +382,17 @@ if (defined('METACONSOLE')) { unset($groups_select[$key_group_all]); } -if (!defined('METACONSOLE')) { - echo ' - ' . __('Group') . ' - ' . - html_print_select_groups(false, "AR", true, "ag_group", - $ag_group, '', '', '0', true, false, false, 'w130', - false, 'width:150px;') . ' - '; -} -else { - echo ' - ' . __('Group') . ' - ' . - html_print_select($groups_select, "ag_group", - io_safe_output($ag_group_metaconsole), '', __('All'), '0', true, false, false, 'w130', - false, 'width:150px;') . ' - '; -} +echo ' +' . __('Group') . ' +' . + html_print_select_groups($config['id_user'], "AR", true, "ag_group", + $ag_group, '', '', '0', true, false, false, 'w130', + false, 'width:150px;', false, false, + 'id_grupo', $strict_user) . ' +'; + echo '' . __('Monitor status') . ""; - - echo ""; $fields = array (); @@ -421,11 +404,9 @@ $fields[AGENT_MODULE_STATUS_NOT_NORMAL] = __('Not normal'); //default $fields[AGENT_MODULE_STATUS_NOT_INIT] = __('Not init'); html_print_select ($fields, "status", $status, '', __('All'), -1, - false, false, true, '', false, 'width: 125px;'); + false, false, true, '', false, 'width: 150px;'); echo ''; - - echo '' . __('Module group') . ''; echo ''; if (!defined('METACONSOLE')) { @@ -440,17 +421,13 @@ if (!defined('METACONSOLE')) { $rows_select[0] = __('Not assigned'); -html_print_select($rows_select, 'modulegroup', $modulegroup, '', __('All'), -1); +html_print_select($rows_select, 'modulegroup', $modulegroup, '', __('All'),-1,false, false, true, '', false, 'width: 120px;'); echo ''; - - echo ''; echo ''; - - echo '' . __('Module name') . ''; echo ''; @@ -463,32 +440,6 @@ html_print_select (index_array ($modules, 'nombre', 'nombre'), "ag_modulename", echo ''; - -echo '' . - __('Tags') . - ui_print_help_tip(__('Only it is show tags in use.'), true) . - ''; -echo ''; - -if (!defined('METACONSOLE')) { - $tags = tags_get_user_tags(); -} - -if (empty($tags)) { - echo __('No tags'); -} -else { - if (!defined('METACONSOLE')) - html_print_select ($tags, "tag_filter", - $tag_filter, '', __('All'), '', false, false, true, '', false, 'width: 150px;'); - else - html_print_select (index_array($tags, 'name', 'name'), "tag_filter", - $tag_filter, '', __('All'), '', false, false, true, '', false, 'width: 150px;'); -} -echo ''; - - - echo '' . __('Search') . ''; @@ -496,7 +447,21 @@ echo ''; html_print_input_text ("ag_freestring", $ag_freestring, '', 20,30, false); echo ''; +echo '' . + __('Tags') . + ui_print_help_tip(__('Only it is show tags in use.'), true); +echo ''; +$tags = tags_get_user_tags(); + +if (empty($tags)) { + echo __('No tags'); +} +else { + + html_print_select ($tags, "tag_filter", $tag_filter, '', __('All'), '', false, false, true, '', false, 'width: 150px;'); +} +echo ''; echo ''; html_print_submit_button (__('Show'), "uptbutton", false, 'class="sub search"'); @@ -732,6 +697,7 @@ switch ($config["dbtype"]) { $sql_from . $sql_conditions_all . " ORDER BY " . $order['field'] . " " . $order['order'] . " LIMIT ".$offset.",".$limit_sql; + break; case "postgresql": if (strstr($config['dbversion'], "8.4") !== false) { @@ -841,7 +807,7 @@ else { WHERE disabled = 0"); if ($servers === false) $servers = array(); - + $result = array(); $count_modules = 0; foreach ($servers as $server) { @@ -941,10 +907,6 @@ if (! defined ('METACONSOLE')) { '' . html_print_image("images/sort_down.png", true, array("style" => $selectModuleNameDown, "alt" => "down")) . ''; } -/* -$table->head[4] = __('Tags'); -*/ - $table->head[5] = __('Interval'); if (! defined ('METACONSOLE')) { $table->head[5] .= ' ' . html_print_image("images/sort_up.png", true, array("style" => $selectIntervalUp, "alt" => "up")) . '' . @@ -1188,7 +1150,6 @@ foreach ($result as $row) { $data[7] = '' . html_print_image("images/chart_curve.png", true, array("border" => '0', "alt" => "")) . ''; if (defined('METACONSOLE')) - //$data[7] .= " " . html_print_image('images/binary.png', true, array("style" => '0', "alt" => '')) . ""; $data[7] .= "". html_print_image ("images/binary.png", true, array ("border" => "0", "alt" => "")) . ""; else $data[7] .= " " . html_print_image('images/binary.png', true, array("style" => '0', "alt" => '')) . ""; @@ -1257,8 +1218,6 @@ foreach ($result as $row) { } } - - if ($module_value == $sub_string) { $salida = $module_value; } @@ -1307,12 +1266,37 @@ else { echo "
"; +//strict user hidden +echo ''; + + enterprise_hook('close_meta_frame'); ui_require_javascript_file('pandora_modules'); ?>