From 8e78110d5d717b317deb8faf0a8279ddfcdd8a04 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Mon, 30 May 2022 17:47:28 +0200 Subject: [PATCH] events sound pandora_enterprise#7960 --- pandora_console/include/ajax/events.php | 179 +++----- pandora_console/include/functions_events.php | 4 +- pandora_console/include/javascript/pandora.js | 54 +++ pandora_console/include/styles/pandora.css | 2 +- .../operation/events/sound_events.php | 409 +++++++++--------- 5 files changed, 339 insertions(+), 309 deletions(-) diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index b8e23d235e..0873923f2c 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -2038,121 +2038,78 @@ if ($get_table_response_command) { if ($get_events_fired) { global $config; - $id = get_parameter('id_row'); - $idGroup = get_parameter('id_group'); - $agents = get_parameter('agents', null); + $filter_id = (int) get_parameter('filter_id', 0); + $interval = (int) get_parameter('interval', 10); - $query = ' AND id_evento > '.$id; - - $type = []; - $alert = get_parameter('alert_fired'); - if ($alert == 'true') { - $resultAlert = alerts_get_event_status_group( - $idGroup, - [ - 'alert_fired', - 'alert_ceased', - ], - $query, - $agents - ); - } - - $critical = get_parameter('critical'); - if ($critical == 'true') { - $resultCritical = alerts_get_event_status_group( - $idGroup, - [ - 'going_up_critical', - 'going_down_critical', - ], - $query, - $agents - ); - } - - $warning = get_parameter('warning'); - if ($warning == 'true') { - $resultWarning = alerts_get_event_status_group( - $idGroup, - [ - 'going_up_warning', - 'going_down_warning', - ], - $query, - $agents - ); - } - - $unknown = get_parameter('unknown'); - if ($unknown == 'true') { - $resultUnknown = alerts_get_event_status_group( - $idGroup, - 'going_unknown', - $query, - $agents - ); - } - - if ($resultAlert) { - $return = [ - 'fired' => $resultAlert, - 'sound' => $config['sound_alert'], + if (empty($filter_id) === true) { + $filter = [ + 'id_group' => 0, + 'event_type' => '', + 'severity' => -1, + 'status' => -1, + 'search' => '', + 'text_agent' => '', + 'id_agent' => 0, + 'id_agent_module' => 0, + 'pagination' => 0, + 'id_user_ack' => 0, + 'group_rep' => 0, + 'tag_with' => [], + 'tag_without' => [], + 'filter_only_alert' => -1, + 'source' => '', + 'id_extra' => '', + 'user_comment' => '', + 'id_source_event' => 0, + 'server_id' => 0, + 'custom_data' => '', + 'custom_data_filter_type' => 0, ]; - $event = events_get_event($resultAlert); - - $module_name = modules_get_agentmodule_name($event['id_agentmodule']); - $agent_name = agents_get_alias($event['id_agente']); - - $return['message'] = io_safe_output($agent_name).' - '; - $return['message'] .= __('Alert fired in module '); - $return['message'] .= io_safe_output($module_name).' - '; - $return['message'] .= $event['timestamp']; - } else if ($resultCritical) { - $return = [ - 'fired' => $resultCritical, - 'sound' => $config['sound_critical'], - ]; - $event = events_get_event($resultCritical); - - $module_name = modules_get_agentmodule_name($event['id_agentmodule']); - $agent_name = agents_get_alias($event['id_agente']); - - $return['message'] = io_safe_output($agent_name).' - '; - $return['message'] .= __('Module ').io_safe_output($module_name); - $return['message'] .= __(' is going to critical').' - '; - $return['message'] .= $event['timestamp']; - } else if ($resultWarning) { - $return = [ - 'fired' => $resultWarning, - 'sound' => $config['sound_warning'], - ]; - $event = events_get_event($resultWarning); - - $module_name = modules_get_agentmodule_name($event['id_agentmodule']); - $agent_name = agents_get_alias($event['id_agente']); - - $return['message'] = io_safe_output($agent_name).' - '; - $return['message'] .= __('Module ').io_safe_output($module_name); - $return['message'] .= __(' is going to warning').' - '; - $return['message'] .= $event['timestamp']; - } else if ($resultUnknown) { - $return = [ - 'fired' => $resultUnknown, - 'sound' => $config['sound_alert'], - ]; - $event = events_get_event($resultUnknown); - - $module_name = modules_get_agentmodule_name($event['id_agentmodule']); - $agent_name = agents_get_alias($event['id_agente']); - - $return['message'] = io_safe_output($agent_name).' - '; - $return['message'] .= __('Module ').io_safe_output($module_name); - $return['message'] .= __(' is going to unknown').' - '; - $return['message'] .= $event['timestamp']; } else { - $return = ['fired' => 0]; + $filter = events_get_event_filter($filter_id); + } + + // Set time. + $filter['event_view_hr'] = 0; + + $start = (time() - $interval); + $end = time(); + + $filter['date_from'] = date('Y-m-d', $start); + $filter['date_to'] = date('Y-m-d', $end); + $filter['time_from'] = date('H:i:s', $start); + $filter['time_to'] = date('H:i:s', $end); + $data = events_get_all( + ['te.*'], + $filter + ); + + $return = []; + if (empty($data) === false) { + foreach ($data as $event) { + $return[] = [ + 'fired' => $event['id_evento'], + 'sound' => 'include/sounds/Star_Trek_emergency_simulation.wav', + 'message' => ui_print_string_substr( + strip_tags(io_safe_output($event['evento'])), + 75, + true, + '9' + ), + 'priority' => ui_print_event_priority($event['criticity'], true, true), + 'type' => events_print_type_img( + $event['event_type'], + true + ), + 'timestamp' => ui_print_timestamp( + $event['timestamp'], + true, + ['style' => 'font-size: 9pt; letter-spacing: 0.3pt;'] + ), + ]; + } } echo io_json_mb_encode($return); + return; } diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 934d7c27bc..6e07dda168 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -917,7 +917,7 @@ function events_get_all( } } - $groups = $filter['id_group_filter']; + $groups = (isset($filter['id_group_filter']) === true) ? $filter['id_group_filter'] : ''; if ((bool) $user_is_admin === false && isset($groups) === false ) { @@ -1280,7 +1280,7 @@ function events_get_all( // Id_user. $config['id_user'], // Id_group. - $ER_groups, + (isset($ER_groups) === true) ? $ER_groups : 0, // Access. 'ER', // Return_mode. diff --git a/pandora_console/include/javascript/pandora.js b/pandora_console/include/javascript/pandora.js index 740ff0f265..0cc66e150a 100644 --- a/pandora_console/include/javascript/pandora.js +++ b/pandora_console/include/javascript/pandora.js @@ -2027,3 +2027,57 @@ function inArray(needle, haystack) { } return false; } + +/* + * Creates a progressbar. + * @param id the id of the div we want to transform in a progressbar. + * @param duration the duration of the timer example: '10s'. + * @param iteration. + * @param callback, optional function which is called when the progressbar reaches 0. + */ +function createProgressTimeBar(id, duration, iteration, callback) { + // We select the div that we want to turn into a progressbar + var progressbar = document.getElementById(id); + progressbar.className = "progressbar"; + + // We create the div that changes width to show progress + var progressbarinner = document.createElement("div"); + progressbarinner.className = "inner"; + + // Now we set the animation parameters + progressbarinner.style.animationDuration = duration; + + progressbarinner.style.animationIterationCount = iteration; + + // Eventually couple a callback + if (typeof callback === "function") { + if (iteration === "infinite") { + progressbarinner.addEventListener("animationiteration", callback); + } else { + progressbarinner.addEventListener("animationend", callback); + } + } + + // Append the progressbar to the main progressbardiv + progressbar.appendChild(progressbarinner); + + // When everything is set up we start the animation + progressbarinner.style.animationPlayState = "running"; + + return progressbarinner; +} + +function progressTimeBar(id, interval, iteration, callback) { + var progress = createProgressTimeBar(id, interval + "s", iteration, callback); + + var controls = { + start: function() { + progress.style.animationPlayState = "running"; + }, + paused: function() { + progress.style.animationPlayState = "paused"; + } + }; + + return controls; +} diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index df286eaf49..aa6ed5bc62 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -6246,7 +6246,7 @@ div.graph div.legend table { .sound_events { background-color: #494949; - margin: 40px 2em 0; + margin: 1em 2em; min-height: auto; } diff --git a/pandora_console/operation/events/sound_events.php b/pandora_console/operation/events/sound_events.php index 0772577784..955b74604c 100644 --- a/pandora_console/operation/events/sound_events.php +++ b/pandora_console/operation/events/sound_events.php @@ -55,13 +55,14 @@ if (check_acl($config['id_user'], 0, 'ER') === false return; } -$agents = agents_get_group_agents(0, false, 'none', false, true); ob_start('ui_process_page_head'); ob_start(); echo ''; echo ''; echo ''.__('Sound Events').''; +ui_require_css_file('wizard'); +ui_require_css_file('discovery'); ?> '; @@ -98,106 +176,94 @@ ui_print_message_dialog( '/images/error_1.png' ); -$table = new StdClass; -$table->width = '100%'; -$table->class = 'w16px sound_div_background '; -$table->size[0] = '10%'; -$table->rowclass[0] = 'bold_top'; -$table->rowclass[1] = 'bold_top'; -$table->rowclass[2] = 'bold_top'; +$inputs = []; -$table->data[0][0] = __('Group'); -$table->data[0][1] = html_print_select_groups( - false, - $access, - true, - 'group', - '', - 'changeGroup();', - '', - 0, - true, - false, - true, - '', - false, - 'max-width:200px;' -).'

