diff --git a/pandora_console/extensions/agents_alerts.php b/pandora_console/extensions/agents_alerts.php index 4fd7be94ae..01d1e7222d 100755 --- a/pandora_console/extensions/agents_alerts.php +++ b/pandora_console/extensions/agents_alerts.php @@ -1,44 +1,80 @@ $pageName.$e->getMessage() ]); + exit; + } else { + echo $pageName.$e->getMessage(); + } + + // Stop this execution, but continue 'globally'. + return; +} + +// AJAX controller. +if (is_ajax()) { + $method = get_parameter('method'); + + if (method_exists($obj, $method) === true) { + $obj->{$method}(); + } else { + $obj->error('Method not found. ['.$method.']'); + } + + // Stop any execution. + exit; +} else { + // Run. + $obj->run(); +} function mainAgentsAlerts() { - global $config; - - // Load global vars - include_once 'include/config.php'; - include_once 'include/functions_reporting.php'; - - check_login(); - // ACL Check - if (! check_acl($config['id_user'], 0, 'AR')) { - db_pandora_audit( - 'ACL Violation', - 'Trying to access Agent view (Grouped)' - ); - include 'general/noaccess.php'; - exit; - } - - // Update network modules for this group - // Check for Network FLAG change request - // Made it a subquery, much faster on both the database and server side - if (isset($_GET['update_netgroup'])) { + /* + // Update network modules for this group + // Check for Network FLAG change request + // Made it a subquery, much faster on both the database and server side + if (isset($_GET['update_netgroup'])) { $group = get_parameter_get('update_netgroup', 0); if (check_acl($config['id_user'], $group, 'AW')) { $where = ['id_agente' => 'ANY(SELECT id_agente FROM tagente WHERE id_grupo = '.$group]; @@ -49,19 +85,19 @@ function mainAgentsAlerts() include 'general/noaccess.php'; exit; } - } + } - if ($config['realtimestats'] == 0) { + if ($config['realtimestats'] == 0) { $updated_info = __('Last update').' : '.ui_print_timestamp(db_get_sql('SELECT min(utimestamp) FROM tgroup_stat'), true); - } else { + } else { // $updated_info = __("Updated at realtime"); $updated_info = ''; - } + } - $updated_time = $updated_info; - $create_alert = (int) get_parameter('create_alert', 0); + $updated_time = $updated_info; + $create_alert = (int) get_parameter('create_alert', 0); - if ($create_alert) { + if ($create_alert) { $template2 = get_parameter('template'); $module_action_threshold = get_parameter('module_action_threshold'); @@ -79,29 +115,29 @@ function mainAgentsAlerts() alerts_add_alert_agent_module_action($id_alert, $action_select, $values); } } - } + } - $refr = (int) get_parameter('refr', 30); - // By default 30 seconds - $show_modules = (bool) get_parameter('show_modules', 0); - $group_id = get_parameter('group_id', 0); - $offset = get_parameter('offset', 0); - $hor_offset = get_parameter('hor_offset', 0); - $block = 20; + $refr = (int) get_parameter('refr', 30); + // By default 30 seconds + $show_modules = (bool) get_parameter('show_modules', 0); + $group_id = get_parameter('group_id', 0); + $offset = get_parameter('offset', 0); + $hor_offset = get_parameter('hor_offset', 0); + $block = 20; - $groups = users_get_groups(); + $groups = users_get_groups(); - $filter_groups .= ''.__('Group').''; - $filter_groups .= '
'; - $filter_groups .= html_print_select_groups(false, 'AR', true, 'group_id', $group_id, false, '', '', true, false, true, '', false, 'margin-right: 10px; margin-top: 5px;'); - $filter_groups .= '
'; + $filter_groups .= ''.__('Group').''; + $filter_groups .= '
'; + $filter_groups .= html_print_select_groups(false, 'AR', true, 'group_id', $group_id, false, '', '', true, false, true, '', false, 'margin-right: 10px; margin-top: 5px;'); + $filter_groups .= '
'; - $check = ''.__('Show modules without alerts').''; - $check .= html_print_checkbox('slides_ids[]', $d['id'], $show_modules, true, false, '', true); + $check = ''.__('Show modules without alerts').''; + $check .= html_print_checkbox('slides_ids[]', $d['id'], $show_modules, true, false, '', true); - $comborefr = '
'; - $comborefr .= ''.__('Refresh').''; - $comborefr .= html_print_select( + $comborefr = ''; + $comborefr .= ''.__('Refresh').''; + $comborefr .= html_print_select( [ '30' => '30 '.__('seconds'), (string) SECONDS_1MINUTE => __('1 minute'), @@ -120,51 +156,51 @@ function mainAgentsAlerts() '', false, 'width: 100px; margin-right: 10px; margin-top: 5px;' - ); - $comborefr .= '
'; + ); + $comborefr .= ''; - if ($config['pure'] == 0) { + if ($config['pure'] == 0) { $fullscreen['text'] = ''.html_print_image('images/full_screen.png', true, ['title' => __('Full screen mode')]).''; - } else { + } else { $fullscreen['text'] = ''.html_print_image('images/normal_screen.png', true, ['title' => __('Back to normal mode')]).''; $config['refr'] = $refr; - } + } - $onheader = [ + $onheader = [ 'updated_time' => $updated_time, 'fullscreen' => $fullscreen, 'combo_groups' => $filter_groups, - ]; + ]; - if ($config['pure'] == 1) { + if ($config['pure'] == 1) { $onheader['combo_refr'] = $comborefr; - } + } - // Header. - ui_print_page_header( + // Header. + ui_print_page_header( __('Agents/Alerts'), 'images/op_alerts.png', false, '', false, $updated_time - ); - - // Old style table, we need a lot of special formatting,don't use table function - // Prepare old-style table - echo ''; - echo ''; - echo ''; - echo ''; - if ($config['pure'] == 1) { + );*/ + /* + // Old style table, we need a lot of special formatting,don't use table function + // Prepare old-style table + echo '
'.$filter_groups.''.$check.'
'; + echo ''; + echo ''; + echo ''; + if ($config['pure'] == 1) { echo ''; - } + } - echo ''; - echo ''; - echo '
'.$filter_groups.''.$check.''.$comborefr.' '.__('Full screen').''.$fullscreen['text'].'
'; + echo ' '.__('Full screen').''.$fullscreen['text'].''; + echo ''; + echo ''; - if ($show_modules) { + if ($show_modules) { if ($group_id > 0) { $grupo = " AND tagente.id_grupo = $group_id"; } else { @@ -172,17 +208,17 @@ function mainAgentsAlerts() } $offset_modules = get_parameter('offset', 0); - $sql_count = "SELECT COUNT(tagente_modulo.nombre) FROM tagente_modulo - INNER JOIN tagente ON tagente.id_agente = tagente_modulo.id_agente - WHERE id_agente_modulo NOT IN (SELECT id_agent_module FROM talert_template_modules) - $grupo"; + $sql_count = "SELECT COUNT(tagente_modulo.nombre) FROM tagente_modulo + INNER JOIN tagente ON tagente.id_agente = tagente_modulo.id_agente + WHERE id_agente_modulo NOT IN (SELECT id_agent_module FROM talert_template_modules) + $grupo"; $count_agent_module = db_get_all_rows_sql($sql_count); - $sql = "SELECT tagente.alias, tagente_modulo.nombre, - tagente_modulo.id_agente_modulo FROM tagente_modulo - INNER JOIN tagente ON tagente.id_agente = tagente_modulo.id_agente - WHERE id_agente_modulo NOT IN (SELECT id_agent_module FROM talert_template_modules) - $grupo LIMIT 20 OFFSET $offset_modules"; + $sql = "SELECT tagente.alias, tagente_modulo.nombre, + tagente_modulo.id_agente_modulo FROM tagente_modulo + INNER JOIN tagente ON tagente.id_agente = tagente_modulo.id_agente + WHERE id_agente_modulo NOT IN (SELECT id_agent_module FROM talert_template_modules) + $grupo LIMIT 20 OFFSET $offset_modules"; $agent_modules = db_get_all_rows_sql($sql); ui_pagination( @@ -315,7 +351,7 @@ function mainAgentsAlerts() } html_print_table($table); - } else { + } else { $filter = [ 'offset' => (int) $offset, 'limit' => (int) $config['block_size'], @@ -329,10 +365,10 @@ function mainAgentsAlerts() // Get the id of all agents with alerts $sql = 'SELECT DISTINCT(id_agente) - FROM tagente_modulo - WHERE id_agente_modulo IN - (SELECT id_agent_module - FROM talert_template_modules)'; + FROM tagente_modulo + WHERE id_agente_modulo IN + (SELECT id_agent_module + FROM talert_template_modules)'; $agents_with_alerts_raw = db_get_all_rows_sql($sql); if ($agents_with_alerts_raw === false) { @@ -369,12 +405,12 @@ function mainAgentsAlerts() $agent_alerts[$alert['agent_name']][$alert['id_alert_template']][] = $alert; } - // Prepare pagination + // Prepare pagination. ui_pagination( $nagents, false, 0, - 0, + 3, false, 'offset', true, @@ -391,18 +427,12 @@ function mainAgentsAlerts() echo ''; echo "".__('Agents').' / '.__('Alert templates').''; - if ($hor_offset > 0) { - $new_hor_offset = ($hor_offset - $block); - echo " - ".html_print_image('images/darrowleft.png', true, ['title' => __('Previous templates')]).' '; - } - $templates_raw = []; if (!empty($templates)) { $sql = sprintf( 'SELECT id, name - FROM talert_templates - WHERE id IN (%s)', + FROM talert_templates + WHERE id IN (%s)', implode(',', array_keys($templates)) ); @@ -435,19 +465,14 @@ function mainAgentsAlerts() } echo ''; - if (($hor_offset + $block) < $ntemplates) { - $new_hor_offset = ($hor_offset + $block); - echo " - ".html_print_image('images/darrowright.png', true, ['title' => __('More templates')]).' '; - } foreach ($agents as $agent) { $alias = db_get_row('tagente', 'id_agente', $agent['id_agente']); echo ''; - // Name of the agent + // Name of the agent. echo ''.$alias['alias'].''; - // Alerts of the agent + // Alerts of the agent. $anyfired = false; foreach ($templates as $tid => $tname) { if ($tname == '') { @@ -488,6 +513,23 @@ function mainAgentsAlerts() echo ''; } + echo ''; + + if ($hor_offset > 0) { + $new_hor_offset = ($hor_offset - $block); + echo " + ".html_print_image('images/darrowleft.png', true, ['style' => 'float: right;', 'title' => __('Previous templates')]).' '; + } + + if (($hor_offset + $block) < $ntemplates) { + $new_hor_offset = ($hor_offset + $block); + echo ""; + echo "".html_print_image('images/darrowright.png', true, ['style' => 'float: right;', 'title' => __('More templates')]).""; + echo ''; + } + + echo ''; + echo ''; ui_pagination( @@ -506,146 +548,6 @@ function mainAgentsAlerts() ], 'alerts_agents' ); - } - -} - - -// Print the modal window for the summary of each alerts group -function print_alerts_summary_modal_window($id, $alerts) -{ - $table->width = '98%'; - $table->class = 'info_table'; - $table->data = []; - - $table->head[0] = __('Module'); - $table->head[1] = __('Action'); - $table->head[2] = __('Last fired'); - $table->head[3] = __('Status'); - - foreach ($alerts as $alert) { - $data[0] = modules_get_agentmodule_name($alert['id_agent_module']); - - $actions = alerts_get_alert_agent_module_actions($alert['id']); - - $actionDefault = db_get_value_sql( - ' - SELECT id_alert_action - FROM talert_templates - WHERE id = '.$alert['id_alert_template'] - ); - - $actionText = ''; - - if (!empty($actions)) { - $actionText = '
'; - } else { - if (!empty($actionDefault)) { - $actionText = db_get_sql( - "SELECT name - FROM talert_actions - WHERE id = $actionDefault" - ).' ('.__('Default').')'; - } } - - $data[1] = $actionText; - $data[2] = ui_print_timestamp($alert['last_fired'], true); - - $status = STATUS_ALERT_NOT_FIRED; - - if ($alert['times_fired'] > 0) { - $status = STATUS_ALERT_FIRED; - $title = __('Alert fired').' '.$alert['internal_counter'].' '.__('time(s)'); - } else if ($alert['disabled'] > 0) { - $status = STATUS_ALERT_DISABLED; - $title = __('Alert disabled'); - } else { - $status = STATUS_ALERT_NOT_FIRED; - $title = __('Alert not fired'); - } - - $data[3] = ui_print_status_image($status, $title, true); - - array_push($table->data, $data); - } - - $content = html_print_table($table, true); - - $agent = modules_get_agentmodule_agent_alias($alerts[0]['id_agent_module']); - $template = alerts_get_alert_template_name($alerts[0]['id_alert_template']); - - echo ''; + */ } - - -extensions_add_operation_menu_option(__('Agents/Alerts view'), 'estado', null, 'v1r1', 'view'); -extensions_add_main_function('mainAgentsAlerts'); - -ui_require_jquery_file('pandora'); - -?> - - diff --git a/pandora_console/extensions/agents_modules.php b/pandora_console/extensions/agents_modules.php index 8aa032c9a8..5f9a984048 100644 --- a/pandora_console/extensions/agents_modules.php +++ b/pandora_console/extensions/agents_modules.php @@ -26,17 +26,6 @@ function agents_modules_load_js() $ignored_params['refresh'] = ''; ?> - - + +