From 5b30aa556091f017a743e8b386c6f377a650a81a Mon Sep 17 00:00:00 2001 From: danielmaya Date: Fri, 31 Aug 2018 16:25:12 +0200 Subject: [PATCH] Added source, comment and id_extra in event filter --- pandora_console/extras/mr/20.sql | 10 +++- .../pandoradb_migrate_6.0_to_7.0.mysql.sql | 3 ++ .../godmode/events/event_edit_filter.php | 19 +++++++ pandora_console/include/functions_events.php | 26 +++++++++- .../operation/events/events.build_query.php | 12 +++++ pandora_console/operation/events/events.php | 3 ++ .../operation/events/events_list.php | 49 +++++++++++++++++-- pandora_console/pandoradb.sql | 3 ++ 8 files changed, 120 insertions(+), 5 deletions(-) diff --git a/pandora_console/extras/mr/20.sql b/pandora_console/extras/mr/20.sql index a78963b813..e99b2911d7 100644 --- a/pandora_console/extras/mr/20.sql +++ b/pandora_console/extras/mr/20.sql @@ -1 +1,9 @@ -ALTER TABLE treport_content ADD COLUMN `recursion` TINYINT(1) default NULL; \ No newline at end of file +START TRANSACTION; + +ALTER TABLE treport_content ADD COLUMN `recursion` TINYINT(1) default NULL; + +ALTER TABLE tevent_filter ADD COLUMN `user_comment` text NOT NULL; +ALTER TABLE tevent_filter ADD COLUMN `source` tinytext NOT NULL; +ALTER TABLE tevent_filter ADD COLUMN `id_extra` tinytext NOT NULL; + +COMMIT; \ No newline at end of file diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql index a472b8b6dd..7ee1968c4c 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql @@ -1213,6 +1213,9 @@ UPDATE `tlink` SET `link` = 'https://github.com/pandorafms/pandorafms/issues' WH -- --------------------------------------------------------------------- ALTER TABLE tevent_filter ADD COLUMN `date_from` date DEFAULT NULL; ALTER TABLE tevent_filter ADD COLUMN `date_to` date DEFAULT NULL; +ALTER TABLE tevent_filter ADD COLUMN `user_comment` text NOT NULL; +ALTER TABLE tevent_filter ADD COLUMN `source` tinytext NOT NULL; +ALTER TABLE tevent_filter ADD COLUMN `id_extra` tinytext NOT NULL; -- --------------------------------------------------------------------- -- Table `tusuario` -- --------------------------------------------------------------------- diff --git a/pandora_console/godmode/events/event_edit_filter.php b/pandora_console/godmode/events/event_edit_filter.php index 851e5b5e58..f83d19e14d 100644 --- a/pandora_console/godmode/events/event_edit_filter.php +++ b/pandora_console/godmode/events/event_edit_filter.php @@ -65,6 +65,9 @@ if ($id) { $group_rep = $filter['group_rep']; $date_from = str_replace("-","/",$filter['date_from']); $date_to = str_replace("-","/",$filter['date_to']); + $source = $filter['source']; + $id_extra = $filter['id_extra']; + $user_comment = $filter['user_comment']; $tag_with_json = $filter['tag_with']; $tag_with_json_clean = io_safe_output($tag_with_json); @@ -130,6 +133,9 @@ if ($update || $create) { $group_rep = get_parameter('group_rep', ''); $date_from = get_parameter('date_from', ''); $date_to = get_parameter('date_to', ''); + $source = get_parameter('source'); + $id_extra = get_parameter('id_extra'); + $user_comment = get_parameter('user_comment'); $tag_with_base64 = get_parameter('tag_with', json_encode(array())); $tag_with_json = io_safe_input(base64_decode($tag_with_base64)); @@ -158,6 +164,9 @@ if ($update || $create) { 'tag_without' => $tag_without_json, 'date_from' => $date_from, 'date_to' => $date_to, + 'source' => $source, + 'id_extra' => $id_extra, + 'user_comment' => $user_comment, 'filter_only_alert' => $filter_only_alert); } @@ -390,6 +399,16 @@ if (!is_metaconsole()) { $text_module, false, true, '', array(), true, $id_agent_module); } +$sources = events_get_all_source(); +$table ->data[22][0] = '' . __('Source') . ''; +$table ->data[22][1] = html_print_select ($sources, 'source', $source, '', '', '', true); + +$table ->data[23][0] = '' . __('Extra ID') . ''; +$table ->data[23][1] = html_print_input_text ('id_extra', $id_extra, '', 11, 255, true); + +$table ->data[24][0] = '' . __('Comment') . ''; +$table ->data[24][1] = html_print_input_text ('user_comment', $user_comment, '', 35, 255, true); + echo '
'; html_print_table ($table); diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 0d496bf9c4..f6b6da21cc 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -1529,7 +1529,31 @@ function events_get_all_status ($report = false) { } return $fields; -} +} + +/** + * Return all event source. + * + * @return array event source array. + */ +function events_get_all_source () { + $event_table = events_get_events_table(is_metaconsole(),false); + $fields = array (); + $fields[''] = __('All'); + + if (users_is_admin()) { + $sources = db_get_all_rows_sql("SELECT DISTINCT(source) FROM ". $event_table); + } else { + $groups_user = users_get_groups ($config['id_user'], "ER", true); + $sources = db_get_all_rows_sql("SELECT DISTINCT(source) FROM ". $event_table. " WHERE id_grupo IN (" .implode(",",array_keys($groups_user)) .")"); + } + + foreach ($sources as $key => $source) { + $fields[$source['source']] = $source['source']; + } + + return $fields; +} /** * Decode a numeric status into status description. diff --git a/pandora_console/operation/events/events.build_query.php b/pandora_console/operation/events/events.build_query.php index 7716257cc4..936d933143 100755 --- a/pandora_console/operation/events/events.build_query.php +++ b/pandora_console/operation/events/events.build_query.php @@ -149,6 +149,18 @@ if ($severity != -1) { } } +if ($id_extra != '') { + $sql_post .= " AND id_extra LIKE '%$id_extra%'"; +} + +if ($user_comment != '') { + $sql_post .= " AND user_comment LIKE '%$user_comment%'"; +} + +if ($source != '') { + $sql_post .= " AND source LIKE '$source'"; +} + // In metaconsole mode the agent search is performed by name if ($meta) { $text_agent = get_parameter("text_agent",""); diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index 03101d09b4..ad692695ae 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -261,6 +261,9 @@ $time_to = (string)get_parameter('time_to', ''); $server_id = (int)get_parameter('server_id', 0); $text_agent = (string) get_parameter("text_agent"); $refr = (int) get_parameter ('refresh'); +$id_extra = (string) get_parameter('id_extra'); +$user_comment = (string) get_parameter('user_comment'); +$source = (string) get_parameter('source'); if ($id_agent != 0) { $text_agent = agents_get_alias($id_agent); diff --git a/pandora_console/operation/events/events_list.php b/pandora_console/operation/events/events_list.php index ea78086c6b..2add378167 100644 --- a/pandora_console/operation/events/events_list.php +++ b/pandora_console/operation/events/events_list.php @@ -89,7 +89,10 @@ if (is_ajax()) { $values['id_group_filter'] = get_parameter('id_group_filter'); $values['date_from'] = get_parameter('date_from'); $values['date_to'] = get_parameter('date_to'); - + $values['source'] = get_parameter('source'); + $values['id_extra'] = get_parameter('id_extra'); + $values['user_comment'] = get_parameter('user_comment'); + $exists = (bool)db_get_value_filter( 'id_filter', 'tevent_filter', $values); @@ -129,6 +132,10 @@ if (is_ajax()) { $values['id_group_filter'] = get_parameter('id_group_filter'); $values['date_from'] = get_parameter('date_from'); $values['date_to'] = get_parameter('date_to'); + $values['source'] = get_parameter('source'); + $values['id_extra'] = get_parameter('id_extra'); + $values['user_comment'] = get_parameter('user_comment'); + if (io_safe_output($values['tag_with']) == "[\"0\"]") { $values['tag_with'] = "[]"; } @@ -189,6 +196,10 @@ if ($user_filter != 0 && empty($id_name) && !$update_from_filter_table) { $status = $user_default_filter['status']; $event_view_hr = $user_default_filter['event_view_hr']; $group_rep = $user_default_filter['group_rep']; + $id_extra = $user_default_filter['id_extra']; + $user_comment = $user_default_filter['user_comment']; + $source = $user_default_filter['source']; + if ($user_default_filter['search'] != "") { $search = $user_default_filter['search']; } @@ -654,6 +665,17 @@ $data[2] .= html_print_select ($repeated_sel, "group_rep", $group_rep, '', '', 0 $table->data[] = $data; $table->rowclass[] = ''; +$data = array(); +$sources = events_get_all_source(); +$data[0] = __('Source') . $jump; +$data[0] .= html_print_select ($sources, 'source', $source, '', '', '', true); +$data[1] = __('Extra ID') . $jump; +$data[1] .= html_print_input_text ('id_extra', $id_extra, '', 11, 255, true); +$data[2] = __("Comment") . $jump; +$data[2] .= html_print_input_text ('user_comment', $user_comment, '', 35, 255, true); +$table->data[] = $data; +$table->rowclass[] = ''; + $data = array(); $data[0] = ui_toggle(html_print_table($table_advanced, true), __('Advanced options'), '', true, true); @@ -952,6 +974,12 @@ $(document).ready( function() { $("#filter_only_alert").val(val); if (i == 'id_group_filter') $("#id_group_filter").val(val); + if (i == 'source') + $("#source").val(val); + if (i == 'id_extra') + $("#text-id_extra").val(val); + if (i == 'user_comment') + $("#text-user_comment").val(val); }); reorder_tags_inputs(); // Update the info with the loaded filter @@ -990,6 +1018,9 @@ $(document).ready( function() { $("#pagination").val(20); $("#update_from_filter_table").val(1); $("#text_id_agent").val(""); + $("#source").val(''); + $("#text-id_extra").val(''); + $("#text-user_comment").val(''); clear_tags_inputs(); @@ -1058,6 +1089,12 @@ $(document).ready( function() { $("#text-date_to").val(val.replace(/\-/g,"/")); } } + if (i == 'source') + $("#source").val(val); + if (i == 'id_extra') + $("#text-id_extra").val(val); + if (i == 'user_comment') + $("#text-user_comment").val(val); }); reorder_tags_inputs(); // Update the info with the loaded filter @@ -1123,7 +1160,10 @@ $(document).ready( function() { "filter_only_alert" : $("#filter_only_alert").val(), "id_group_filter": $("#id_group_filter").val(), "date_from": $("#text-date_from").val(), - "date_to": $("#text-date_to").val() + "date_to": $("#text-date_to").val(), + "source": $("#source").val(), + "id_extra": $("#text-id_extra").val(), + "user_comment": $("#text-user_comment").val() }, function (data) { $(".info_box").hide(); @@ -1220,7 +1260,10 @@ $(document).ready( function() { "filter_only_alert" : $("#filter_only_alert").val(), "id_group_filter": $("#id_group_filter").val(), "date_from": $("#text-date_from").val(), - "date_to": $("#text-date_to").val() + "date_to": $("#text-date_to").val(), + "source": $("#source").val(), + "id_extra": $("#text-id_extra").val(), + "user_comment": $("#text-user_comment").val() }, function (data) { $(".info_box").hide(); diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 3255136a7b..6fa0cc6e6e 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -1079,6 +1079,9 @@ CREATE TABLE IF NOT EXISTS `tevent_filter` ( `filter_only_alert` int(10) NOT NULL default -1, `date_from` date default NULL, `date_to` date default NULL, + `source` tinytext NOT NULL, + `id_extra` tinytext NOT NULL, + `user_comment` text NOT NULL, PRIMARY KEY (`id_filter`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;