From fdc13256cd776b52b3127496e7b00a5cfd4102ef Mon Sep 17 00:00:00 2001 From: Jonathan Date: Thu, 27 Apr 2023 16:05:37 +0200 Subject: [PATCH 1/8] #9478 create edit delete alerts from meta --- .../godmode/alerts/alert_list.builder.php | 38 ++- pandora_console/godmode/alerts/alert_list.php | 74 ++++++ .../include/ajax/alert_list.ajax.php | 31 ++- pandora_console/include/functions_ui.php | 68 +++++- .../operation/agentes/alerts_status.php | 225 +++++++++++------- .../operation/agentes/estado_agente.php | 18 ++ .../operation/agentes/ver_agente.php | 5 + 7 files changed, 362 insertions(+), 97 deletions(-) diff --git a/pandora_console/godmode/alerts/alert_list.builder.php b/pandora_console/godmode/alerts/alert_list.builder.php index af380c396c..9e42cd5a44 100644 --- a/pandora_console/godmode/alerts/alert_list.builder.php +++ b/pandora_console/godmode/alerts/alert_list.builder.php @@ -40,29 +40,47 @@ $table->size = []; $table->style[0] = 'width: 50%'; $table->style[1] = 'width: 50%'; -// Add an agent selector -if (! $id_agente) { +if (is_metaconsole() === true) { $params = []; $params['return'] = true; $params['show_helptip'] = true; $params['input_name'] = 'id_agent'; $params['selectbox_id'] = 'id_agent_module'; $params['javascript_is_function_select'] = true; - $params['metaconsole_enabled'] = false; + $params['metaconsole_enabled'] = true; $params['use_hidden_input_idagent'] = true; $params['print_hidden_input_idagent'] = true; + $params['javascript_page'] = 'enterprise/meta/include/ajax/events.ajax'; + $table->data[0][0] = html_print_label_input_block( __('Agent'), - ui_print_agent_autocomplete_input($params) + '
'.ui_print_agent_autocomplete_input($params).'
' ); +} else { + // Add an agent selector. + if (! $id_agente) { + $params = []; + $params['return'] = true; + $params['show_helptip'] = true; + $params['input_name'] = 'id_agent'; + $params['selectbox_id'] = 'id_agent_module'; + $params['javascript_is_function_select'] = true; + $params['metaconsole_enabled'] = false; + $params['use_hidden_input_idagent'] = true; + $params['print_hidden_input_idagent'] = true; + $table->data[0][0] = html_print_label_input_block( + __('Agent'), + ui_print_agent_autocomplete_input($params) + ); + } + + if ($id_agente) { + $modules = agents_get_modules($id_agente, false, ['delete_pending' => 0]); + } } $modules = []; -if ($id_agente) { - $modules = agents_get_modules($id_agente, false, ['delete_pending' => 0]); -} - $table->data[0][1] = html_print_label_input_block( __('Module'), html_print_select( @@ -319,7 +337,8 @@ $(document).ready (function () { jQuery.post ( + "ajax.php", {"page" : "operation/agentes/estado_agente", "get_agent_module_last_value" : 1, - "id_agent_module" : this.value + "id_agent_module" : this.value, + "server_name" : $('#text-id_agent').val(), }, function (data, status) { if (data === false) { @@ -338,5 +357,4 @@ $(document).ready (function () { ); }); }); -/* ]]> */ diff --git a/pandora_console/godmode/alerts/alert_list.php b/pandora_console/godmode/alerts/alert_list.php index ce42dd1675..9abe728e5e 100644 --- a/pandora_console/godmode/alerts/alert_list.php +++ b/pandora_console/godmode/alerts/alert_list.php @@ -99,6 +99,19 @@ if ($update_alert) { } if ($create_alert) { + if (is_metaconsole()) { + if (enterprise_include_once('include/functions_metaconsole.php') !== ENTERPRISE_NOT_HOOK) { + $server_name = explode(' ', io_safe_output(get_parameter('id_agent')))[0]; + $connection = metaconsole_get_connection($server_name); + if (metaconsole_load_external_db($connection) !== NOERR) { + echo json_encode(false); + // Restore db connection. + metaconsole_restore_db(); + return; + } + } + } + $id_alert_template = (int) get_parameter('template'); $id_agent_module = (int) get_parameter('id_agent_module'); @@ -203,9 +216,28 @@ if ($create_alert) { } } } + + if (is_metaconsole()) { + // Restore db connection. + metaconsole_restore_db(); + echo ''; + } } if ($delete_alert) { + if (is_metaconsole()) { + if (enterprise_include_once('include/functions_metaconsole.php') !== ENTERPRISE_NOT_HOOK) { + $server_name = explode(' ', io_safe_output(get_parameter('id_agent')))[0]; + $connection = metaconsole_get_connection($server_name); + if (metaconsole_load_external_db($connection) !== NOERR) { + echo json_encode(false); + // Restore db connection. + metaconsole_restore_db(); + return; + } + } + } + $id_alert_agent_module = (int) get_parameter('id_alert'); $temp = db_get_row('talert_template_modules', 'id', $id_alert_agent_module); @@ -241,6 +273,11 @@ if ($delete_alert) { '', true ); + if (is_metaconsole()) { + // Restore db connection. + metaconsole_restore_db(); + echo ''; + } } if ($add_action) { @@ -283,6 +320,19 @@ if ($add_action) { } if ($update_action) { + if (is_metaconsole()) { + if (enterprise_include_once('include/functions_metaconsole.php') !== ENTERPRISE_NOT_HOOK) { + $server_name = explode(' ', io_safe_output(get_parameter('id_agent')))[0]; + $connection = metaconsole_get_connection($server_name); + if (metaconsole_load_external_db($connection) !== NOERR) { + echo json_encode(false); + // Restore db connection. + metaconsole_restore_db(); + return; + } + } + } + $alert_id = (int) get_parameter('alert_id'); $id_action = (int) get_parameter('action_select_ajax-'.$alert_id); $id_module_action = (int) get_parameter('id_module_action_ajax'); @@ -321,9 +371,28 @@ if ($update_action) { '', true ); + + if (is_metaconsole()) { + // Restore db connection. + metaconsole_restore_db(); + echo ''; + } } if ($delete_action) { + if (is_metaconsole()) { + if (enterprise_include_once('include/functions_metaconsole.php') !== ENTERPRISE_NOT_HOOK) { + $server_name = explode(' ', io_safe_output(get_parameter('id_agent')))[0]; + $connection = metaconsole_get_connection($server_name); + if (metaconsole_load_external_db($connection) !== NOERR) { + echo json_encode(false); + // Restore db connection. + metaconsole_restore_db(); + return; + } + } + } + $id_action = (int) get_parameter('id_action'); $id_alert = (int) get_parameter('id_alert'); @@ -348,6 +417,11 @@ if ($delete_action) { '', true ); + + if (is_metaconsole()) { + // Restore db connection. + metaconsole_restore_db(); + } } if ($enable_alert) { diff --git a/pandora_console/include/ajax/alert_list.ajax.php b/pandora_console/include/ajax/alert_list.ajax.php index 7d9e372d7e..3c66cf1df9 100644 --- a/pandora_console/include/ajax/alert_list.ajax.php +++ b/pandora_console/include/ajax/alert_list.ajax.php @@ -406,6 +406,19 @@ if ($get_actions_module) { } if ($show_update_action_menu) { + if (is_metaconsole()) { + if (enterprise_include_once('include/functions_metaconsole.php') !== ENTERPRISE_NOT_HOOK) { + $server_name = explode(' ', io_safe_output(get_parameter('id_agent')))[0]; + $connection = metaconsole_get_connection($server_name); + if (metaconsole_load_external_db($connection) !== NOERR) { + echo json_encode(false); + // Restore db connection. + metaconsole_restore_db(); + return; + } + } + } + if (! check_acl($config['id_user'], 0, 'LW')) { db_pandora_audit( AUDIT_LOG_ACL_VIOLATION, @@ -436,7 +449,12 @@ if ($show_update_action_menu) { $id_action ); - $data .= '
'; + if (is_metaconsole()) { + $data .= ''; + } else { + $data .= ''; + } + $data .= ''; $data .= html_print_input_hidden( 'update_action', @@ -453,6 +471,11 @@ if ($show_update_action_menu) { $id_action, true ); + $data .= html_print_input_hidden( + 'id_agent', + $server_name, + true + ); if (! $id_agente) { $data .= ''; $data .= ''; $data .= ''; + + if (isset($action_option['module_action_threshold']) === false) { + $action_option['module_action_threshold'] = '300'; + } + $data .= ''; $data .= ''; $data .= ''; diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index d98057b97c..eec1ba849e 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -1562,13 +1562,13 @@ function alerts_delete_alert_agent_module_action($id_alert_agent_module_action) * * @return mixed Actions associated or false if something goes wrong. */ -function alerts_get_alert_agent_module_actions($id_alert_agent_module, $fields=false, $server_id=-1) +function alerts_get_alert_agent_module_actions($id_alert_agent_module, $fields=false, $server_id=-1, $ignore_metaconsole=false) { if (empty($id_alert_agent_module)) { return false; } - if (defined('METACONSOLE')) { + if (defined('METACONSOLE') && $ignore_metaconsole === false) { $server = db_get_row('tmetaconsole_setup', 'id', $server_id); if (metaconsole_connect($server) == NOERR) { @@ -1602,6 +1602,7 @@ function alerts_get_alert_agent_module_actions($id_alert_agent_module, $fields=f $action['fires_min'] = $element['fires_min']; $action['fires_max'] = $element['fires_max']; $action['module_action_threshold'] = $element['module_action_threshold']; + $action['original_id'] = $element['id']; if (isset($element['id'])) { $retval[$element['id']] = $action; diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index d85b2c1054..1c0ea71889 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -1418,7 +1418,8 @@ function ui_format_alert_row( ); } - $data[$index['module_name']] = ui_print_truncate_text(isset($alert['agent_module_name']) ? $alert['agent_module_name'] : modules_get_agentmodule_name($alert['id_agent_module']), 'module_small', false, true, true, '[…]', ''); + $alert_module_name = isset($alert['agent_module_name']) ? $alert['agent_module_name'] : modules_get_agentmodule_name($alert['id_agent_module']); + $data[$index['module_name']] = ui_print_truncate_text($alert_module_name, 'module_small', false, true, true, '[…]', ''); } $data[$index['agent_name']] .= $disabledHtmlEnd; @@ -1432,7 +1433,24 @@ function ui_format_alert_row( $data[$index['description']] .= $disabledHtmlStart.ui_print_truncate_text(io_safe_output($description), 'description', false, true, true, '[…]', '').$disabledHtmlEnd; - $actions = alerts_get_alert_agent_module_actions($alert['id'], false, $alert['server_data']['id']); + if (is_metaconsole()) { + if (enterprise_include_once('include/functions_metaconsole.php') !== ENTERPRISE_NOT_HOOK) { + $connection = metaconsole_get_connection($agente['server_name']); + if (metaconsole_load_external_db($connection) !== NOERR) { + echo json_encode(false); + // Restore db connection. + metaconsole_restore_db(); + return; + } + } + } + + $actions = alerts_get_alert_agent_module_actions($alert['id'], false, -1, true); + + if (is_metaconsole()) { + // Restore db connection. + metaconsole_restore_db(); + } if (empty($actions) === false || $actionDefault != '') { $actionText = '
    '; @@ -1442,12 +1460,50 @@ function ui_format_alert_row( $actionText .= ' ('.$action['fires_min'].' / '.$action['fires_max'].')'; } + $actionText .= ui_print_help_tip(__('The default actions will be executed every time that the alert is fired and no other action is executed'), true); + // Is possible manage actions if have LW permissions in the agent group of the alert module. + if (check_acl($config['id_user'], $id_group, 'LW') || check_acl($config['id_user'], $id_group, 'LM')) { + $actionText .= ''; + $actionText .= html_print_input_image( + 'delete', + 'images/delete.svg', + 1, + 'padding:0px; margin-left:5px; margin-right:5px; width: 22px;', + true, + [ + 'title' => __('Delete action'), + 'class' => 'main_menu_icon invert_filter', + ] + ); + + $actionText .= html_print_input_hidden('id_agent', $agente['alias'], true); + $actionText .= html_print_input_hidden('delete_action', 1, true); + $actionText .= html_print_input_hidden('id_alert', $alert['id'], true); + $actionText .= html_print_input_hidden('id_action', $action['original_id'], true); + $actionText .= ''; + $actionText .= html_print_input_image( + 'update_action', + '/images/edit.svg', + 1, + 'padding:0px;', + true, + [ + 'title' => __('Update action'), + 'class' => 'main_menu_icon invert_filter', + 'onclick' => 'show_display_update_action(\''.$action['original_id'].'\',\''.$alert['id'].'\',\''.$alert['id_agent_module'].'\',\''.$action['original_id'].'\',\''.$alert['agent_name'].'\')', + ] + ); + $actionText .= html_print_input_hidden('id_agent_module', $alert['id_agent_module'], true); + } + + $actionText .= ''; $actionText .= '