'; +// Load filter. +$fields = \events_get_event_filter_select(); +$inputs[] = [ + 'label' => \__('Load filter'), + 'class' => 'flex-row', + 'arguments' => [ + 'type' => 'select', + 'fields' => $fields, + 'name' => 'filter_id', + 'selected' => 0, + 'return' => true, + 'nothing' => \__('All new events'), + 'nothing_value' => 0, + 'class' => 'fullwidth', + ], +]; -$table->data[0][2] = __('Type'); -$table->data[0][3] = html_print_checkbox( - 'alert_fired', - 'alert_fired', - true, - true, - false, - 'changeType();' -); -$table->data[0][3] .= __('Alert fired').'
'; -$table->data[0][3] .= html_print_checkbox( - 'critical', - 'critical', - true, - true, - false, - 'changeType();' -); -$table->data[0][3] .= __('Monitor critical').'
'; -$table->data[0][3] .= html_print_checkbox( - 'unknown', - 'unknown', - true, - true, - false, - 'changeType();' -); -$table->data[0][3] .= __('Monitor unknown').'
'; -$table->data[0][3] .= html_print_checkbox( - 'warning', - 'warning', - true, - true, - false, - 'changeType();' -); -$table->data[0][3] .= __('Monitor warning').'
'; +$times_interval = [ + 10 => '10 '.__('seconds'), + 15 => '15 '.__('seconds'), + 30 => '30 '.__('seconds'), + 60 => '60 '.__('seconds'), +]; -$table->data[1][0] = __('Agent'); -$table->data[1][1] = html_print_select( - $agents, - 'id_agents[]', - true, +$times_sound = [ + 2 => '2 '.__('seconds'), + 5 => '5 '.__('seconds'), + 10 => '10 '.__('seconds'), + 15 => '15 '.__('seconds'), + 30 => '30 '.__('seconds'), + 60 => '60 '.__('seconds'), +]; + +$inputs[] = [ + 'class' => 'flex-row flex-row-center', + 'direct' => 1, + 'block_content' => [ + [ + 'label' => __('Interval'), + 'arguments' => [ + 'type' => 'select', + 'fields' => $times_interval, + 'name' => 'interval', + 'selected' => 10, + 'return' => true, + ], + ], + [ + 'label' => __('Time Sound'), + 'arguments' => [ + 'type' => 'select', + 'fields' => $times_sound, + 'name' => 'time_sound', + 'selected' => 10, + 'return' => true, + ], + ], + ], +]; + +// Print form. +HTML::printForm( + [ + 'form' => [ + 'action' => '', + 'method' => 'POST', + ], + 'inputs' => $inputs, + ], false, - '', - '', - true, - true, - '', - '', - '', - 'max-width:200px; height:100px', - '', - false, - '', - '', true ); -$table->data[1][2] = __('Event'); -$table->data[1][3] = html_print_textarea( - 'events_fired', - 200, - 20, - '', - 'readonly="readonly" style="max-height:100px; resize:none;"', - true -); +$result = '
'; -html_print_table($table); +$result .= '
'; + +echo $result; $table = new StdClass; $table->width = '100%'; -$table->class = 'w16px sound_div_background text_center'; +$table->class = 'sound_div_background text_center'; $table->data[0][0] = ''; $table->data[0][0] .= html_print_image( @@ -239,18 +305,11 @@ html_print_table($table); ?>