From 7e4a2ba7a936c3f8f97b7105932a4966b0d32c6b Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Mon, 24 Mar 2014 11:41:54 +0000 Subject: [PATCH] 2014-03-24 Miguel de Dios * godmode/massive/massive_edit_agents.php, godmode/massive/massive_delete_agents.php, godmode/groups/group_list.php, include/functions_agents.php, include/javascript/jquery.pandora.controls.js, operation/agentes/ver_agente.php, operation/agentes/estado_monitores.php: added the feature to filter by agent status in the massive operations into "massive agent deletion" and "massive agent edition". Incident: #669 git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@9639 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 13 ++++ pandora_console/godmode/groups/group_list.php | 7 ++- .../godmode/massive/massive_delete_agents.php | 61 +++++++++++++------ .../godmode/massive/massive_edit_agents.php | 29 +++++++-- pandora_console/include/functions_agents.php | 30 +++++++++ .../javascript/jquery.pandora.controls.js | 26 ++++---- .../operation/agentes/estado_monitores.php | 8 ++- .../operation/agentes/ver_agente.php | 11 ++-- 8 files changed, 144 insertions(+), 41 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index d1fb1a5fc8..5dc63e8f4c 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,16 @@ +2014-03-24 Miguel de Dios + + * godmode/massive/massive_edit_agents.php, + godmode/massive/massive_delete_agents.php, + godmode/groups/group_list.php, include/functions_agents.php, + include/javascript/jquery.pandora.controls.js, + operation/agentes/ver_agente.php, + operation/agentes/estado_monitores.php: added the feature to filter + by agent status in the massive operations into + "massive agent deletion" and "massive agent edition". + + Incident: #669 + 2014-03-21 Miguel de Dios * include/constants.php: added lost constant for diff --git a/pandora_console/godmode/groups/group_list.php b/pandora_console/godmode/groups/group_list.php index 9d1c997f2d..06fd68c6b0 100644 --- a/pandora_console/godmode/groups/group_list.php +++ b/pandora_console/godmode/groups/group_list.php @@ -71,6 +71,7 @@ if (is_ajax ()) { $keys_prefix = (string) get_parameter ('keys_prefix', ''); // Ids of agents to be include in the SQL clause as id_agent IN () $filter_agents_json = (string) get_parameter ('filter_agents_json', ''); + $status_agents = (int)get_parameter('status_agents', AGENT_STATUS_ALL); if (! check_acl ($config['id_user'], $id_group, "AR")) { db_pandora_audit("ACL Violation", @@ -89,7 +90,11 @@ if (is_ajax ()) { $filter['string'] = $search; } - $agents = agents_get_group_agents ($id_group, $filter, "none", false, $recursion); + if ($status_agents != AGENT_STATUS_ALL) { + $filter['status'] = $status_agents; + } + + $agents = agents_get_group_agents($id_group, $filter, "none", false, $recursion); // Add keys prefix if ($keys_prefix !== "") { diff --git a/pandora_console/godmode/massive/massive_delete_agents.php b/pandora_console/godmode/massive/massive_delete_agents.php index a41b2df69f..eea1639793 100644 --- a/pandora_console/godmode/massive/massive_delete_agents.php +++ b/pandora_console/godmode/massive/massive_delete_agents.php @@ -102,16 +102,29 @@ $table->size[3] = '35%'; $table->data = array (); $table->data[0][0] = __('Group'); -$table->data[0][1] = html_print_select_groups(false, "AR", true, 'id_group', $id_group, - false, '', '', true); +$table->data[0][1] = html_print_select_groups(false, "AR", true, + 'id_group', $id_group, false, '', '', true); $table->data[0][2] = __('Group recursion'); -$table->data[0][3] = html_print_checkbox ("recursion", 1, $recursion, true, false); +$table->data[0][3] = html_print_checkbox ("recursion", 1, $recursion, + true, false); -$table->data[1][0] = __('Agents'); -$table->data[1][0] .= ''; -$table->data[1][1] = html_print_select (agents_get_group_agents ($id_group, false, "none"), +$status_list = array (); +$status_list[AGENT_STATUS_NORMAL] = __('Normal'); +$status_list[AGENT_STATUS_WARNING] = __('Warning'); +$status_list[AGENT_STATUS_CRITICAL] = __('Critical'); +$status_list[AGENT_STATUS_UNKNOWN] = __('Unknown'); +$status_list[AGENT_STATUS_NOT_NORMAL] = __('Not normal'); +$status_list[AGENT_STATUS_NOT_INIT] = __('Not init'); +$table->data[1][0] = __('Status'); +$table->data[1][1] = html_print_select($status_list, 'status_agents', 'selected', + '', __('All'), AGENT_STATUS_ALL, true); + +$table->data[2][0] = __('Agents'); +$table->data[2][0] .= ''; +$table->data[2][1] = html_print_select( + agents_get_group_agents($id_group, false, "none"), 'id_agents[]', 0, false, '', '', true, true); echo '
'; @@ -130,15 +143,27 @@ ui_require_jquery_file ('pandora.controls'); ?> diff --git a/pandora_console/godmode/massive/massive_edit_agents.php b/pandora_console/godmode/massive/massive_edit_agents.php index a9608a5772..4b1274c8a9 100644 --- a/pandora_console/godmode/massive/massive_edit_agents.php +++ b/pandora_console/godmode/massive/massive_edit_agents.php @@ -198,14 +198,26 @@ $table->data[0][1] = html_print_select_groups(false, "AR", true, 'id_group', $id $table->data[0][2] = __('Group recursion'); $table->data[0][3] = html_print_checkbox ("recursion", 1, $recursion, true, false); -$table->data[1][0] = __('Agents'); -$table->data[1][0] .= ''; + +$status_list = array (); +$status_list[AGENT_STATUS_NORMAL] = __('Normal'); +$status_list[AGENT_STATUS_WARNING] = __('Warning'); +$status_list[AGENT_STATUS_CRITICAL] = __('Critical'); +$status_list[AGENT_STATUS_UNKNOWN] = __('Unknown'); +$status_list[AGENT_STATUS_NOT_NORMAL] = __('Not normal'); +$status_list[AGENT_STATUS_NOT_INIT] = __('Not init'); +$table->data[1][0] = __('Status'); +$table->data[1][1] = html_print_select($status_list, 'status_agents', 'selected', + '', __('All'), AGENT_STATUS_ALL, true); + +$table->data[2][0] = __('Agents'); +$table->data[2][0] .= ''; $enabled_agents = agents_get_group_agents ($id_group, array('disabled' => 0), "none"); $all_agents = agents_get_group_agents ($id_group, array('disabled' => 1), "none") + $enabled_agents; -$table->data[1][1] = html_print_select ($all_agents, +$table->data[2][1] = html_print_select ($all_agents, 'id_agents[]', 0, false, '', '', true, true); echo ''; @@ -463,9 +475,16 @@ $(document).ready (function () { $("#id_group").pandoraSelectGroupAgent ({ agentSelect: "select#id_agents", + status_agents: function () { + return $("#status_agents").val(); + }, recursion: function() {return recursion} }); + $("#status_agents").change(function() { + $("#id_group").trigger("change"); + }); + $("#id_group").pandoraSelectGroupAgentDisabled ({ agentSelect: "select#id_agents", recursion: function() {return recursion} diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 6fc6dee4d5..8e5bd080de 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -820,6 +820,36 @@ function agents_get_group_agents ($id_group = 0, $search = false, $case = "lower unset ($search["name"]); } + if (isset($search['status'])) { + switch ($search['status']) { + case AGENT_STATUS_NORMAL: + $search_sql .= + " AND normal_count = total_count"; + break; + case AGENT_STATUS_WARNING: + $search_sql .= + " AND critical_count = 0 AND warning_count > 0"; + break; + case AGENT_STATUS_CRITICAL: + $search_sql .= + " AND critical_count > 0"; + break; + case AGENT_STATUS_UNKNOWN: + $search_sql .= + " AND critical_count = 0 AND warning_count = 0 + AND unknown_count > 0"; + break; + case AGENT_STATUS_NOT_NORMAL: + $search_sql .= " AND normal_count <> total_count"; + break; + case AGENT_STATUS_NOT_INIT: + $search_sql .= " AND notinit_count = total_count"; + break; + } + unset($search['status']); + } + + if (! empty ($search)) { $search_sql .= ' AND '.db_format_array_where_clause_sql ($search); } diff --git a/pandora_console/include/javascript/jquery.pandora.controls.js b/pandora_console/include/javascript/jquery.pandora.controls.js index 26d4b80dcf..dd41f63f9c 100644 --- a/pandora_console/include/javascript/jquery.pandora.controls.js +++ b/pandora_console/include/javascript/jquery.pandora.controls.js @@ -2,12 +2,13 @@ var dummyFunc = function () { return true; }; - + var _pandoraSelectGroupAgent = function (disabled) { var that = this; - + this.defaults = { agentSelect: "select#id_agent", + status_agents: -1, recursion: 0, filter_agents_json: "", loading: "#agent_loading", @@ -18,22 +19,22 @@ debug: false, disabled: disabled || false, }; - + /* public methods */ this.construct = function (settings) { return this.each (function() { this.config = {}; - + this.config = $.extend (this.config, that.defaults, settings); var config = this.config; - + $(this).change (function () { var $select = $(config.agentSelect).disable (); $(config.loading).show (); $("option[value!=0]", $select).remove (); if (! config.callbackBefore (this)) return; - + var opts = { "page" : "godmode/groups/group_list", "get_group_agents" : 1, @@ -41,17 +42,18 @@ "recursion" : config.recursion, "filter_agents_json" : config.filter_agents_json, "disabled" : config.disabled ? 1 : 0, + "status_agents" : config.status_agents, // Add a key prefix to avoid auto sorting in js object conversion "keys_prefix" : "_" }; - + jQuery.post ("ajax.php", opts, function (data, status) { jQuery.each (data, function (id, value) { // Remove keys_prefix from the index id = id.substring(1); - if (id !== 'keycount'){ + if (id !== 'keycount') { config.callbackPre (); option = $("") .attr ("value", id) @@ -137,7 +139,7 @@ ); }); }); - + }; } }); @@ -162,7 +164,7 @@ this.config = $.extend (this.config, $.pandoraSelectAgentAlert.defaults, settings); var config = this.config; - + $(this).change (function () { var $select = $(config.alertSelect).disable (); $(config.loading).show (); @@ -212,7 +214,7 @@ this.config = $.extend (this.config, $.pandoraSelectOS.defaults, settings); var config = this.config; - + $(this).change (function () { var id_os = this.value; @@ -259,7 +261,7 @@ this.config = $.extend (this.config, $.pandoraSelectGroupIcon.defaults, settings); var config = this.config; - + $(this).change (function () { var id_group = this.value; diff --git a/pandora_console/operation/agentes/estado_monitores.php b/pandora_console/operation/agentes/estado_monitores.php index 408f764811..214bc0185f 100644 --- a/pandora_console/operation/agentes/estado_monitores.php +++ b/pandora_console/operation/agentes/estado_monitores.php @@ -383,7 +383,13 @@ foreach ($modules as $module) { $data = array (); if (($module["id_modulo"] != 1) && ($module["id_tipo_modulo"] != 100)) { if ($module["flag"] == 0) { - $data[0] = '' . html_print_image("images/target.png", true, array("border" => '0', "title" => __('Force'))) . ''; + $data[0] = '' . html_print_image("images/target.png", true, array("border" => '0', "title" => __('Force'))) . ''; } else { $data[0] = '' . html_print_image("images/refresh.png", true, array("border" => "0", "title" => __("Refresh"))) . ''; diff --git a/pandora_console/operation/agentes/ver_agente.php b/pandora_console/operation/agentes/ver_agente.php index f850ba0c09..f0be0db2bf 100644 --- a/pandora_console/operation/agentes/ver_agente.php +++ b/pandora_console/operation/agentes/ver_agente.php @@ -52,7 +52,8 @@ if (is_ajax ()) { if ($id_group > 0) { $groups = array($id_group); if ($recursion) { - $groups = array_merge($groups, groups_get_id_recursive($id_group, true)); + $groups = array_merge($groups, + groups_get_id_recursive($id_group, true)); } } else { @@ -61,13 +62,14 @@ if (is_ajax ()) { $groups = array_keys($groups_orig); } - $filter = " WHERE id_grupo IN (". implode(',', $groups) .") ORDER BY nombre ASC"; + $filter = " WHERE id_grupo IN (" . implode(',', $groups) . ") + ORDER BY nombre ASC"; $agents = db_get_all_rows_sql("SELECT id_agente, nombre FROM tagente" . $filter); // Add keys prefix if ($keys_prefix !== "") { - foreach($agents as $k => $v) { + foreach ($agents as $k => $v) { $agents[$keys_prefix . $k] = $v; unset($agents[$k]); } @@ -689,7 +691,8 @@ if ($flag !== '') { if ($flag == 1 && check_acl ($config['id_user'], $id_grupo, "AW")) { $id_agent_module = get_parameter('id_agente_modulo'); - db_process_sql_update('tagente_modulo', array('flag' => 1), array('id_agente_modulo' => $id_agent_module)); + db_process_sql_update('tagente_modulo', + array('flag' => 1), array('id_agente_modulo' => $id_agent_module)); } } // Check for Network FLAG change request