'; } $actionText .= ''; - if ($actionDefault !== '') { + if ($actionDefault !== '' && $actionDefault !== false) { $actionDefault_name = db_get_sql( sprintf( 'SELECT name FROM talert_actions WHERE id = %d', @@ -1457,6 +1513,8 @@ function ui_format_alert_row( foreach ($actions as $action) { if ($actionDefault_name === $action['name']) { $hide_actionDefault = true; + } else { + $hide_actionDefault = false; } } @@ -1509,34 +1567,34 @@ function ui_format_alert_row( metaconsole_restore_db(); } + $tableActionButtons[] = ''; + // Edit. if (check_acl($config['id_user'], $id_group, 'LW') || check_acl($config['id_user'], $id_group, 'LM') ) { - $tableActionButtons[] = html_print_input_image( - 'update_action', - '/images/edit.svg', - 1, - 'padding:0px;', - true, - [ - 'title' => __('Update action'), - 'class' => 'main_menu_icon invert_filter', - 'onclick' => 'show_display_update_action(\''.$action['id'].'\',\''.$alert['id'].'\',\''.$alert['id_agent_module'].'\',\''.$action['id'].'\',\''.$alert['agent_name'].'\')', - ] - ); $tableActionButtons[] = html_print_input_hidden('id_agent_module', $alert['id_agent_module'], true); - } - if (check_acl($config['id_user'], $id_group, 'LM') - ) { - $tableActionButtons[] = ''.html_print_image( - 'images/delete.svg', + if (check_acl($config['id_user'], $id_group, 'LM') + ) { + $tableActionButtons[] = ''.html_print_image( + 'images/delete.svg', + true, + [ + 'alt' => __('Delete'), + 'title' => __('Delete'), + 'class' => 'main_menu_icon invert_filter vertical_baseline', + ] + ).''; + } + + $tableActionButtons[] = ''.html_print_image( + 'images/plus-black.svg', true, [ - 'alt' => __('Delete'), - 'title' => __('Delete'), - 'class' => 'main_menu_icon invert_filter vertical_baseline', + 'title' => __('Add action'), + 'class' => 'invert_filter main_menu_icon', + 'style' => 'margin-bottom: 12px;', ] ).''; } @@ -1550,6 +1608,123 @@ function ui_format_alert_row( ); } + // Is possible manage actions if have LW permissions in the agent group of the alert module. + if (check_acl_one_of_groups($config['id_user'], $all_groups, 'LW') || check_acl($config['id_user'], $template_group, 'LM')) { + if (check_acl($config['id_user'], $template_group, 'LW')) { + $own_groups = users_get_groups($config['id_user'], 'LW', true); + } else if (check_acl($config['id_user'], $template_group, 'LM')) { + $own_groups = users_get_groups($config['id_user'], 'LM', true); + } + + $filter_groups = ''; + $filter_groups = implode(',', array_keys($own_groups)); + if ($filter_groups != null) { + $actions = alerts_get_alert_actions_filter(true, 'id_group IN ('.$filter_groups.')'); + } + + $data[$index['actions']] .= '
'; @@ -571,6 +594,11 @@ if ($show_update_action_menu) { true ); $data .= ''; + if (is_metaconsole()) { + // Restore db connection. + metaconsole_restore_db(); + } + echo $data; return; } @@ -933,6 +961,7 @@ if ($get_agent_alerts_datatable === true) { $tmp->last_fired = $row[7]; $tmp->status = $row[8]; $tmp->validate = $row[9]; + $tmp->actions = $row[10]; } else { // Open. $tmp->standby = $row[0]; diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index 4dcf94edf1..62999b53b3 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -1139,6 +1139,7 @@ function ui_format_alert_row( 'last_fired' => 7, 'status' => 8, 'validate' => 9, + 'actions' => 10, ]; } else { $index = [ @@ -1458,6 +1459,69 @@ function ui_format_alert_row( } $data[$index['status']] = ui_print_status_image($status, $title, true); + $data[$index['status']] .= '
'; $data .= __('Threshold').ui_print_help_tip(__('If a value of 0 is assigned, the Threshold of the action will be used.'), true); @@ -591,7 +596,7 @@ if ($show_update_action_menu) { false, '', false, - true + false ); $data .= '
'; + $data[$index['actions']] .= html_print_input_hidden('add_action', 1, true); + $data[$index['actions']] .= html_print_input_hidden('id_agent', $agente['alias'], true); + $data[$index['actions']] .= html_print_input_hidden('id_alert_module', $alert['id'], true); + + if (! $id_agente) { + $data[$index['actions']] .= ''; + $data[$index['actions']] .= ''; + $data[$index['actions']] .= ''; + $data[$index['actions']] .= ''; + } + + $data[$index['actions']] .= ''; + $data[$index['actions']] .= ''; + + $data[$index['actions']] .= ''; + $data[$index['actions']] .= ''; + $data[$index['actions']] .= ''; + $data[$index['actions']] .= ''; + $data[$index['actions']] .= ''; + $data[$index['actions']] .= '
'.html_print_label_input_block( + __('Agent'), + ui_print_truncate_text($agente['alias'], 'agent_small', false, true, true, '[…]') + ).''.html_print_label_input_block( + __('Module'), + ui_print_truncate_text($alert_module_name, 'module_small', false, true, true, '[…]') + ).'
'.html_print_label_input_block( + __('Action'), + html_print_select( + $actions, + 'action_select', + '', + '', + __('None'), + 0, + true, + false, + true, + '', + false, + 'width:100%' + ) + ).''.html_print_label_input_block( + __('Number of alerts match from'), + '
'.html_print_input_text( + 'fires_min', + 0, + '', + 4, + 10, + true, + false, + false, + '', + 'w40p' + ).' '.__('to').' '.html_print_input_text( + 'fires_max', + 0, + '', + 4, + 10, + true, + false, + false, + '', + 'w40p' + ).'
' + ).'
'.html_print_label_input_block( + __('Threshold'), + html_print_extended_select_for_time( + 'module_action_threshold', + 0, + '', + '', + '', + false, + true, + false, + true, + '', + false, + false, + '', + false, + true + ) + ).'
'; + $data[$index['actions']] .= html_print_submit_button( + __('Add'), + 'addbutton', + false, + [ + 'icon' => 'next', + 'class' => 'mini float-right', + ], + true + ); + $data[$index['actions']] .= ''; + $data[$index['actions']] .= ''; + } + return $data; } diff --git a/pandora_console/operation/agentes/alerts_status.php b/pandora_console/operation/agentes/alerts_status.php index ffa860f634..f5a812e16d 100755 --- a/pandora_console/operation/agentes/alerts_status.php +++ b/pandora_console/operation/agentes/alerts_status.php @@ -656,4 +656,21 @@ function show_display_update_action(id_module_action, alert_id, alert_id_agent_m } }); } - + +function show_add_action(id_alert) { + $("#add_action-div-" + id_alert).hide () + .dialog ({ + resizable: true, + draggable: true, + modal: true, + width: 700, + title: '', + modal: true, + overlay: { + opacity: 0.5, + background: "black" + } + }) + .show (); +} + \ No newline at end of file From 8be0236af1636e9e27d79ca807bfe8baa749f03f Mon Sep 17 00:00:00 2001 From: Jonathan Date: Wed, 5 Jul 2023 11:14:09 +0200 Subject: [PATCH 7/8] #9478 permisions & confirm on delete alert action --- pandora_console/include/functions_ui.php | 45 +++++++++--------------- 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index 1c0ea71889..f50f2d56e4 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -1462,25 +1462,19 @@ function ui_format_alert_row( $actionText .= ui_print_help_tip(__('The default actions will be executed every time that the alert is fired and no other action is executed'), true); // Is possible manage actions if have LW permissions in the agent group of the alert module. - if (check_acl($config['id_user'], $id_group, 'LW') || check_acl($config['id_user'], $id_group, 'LM')) { - $actionText .= ''; + if (check_acl($config['id_user'], $id_group, 'LW')) { $actionText .= html_print_input_image( 'update_action', '/images/edit.svg', @@ -1570,23 +1564,18 @@ function ui_format_alert_row( $tableActionButtons[] = ''; // Edit. - if (check_acl($config['id_user'], $id_group, 'LW') - || check_acl($config['id_user'], $id_group, 'LM') - ) { + if (check_acl($config['id_user'], $id_group, 'LM')) { $tableActionButtons[] = html_print_input_hidden('id_agent_module', $alert['id_agent_module'], true); - if (check_acl($config['id_user'], $id_group, 'LM') - ) { - $tableActionButtons[] = ''.html_print_image( - 'images/delete.svg', - true, - [ - 'alt' => __('Delete'), - 'title' => __('Delete'), - 'class' => 'main_menu_icon invert_filter vertical_baseline', - ] - ).''; - } + $tableActionButtons[] = ''.html_print_image( + 'images/delete.svg', + true, + [ + 'alt' => __('Delete'), + 'title' => __('Delete'), + 'class' => 'main_menu_icon invert_filter vertical_baseline', + ] + ).''; $tableActionButtons[] = ''.html_print_image( 'images/plus-black.svg', From 47af436342660128282c66f18bae37abe0809199 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Wed, 5 Jul 2023 14:51:07 +0200 Subject: [PATCH 8/8] #11695 fix search alerts --- pandora_console/godmode/alerts/alert_actions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/godmode/alerts/alert_actions.php b/pandora_console/godmode/alerts/alert_actions.php index b972e1ff5a..97a492809e 100644 --- a/pandora_console/godmode/alerts/alert_actions.php +++ b/pandora_console/godmode/alerts/alert_actions.php @@ -333,7 +333,7 @@ $show_table_filter .= ui_toggle( __('Search'), 'search', true, - false, + true, '', 'white-box-content no_border', 'filter-datatable-main box-flat white_table_graph fixed_filter_bar '