From db7680eb46032d2a7139df48f15b2925eb88e621 Mon Sep 17 00:00:00 2001 From: m-lopez-f Date: Wed, 21 Jan 2015 15:26:49 +0100 Subject: [PATCH] Add filter group module in general view of agents --- pandora_console/include/ajax/module.php | 94 ++++++++++++------- .../operation/agentes/estado_monitores.php | 25 ++++- 2 files changed, 78 insertions(+), 41 deletions(-) diff --git a/pandora_console/include/ajax/module.php b/pandora_console/include/ajax/module.php index 2ff6afe878..5dca8c9095 100755 --- a/pandora_console/include/ajax/module.php +++ b/pandora_console/include/ajax/module.php @@ -476,6 +476,7 @@ if ($list_modules) { $status_filter_monitor = (int)get_parameter('status_filter_monitor', -1); $status_text_monitor = get_parameter('status_text_monitor', ''); $filter_monitors = (bool)get_parameter('filter_monitors', false); + $status_module_group = get_parameter('status_module_group', -1); $monitors_change_filter = (bool)get_parameter('monitors_change_filter', false); $status_filter_sql = '1 = 1'; @@ -486,6 +487,13 @@ if ($list_modules) { $status_filter_sql = 'tagente_estado.estado = ' . $status_filter_monitor; } + if($status_module_group != -1){ + $status_module_group_filter = 'id_module_group = ' . $status_module_group; + } + else{ + $status_module_group_filter = 'id_module_group >= 0'; + } + $status_text_monitor_sql = '%'; if (!empty($status_text_monitor)) { $status_text_monitor_sql .= $status_text_monitor . '%'; @@ -496,19 +504,21 @@ if ($list_modules) { switch ($config["dbtype"]) { case "mysql": $sql = sprintf(" - SELECT COUNT(*) - FROM tagente_estado, - (SELECT * - FROM tagente_modulo - WHERE id_agente = %d AND nombre LIKE \"%s\" AND delete_pending = 0 - AND disabled = 0) tagente_modulo - LEFT JOIN tmodule_group - ON tagente_modulo.id_module_group = tmodule_group.id_mg - WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND %s %s - AND tagente_estado.estado != %d - ORDER BY tagente_modulo.id_module_group , %s %s", - $id_agente, $status_text_monitor_sql, $status_filter_sql, $tags_sql, AGENT_MODULE_STATUS_NO_DATA, $order['field'], $order['order']); + SELECT COUNT(*) + FROM tagente_estado, + (SELECT * + FROM tagente_modulo + WHERE id_agente = %d AND nombre LIKE \"%s\" AND delete_pending = 0 + AND disabled = 0 AND %s) tagente_modulo + LEFT JOIN tmodule_group + ON tagente_modulo.id_module_group = tmodule_group.id_mg + WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo + AND %s %s + AND tagente_estado.estado != %d + AND tagente_modulo.%s + ORDER BY tagente_modulo.id_module_group , %s %s", + $id_agente, $status_text_monitor_sql,$status_module_group_filter,$status_filter_sql, $tags_sql, AGENT_MODULE_STATUS_NO_DATA, + $status_module_group_filter, $order['field'], $order['order']); break; case "postgresql": $sql = sprintf(" @@ -518,22 +528,23 @@ if ($list_modules) { FROM tagente_modulo WHERE id_agente = %d AND nombre LIKE '%s' AND delete_pending = 0 - AND disabled = 0) tagente_modulo + AND disabled = 0 AND %s) tagente_modulo LEFT JOIN tmodule_group ON tagente_modulo.id_module_group = tmodule_group.id_mg WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND %s %s AND tagente_estado.estado != %d + AND tagente_modulo.%s GROUP BY tagente_modulo.id_module_group, tagente_modulo.nombre ORDER BY tagente_modulo.id_module_group , %s %s", - $id_agente, $status_text_monitor_sql, $status_filter_sql, - $tags_sql, AGENT_MODULE_STATUS_NO_DATA, $order['field'], + $id_agente, $status_text_monitor_sql,$status_module_group_filter,$status_filter_sql, + $tags_sql, AGENT_MODULE_STATUS_NO_DATA,$status_module_group_filter,$order['field'], $order['order']); break; case "oracle": $sql = sprintf (" - SELECT COUNT(*)" . + SELECT COUNT(*)" . " FROM tagente_estado, tagente_modulo LEFT JOIN tmodule_group ON tmodule_group.id_mg = tagente_modulo.id_module_group @@ -544,8 +555,10 @@ if ($list_modules) { AND tagente_modulo.delete_pending = 0 AND tagente_modulo.disabled = 0 AND tagente_estado.estado != %d + AND tagente_modulo.%s ORDER BY tagente_modulo.id_module_group , %s %s - ", $id_agente, $status_text_monitor_sql, $status_filter_sql, $tags_sql, AGENT_MODULE_STATUS_NO_DATA, $order['field'], $order['order']); + ", $id_agente, $status_text_monitor_sql, $status_filter_sql, $tags_sql, AGENT_MODULE_STATUS_NO_DATA, + $status_module_group_filter,$order['field'], $order['order']); break; } @@ -566,14 +579,17 @@ if ($list_modules) { (SELECT * FROM tagente_modulo WHERE id_agente = %d AND nombre LIKE \"%s\" AND delete_pending = 0 - AND disabled = 0) tagente_modulo + AND disabled = 0 AND %s) tagente_modulo LEFT JOIN tmodule_group ON tagente_modulo.id_module_group = tmodule_group.id_mg WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND %s %s AND tagente_estado.estado != %d + AND tagente_modulo.%s ORDER BY tagente_modulo.id_module_group , %s %s", - $id_agente, $status_text_monitor_sql, $status_filter_sql, $tags_sql, AGENT_MODULE_STATUS_NO_DATA, $order['field'], $order['order']); + $id_agente, $status_text_monitor_sql,$status_module_group_filter,$status_filter_sql, $tags_sql, AGENT_MODULE_STATUS_NO_DATA, + $status_module_group_filter, $order['field'], $order['order']); + break; case "postgresql": $sql = sprintf(" @@ -582,14 +598,16 @@ if ($list_modules) { (SELECT * FROM tagente_modulo WHERE id_agente = %d AND nombre LIKE '%s' AND delete_pending = 0 - AND disabled = 0) tagente_modulo + AND disabled = 0 AND %s) tagente_modulo LEFT JOIN tmodule_group ON tagente_modulo.id_module_group = tmodule_group.id_mg WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND %s %s AND tagente_estado.estado != %d + AND tagente_modulo.%s ORDER BY tagente_modulo.id_module_group , %s %s", - $id_agente, $status_text_monitor_sql, $status_filter_sql, $tags_sql, AGENT_MODULE_STATUS_NO_DATA, $order['field'], $order['order']); + $id_agente, $status_text_monitor_sql,$status_module_group_filter,$status_filter_sql, $tags_sql, AGENT_MODULE_STATUS_NO_DATA, + $status_module_group_filter, $order['field'], $order['order']); break; // If Dbms is Oracle then field_list in sql statement has to be recoded. See oracle_list_all_field_table() case "oracle": @@ -598,7 +616,7 @@ if ($list_modules) { $fields_tmodule_group = oracle_list_all_field_table('tmodule_group', 'string'); $sql = sprintf (" - SELECT " . $fields_tagente_estado . ', ' . $fields_tagente_modulo . ', ' . $fields_tmodule_group . + SELECT " . $fields_tagente_estado . ', ' . $fields_tagente_modulo . ', ' . $fields_tmodule_group . " FROM tagente_estado, tagente_modulo LEFT JOIN tmodule_group ON tmodule_group.id_mg = tagente_modulo.id_module_group @@ -609,8 +627,10 @@ if ($list_modules) { AND tagente_modulo.delete_pending = 0 AND tagente_modulo.disabled = 0 AND tagente_estado.estado != %d + AND tagente_modulo.%s ORDER BY tagente_modulo.id_module_group , %s %s - ", $id_agente, $status_text_monitor_sql, $tags_sql, $status_filter_sql, AGENT_MODULE_STATUS_NO_DATA, $order['field'], $order['order']); + ", $id_agente, $status_text_monitor_sql, $tags_sql, $status_filter_sql, AGENT_MODULE_STATUS_NO_DATA, + $status_module_group_filter, $order['field'], $order['order']); break; } @@ -649,23 +669,24 @@ if ($list_modules) { } $table->head[2] = __('Type') . ' ' . - '' . html_print_image("images/sort_up.png", true, array("style" => $selectTypeUp, "alt" => "up")) . '' . - '' . html_print_image("images/sort_down.png", true, array("style" => $selectTypeDown, "alt" => "down")) . ''; + '' . html_print_image("images/sort_up.png", true, array("style" => $selectTypeUp, "alt" => "up")) . '' . + '' . html_print_image("images/sort_down.png", true, array("style" => $selectTypeDown, "alt" => "down")) . ''; $table->head[3] = __('Module name') . ' ' . - '' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp, "alt" => "up")) . '' . - '' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown, "alt" => "down")) . ''; + '' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp, "alt" => "up")) . '' . + '' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown, "alt" => "down")) . ''; $table->head[4] = __('Description'); $table->head[5] = __('Status') . ' ' . - '' . html_print_image("images/sort_up.png", true, array("style" => $selectStatusUp, "alt" => "up")) . '' . - '' . html_print_image("images/sort_down.png", true, array("style" => $selectStatusDown, "alt" => "down")) . ''; + '' . html_print_image("images/sort_up.png", true, array("style" => $selectStatusUp, "alt" => "up")) . '' . + '' . html_print_image("images/sort_down.png", true, array("style" => $selectStatusDown, "alt" => "down")) . ''; $table->head[6] = __('Warn'); $table->head[7] = __('Data') . ' ' . - '' . html_print_image("images/sort_up.png", true, array("style" => $selectDataUp, "alt" => "up")) . '' . - '' . html_print_image("images/sort_down.png", true, array("style" => $selectDataDown, "alt" => "down")) . ''; + '' . html_print_image("images/sort_up.png", true, array("style" => $selectDataUp, "alt" => "up")) . '' . + '' . html_print_image("images/sort_down.png", true, array("style" => $selectDataDown, "alt" => "down")) . ''; $table->head[8] = __('Graph'); $table->head[9] = __('Last contact') . ' ' . - '' . html_print_image("images/sort_up.png", true, array("style" => $selectLastContactUp, "alt" => "up")) . '' . - '' . html_print_image("images/sort_down.png", true, array("style" => $selectLastContactDown, "alt" => "down")) . ''; + '' . html_print_image("images/sort_up.png", true, array("style" => $selectLastContactUp, "alt" => "up")) . '' . + '' . html_print_image("images/sort_down.png", true, array("style" => $selectLastContactDown, "alt" => "down")) . ''; + $table->align = array("left", "left", "center", "left", "left", "center"); @@ -1011,7 +1032,8 @@ if ($list_modules) { "id_agente=" . $id_agente . "&" . "refr=&filter_monitors=1&" . "status_filter_monitor=" . $status_filter_monitor . "&" . - "status_text_monitor=" . $status_text_monitor; + "status_text_monitor=" . $status_text_monitor . "&". + "status_module_group=" . $status_module_group; if ($paginate_module) { ui_pagination ($count_modules, false, 0, 0, false, 'offset', @@ -1036,4 +1058,4 @@ if ($list_modules) { } -?> \ No newline at end of file +?> diff --git a/pandora_console/operation/agentes/estado_monitores.php b/pandora_console/operation/agentes/estado_monitores.php index 0af43e572d..46de9cd49d 100755 --- a/pandora_console/operation/agentes/estado_monitores.php +++ b/pandora_console/operation/agentes/estado_monitores.php @@ -193,6 +193,7 @@ ui_toggle($html_toggle, parameters["sort"] = sort_rows; parameters["status_filter_monitor"] = filter_status; parameters["status_text_monitor"] = filter_text; + parameters["status_module_group"] = filter_group; parameters["page"] = "include/ajax/module"; @@ -218,6 +219,7 @@ ui_toggle($html_toggle, function filter_modules() { filter_status = $("#status_filter_monitor").val(); + filter_group = $("#status_module_group").val(); filter_text = $("input[name='status_text_monitor']").val(); var parameters = {}; @@ -228,6 +230,7 @@ ui_toggle($html_toggle, parameters["sort"] = sort_rows; parameters["status_filter_monitor"] = filter_status; parameters["status_text_monitor"] = filter_text; + parameters["status_module_group"] = filter_group; parameters["filter_monitors"] = 1; parameters["monitors_change_filter"] = 1; parameters["page"] = "include/ajax/module"; @@ -255,6 +258,7 @@ ui_toggle($html_toggle, function reset_filter_modules() { $("#status_filter_monitor").val(-1); + $("#status_module_group").val(-1); $("input[name='status_text_monitor']").val(""); filter_modules(); @@ -270,6 +274,7 @@ ui_toggle($html_toggle, parameters["sort"] = sort_rows; parameters["status_filter_monitor"] = filter_status; parameters["status_text_monitor"] = filter_text; + parameters["status_module_group"] = filter_group; parameters["filter_monitors"] = 0; parameters["monitors_change_filter"] = 0; parameters["page"] = "include/ajax/module"; @@ -408,7 +413,7 @@ ui_require_jquery_file("ui.datepicker-" . get_user_language(), "include/javascri data[0][2] = __('Free text for search (*):'); $table->data[0][3] = html_print_input_text('status_text_monitor', $status_text_monitor, '', 30, 100, true); - - $table->data[0][4] = html_print_button(__('Filter'), 'filter', false, 'filter_modules();', 'class="sub search"', true); - $table->data[0][4] .= ' ' . html_print_button(__('Reset'), 'filter', false, 'reset_filter_modules();', 'class="sub upd"', true); + $table->data[0][4] = __('Module group'); + $rows = db_get_all_rows_sql("SELECT * + FROM tmodule_group ORDER BY name"); + $rows = io_safe_output($rows); + $rows_select = array(); + if (!empty($rows)){ + $rows_select[-1] = __('All'); + foreach ($rows as $module_group) + $rows_select[$module_group['id_mg']] = __($module_group['name']); + } + $table->data[0][5] = html_print_select ($rows_select,'status_module_group', $status_module_group, '', '',0, true); + $table->data[0][6] = html_print_button(__('Filter'), 'filter', false, 'filter_modules();', 'class="sub search"', true); + $table->data[0][7] .= ' ' . html_print_button(__('Reset'), 'filter', false, 'reset_filter_modules();', 'class="sub upd"', true); $form_text .= html_print_table($table, true); $filter_hidden = false; - if ($status_filter_monitor == -1 && $status_text_monitor == '') { + if ($status_filter_monitor == -1 && $status_text_monitor == '' && $status_module_group == -1 ) { $filter_hidden = true; }