Merge branch 'ent-7960-filtros-de-alertas-sonoras-sound-events-2' into 'develop'

events sound pandora_enterprise#7960

See merge request artica/pandorafms!4923
This commit is contained in:
daniel 2022-06-28 13:47:05 +00:00
commit 4ca27cd5a9
6 changed files with 378 additions and 315 deletions

View File

@ -2227,121 +2227,77 @@ if ($process_buffers === true) {
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'],
'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;
}

View File

@ -2028,6 +2028,60 @@ 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;
}
/**
* Filter selector item by text based on a text input.
*

View File

@ -6256,7 +6256,7 @@ div.graph div.legend table {
.sound_events {
background-color: #494949;
margin: 40px 2em 0;
margin: 1em 2em;
min-height: auto;
}

View File

@ -1475,12 +1475,20 @@ if ($pure) {
?>
<script type="text/javascript">
function openSoundEventWindow() {
url = "<?php echo ui_get_full_url('operation/events/sound_events.php'); ?>";
url = '<?php echo ui_get_full_url('operation/events/sound_events.php'); ?>';
// devicePixelRatio knows how much zoom browser applied.
var windowScale = parseFloat(window.devicePixelRatio);
var defaultWidth = 630;
var defaultHeight = 630;
// If the scale is 1, no zoom has been applied.
var windowWidth = windowScale <= 1 ? defaultWidth : windowScale*defaultWidth;
var windowHeight = windowScale <= 1 ? defaultHeight : windowScale*defaultHeight + (defaultHeight*0.1);
window.open(
url,
'<?php __('Sound Alerts'); ?>',
'width=600, height=450, toolbar=no, location=no, directories=no, status=no, menubar=no, resizable=no'
);
'width='+windowWidth+', height='+windowHeight+', resizable=yes, toolbar=no, location=no, directories=no, status=no, menubar=no'
);
}
</script>
<?php

View File

@ -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 '<html>';
echo '<head>';
echo '<title>'.__('Sound Events').'</title>';
ui_require_css_file('wizard');
ui_require_css_file('discovery');
?>
<style type='text/css'>
* {
@ -72,6 +73,83 @@ echo '<title>'.__('Sound Events').'</title>';
img {
border: 0;
}
ul.wizard li > label:not(.p-switch):first-of-type {
width: inherit;
}
form {
margin-top: -3px;
margin-bottom: 10px;
}
table {
margin-top: 5px;
}
.events_fired {
background: white;
padding: 20px;
overflow: auto;
height: 200px;
margin-bottom: 5px;
}
.events_fired li {
padding: 5px;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
}
.events_fired li div {
margin-right: 10px;
}
.events_fired li div.flex0 {
flex: 0;
}
.events_fired li div.flex-time {
flex: 0 1 100px;
text-align: end;
}
.events_fired li div.mess {
width: 100%;
}
.forced_title.mini-criticity {
width: 10px;
height: 30px;
}
.progressbar {
width: 100%;
margin: 5px 0px;
}
.progressbar .inner {
height: 10px;
animation: progressbar-countdown;
/* Placeholder, this will be updated using javascript */
animation-duration: 40s;
/* We stop in the end */
animation-iteration-count: 1;
/* Stay on pause when the animation is finished finished */
animation-fill-mode: forwards;
/* We start paused, we start the animation using javascript */
animation-play-state: paused;
/* We want a linear animation, ease-out is standard */
animation-timing-function: linear;
}
@keyframes progressbar-countdown {
0% {
width: 100%;
background: #82b92e;
}
100% {
width: 0%;
background: #e63c52;
}
}
</style>
<?php
echo '<link rel="icon" href="../../'.ui_get_favicon().'" type="image/ico" />';
@ -98,106 +176,121 @@ 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;'
).'<br /><br />';
// 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').'<br />';
$table->data[0][3] .= html_print_checkbox(
'critical',
'critical',
true,
true,
false,
'changeType();'
);
$table->data[0][3] .= __('Monitor critical').'<br />';
$table->data[0][3] .= html_print_checkbox(
'unknown',
'unknown',
true,
true,
false,
'changeType();'
);
$table->data[0][3] .= __('Monitor unknown').'<br />';
$table->data[0][3] .= html_print_checkbox(
'warning',
'warning',
true,
true,
false,
'changeType();'
);
$table->data[0][3] .= __('Monitor warning').'<br />';
$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,
],
],
],
];
$sounds = [
'aircraftalarm.wav' => 'Air craft alarm',
'air_shock_alarm.wav' => 'Air shock alarm',
'alien_alarm.wav' => 'Alien alarm',
'alien_beacon.wav' => 'Alien beacon',
'bell_school_ringing.wav' => 'Bell school ringing',
'Door_Alarm.wav' => 'Door alarm',
'EAS_beep.wav' => 'EAS beep',
'Firewarner.wav' => 'Fire warner',
'HardPCMAlarm.wav' => 'Hard PCM Alarm',
'negativebeep.wav' => 'Negative beep',
'Star_Trek_emergency_simulation.wav' => 'StarTrek emergency simulation',
];
$inputs[] = [
'label' => \__('Sounds'),
'class' => 'flex-row',
'arguments' => [
'type' => 'select',
'fields' => $sounds,
'name' => 'sound_id',
'selected' => 'Star_Trek_emergency_simulation.wav',
'return' => true,
'class' => 'fullwidth',
],
];
// 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 = '<div><ul class="events_fired">';
$result .= '<li class="events_fired_li_empty">';
$result .= ui_print_info_message(__('Events not found'), '', true);
$result .= '</li>';
$result .= '</ul></div>';
html_print_table($table);
$result .= '<div id="progressbar_time"></div>';
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] = '<a href="javascript: toggleButton();">';
$table->data[0][0] .= html_print_image(
@ -239,18 +332,11 @@ html_print_table($table);
?>
<script type="text/javascript">
var group = 0;
var alert_fired = true;
var critical = true;
var warning = true;
var unknown = true;
var control = false;
var running = false;
var id_row = 0;
var button_play_status = "play";
var test_sound = false;
function test_sound_button() {
@ -258,64 +344,18 @@ function test_sound_button() {
$("#button_try").attr('src', '../../images/icono_test.png');
$('body').append("<audio src='../../include/sounds/Star_Trek_emergency_simulation.wav' autoplay='true' hidden='true' loop='false'>");
test_sound = true;
}
else {
} else {
$("#button_try").attr('src', '../../images/icono_test.png');
$('body audio').remove();
test_sound = false;
}
}
function changeGroup() {
group = $("#group").val();
jQuery.post ("../../ajax.php",
{"page" : "include/ajax/agent",
"get_agents_group": 1,
"id_group": group
},
function (data) {
$("#id_agents").empty();
jQuery.each (data, function (id, value) {
if (value != "") {
$("#id_agents")
.append(
'<option value="' + id + '">' + value + '</option>'
);
}
});
},
"json"
);
}
function changeType() {
alert_fired = false;
critical = false;
warning = false;
unknown = false;
if($("input[name=alert_fired]").is(':checked') ) {
alert_fired = true;
}
if($("input[name=critical]").is(':checked') ) {
critical = true;
}
if($("input[name=warning]").is(':checked') ) {
warning = true;
}
if($("input[name=unknown]").is(':checked') ) {
unknown = true;
}
}
function toggleButton() {
if (button_play_status == 'pause') {
$("#button").attr('src', '../../images/play.button.png');
stopSound();
control.paused();
button_play_status = 'play';
}
@ -331,7 +371,7 @@ function toggleButton() {
function ok() {
$('#button_status').attr('src','../../images/tick_sound_events.png');
$('audio').remove();
$('#textarea_events_fired').val("");
$('.events_fired').empty();
}
function stopSound() {
@ -345,66 +385,77 @@ function startSound() {
}
function forgetPreviousEvents() {
var agents = $("#id_agents").val();
jQuery.post ("../../ajax.php",
{"page" : "include/ajax/events",
"get_events_fired": 1,
"id_group": group,
"alert_fired": alert_fired,
"critical": critical,
"warning": warning,
"unknown": unknown,
"id_row": id_row,
"agents[]" : agents
},
function (data) {
firedId = parseInt(data['fired']);
if (firedId != 0) {
id_row = firedId;
if(control === false) {
running = true;
control = progressTimeBar(
"progressbar_time",
$("#interval").val(),
'infinite',
function() {
check_event();
}
running = true;
},
"json"
);
);
} else {
control.start();
}
}
function check_event() {
var agents = $("#id_agents").val();
if (running) {
var sound = '../../include/sounds/' + $('#sound_id').val();
jQuery.post ("../../ajax.php",
{"page" : "include/ajax/events",
{
"page" : "include/ajax/events",
"get_events_fired": 1,
"id_group": group,
"alert_fired": alert_fired,
"critical": critical,
"warning": warning,
"unknown": unknown,
"id_row": id_row,
"agents[]" : agents,
"filter_id": $('#filter_id').val(),
"interval": $('#interval').val(),
"time_sound": $('#time_sound').val(),
},
function (data) {
firedId = parseInt(data['fired']);
if (firedId != 0) {
id_row = firedId;
var actual_text = $('#textarea_events_fired').val();
if (actual_text == "") {
$('#textarea_events_fired').val(data['message'] + "\n");
} else {
$('#textarea_events_fired')
.val(actual_text + "\n" + data['message'] + "\n");
}
if(data != false) {
$('.events_fired_li_empty').remove();
$('#button_status')
.attr(
'src','../../images/sound_events_console_alert.gif'
);
$('audio').remove();
if(data['sound'] == '') {
data['sound'] = 'include/sounds/Star_Trek_emergency_simulation.wav';
}
$('body')
.append("<audio src='../../" + data['sound'] + "' autoplay='true' hidden='true' loop='true'>");
.append(
"<audio id='audio-boom' src='" + sound + "' autoplay='true' hidden='true' loop='true' >"
);
data.forEach(function (element) {
var li = document.createElement('li');
li.insertAdjacentHTML(
'beforeend',
'<div class="flex0">'+element.priority+'</div>'
);
li.insertAdjacentHTML(
'beforeend',
'<div class="flex0">'+element.type+'</div>'
);
li.insertAdjacentHTML(
'beforeend',
'<div class="mess">'+element.message+'</div>'
);
li.insertAdjacentHTML(
'beforeend',
'<div class="flex-time">'+element.timestamp+'</div>'
);
$('.events_fired').append(li);
});
function removeAudio() {
$('audio').remove();
}
// -100 delay sound.
setTimeout(
removeAudio,
(parseInt($('#time_sound').val()) * 1000) - 100
);
}
},
"json"
@ -412,11 +463,6 @@ function check_event() {
}
}
$(document).ready (function () {
//10 seconds between ajax request
setInterval("check_event()", (10 * 1000));
});
</script>
<?php

View File

@ -420,7 +420,6 @@ if (check_acl($config['id_user'], 0, 'ER')
// Sound Events.
$javascript = "javascript: window.open('operation/events/sound_events.php');";
$javascript = 'javascript: alert(111);';
$javascript = 'javascript: openSoundEventWindow();';
$sub[$javascript]['text'] = __('Sound Events');
$sub[$javascript]['id'] = 'Sound Events';
@ -432,12 +431,12 @@ if (check_acl($config['id_user'], 0, 'ER')
url = '<?php echo ui_get_full_url('operation/events/sound_events.php'); ?>';
// devicePixelRatio knows how much zoom browser applied.
var windowScale = parseFloat(window.devicePixelRatio);
var defaultWidth = 600;
var defaultHeight = 450;
var defaultWidth = 630;
var defaultHeight = 630;
// If the scale is 1, no zoom has been applied.
var windowWidth = windowScale <= 1 ? defaultWidth : windowScale*defaultWidth;
var windowHeight = windowScale <= 1 ? defaultHeight : windowScale*defaultHeight + (defaultHeight*0.1);
window.open(
url,
'<?php __('Sound Alerts'); ?>',