Switched from time range to hours old selector (SNMP console)

This commit is contained in:
fbsanchez 2020-09-18 15:07:31 +02:00
parent 7f0cc64193
commit 6f2eb57587
2 changed files with 55 additions and 86 deletions

View File

@ -394,24 +394,14 @@ function print_snmp_tags_active_filters($filter_resume=[])
} }
// Date from // Date from
if (isset($filter_resume['date_from_trap']) && $filter_resume['date_from_trap'] != '') { if (isset($filter_resume['hours_ago']) === true) {
if (isset($filter_resume['time_from_trap']) && $filter_resume['time_from_trap'] != '') { array_push(
array_push( $tags_set,
$tags_set, [
[ 'title' => __('Max. hours old'),
'title' => __('From'), 'value' => $filter_resume['hours_ago'].' '.__('hours'),
'value' => $filter_resume['date_from_trap'].' '.$filter_resume['time_from_trap'], ]
] );
);
} else {
array_push(
$tags_set,
[
'title' => __('From'),
'value' => $filter_resume['date_from_trap'],
]
);
}
} }
// Date to // Date to

View File

@ -32,6 +32,8 @@ enterprise_include('include/functions_snmp.php');
require_once 'include/functions_agents.php'; require_once 'include/functions_agents.php';
require_once 'include/functions_snmp.php'; require_once 'include/functions_snmp.php';
ui_require_css_file('snmp_view');
check_login(); check_login();
$agent_a = check_acl($config['id_user'], 0, 'AR'); $agent_a = check_acl($config['id_user'], 0, 'AR');
$agent_w = check_acl($config['id_user'], 0, 'AW'); $agent_w = check_acl($config['id_user'], 0, 'AW');
@ -46,25 +48,29 @@ if (!$agent_a && !$agent_w) {
} }
// Read parameters. // Read parameters.
$now = new DateTime();
$ago = new DateTime();
$interval = new DateInterval('PT8H');
$ago->sub($interval);
$filter_severity = (int) get_parameter('filter_severity', -1); $filter_severity = (int) get_parameter('filter_severity', -1);
$filter_fired = (int) get_parameter('filter_fired', -1); $filter_fired = (int) get_parameter('filter_fired', -1);
$filter_status = (int) get_parameter('filter_status', 0); $filter_status = (int) get_parameter('filter_status', 0);
$free_search_string = (string) get_parameter('free_search_string', ''); $free_search_string = (string) get_parameter('free_search_string', '');
$pagination = (int) get_parameter('pagination', $config['block_size']); $pagination = (int) get_parameter('pagination', $config['block_size']);
$offset = (int) get_parameter('offset', 0); $offset = (int) get_parameter('offset', 0);
$pure = (int) get_parameter('pure', 0);
$trap_type = (int) get_parameter('trap_type', -1); $trap_type = (int) get_parameter('trap_type', -1);
$group_by = (int) get_parameter('group_by', 0); $group_by = (int) get_parameter('group_by', 0);
$refr = (int) get_parameter('refresh'); $refr = (int) get_parameter('refresh');
$default_refr = !empty($refr) ? $refr : $config['vc_refr']; $default_refr = !empty($refr) ? $refr : $config['vc_refr'];
$date_from_trap = get_parameter('date_from_trap', $ago->format('Y/m/d')); $hours_ago = get_parameter('hours_ago', 8);
$date_to_trap = get_parameter('date_to_trap', $now->format('Y/m/d'));
$time_from_trap = get_parameter('time_from_trap', $ago->format('H:i:s')); // Build ranges.
$time_to_trap = get_parameter('time_to_trap', $now->format('H:i:s')); $now = new DateTime();
$ago = new DateTime();
$interval = new DateInterval(sprintf('PT%dH', $hours_ago));
$ago->sub($interval);
$date_from_trap = $ago->format('Y/m/d');
$date_to_trap = $now->format('Y/m/d');
$time_from_trap = $ago->format('H:i:s');
$time_to_trap = $now->format('H:i:s');
$user_groups = users_get_groups($config['id_user'], $access, false); $user_groups = users_get_groups($config['id_user'], $access, false);
@ -80,7 +86,11 @@ foreach ($user_groups as $id => $name) {
$i++; $i++;
} }
$url = 'index.php?sec=estado&sec2=operation/snmpconsole/snmp_view&filter_severity='.$filter_severity.'&filter_fired='.$filter_fired.'&free_search_string='.$free_search_string.'&pagination='.$pagination.'&offset='.$offset.'&trap_type='.$trap_type.'&group_by='.$group_by.'&date_from_trap='.$date_from_trap.'&date_to_trap='.$date_to_trap.'&time_from_trap='.$time_from_trap.'&time_to_trap='.$time_to_trap; $url = 'index.php?sec=estado&sec2=operation/snmpconsole/snmp_view';
$url .= '&filter_severity='.$filter_severity.'&filter_fired='.$filter_fired;
$url .= '&free_search_string='.$free_search_string.'&pagination='.$pagination;
$url .= '&offset='.$offset.'&trap_type='.$trap_type.'&group_by='.$group_by;
$url .= '&hours_ago='.$hours_ago.'&pure='.$pure;
$statistics['text'] = '<a href="index.php?sec=estado&sec2=operation/snmpconsole/snmp_statistics&pure='.$config['pure'].'&refr='.$refr.'">'.html_print_image('images/op_reporting.png', true, ['title' => __('Statistics')]).'</a>'; $statistics['text'] = '<a href="index.php?sec=estado&sec2=operation/snmpconsole/snmp_statistics&pure='.$config['pure'].'&refr='.$refr.'">'.html_print_image('images/op_reporting.png', true, ['title' => __('Statistics')]).'</a>';
$list['text'] = '<a href="'.$url.'&pure='.$config['pure'].'&refresh='.$refr.'">'.html_print_image('images/op_snmp.png', true, ['title' => __('List')]).'</a>'; $list['text'] = '<a href="'.$url.'&pure='.$config['pure'].'&refresh='.$refr.'">'.html_print_image('images/op_snmp.png', true, ['title' => __('List')]).'</a>';
@ -594,15 +604,16 @@ $table->data[2][4] = html_print_input_text(
true true
); );
$table->data[4][0] = '<strong>'.__('From (Date)').'</strong>'; $table->data[4][0] = '<strong>'.__('Max. hours old').'</strong>';
$table->data[4][1] = html_print_input_text('date_from_trap', $date_from_trap, '', 15, 10, true); $table->data[4][1] = html_print_input(
$table->data[4][2] = '<strong>'.__('To (Date)').'</strong>'; [
$table->data[4][3] = html_print_input_text('date_to_trap', $date_to_trap, '', 15, 10, true); 'type' => 'number',
'name' => 'hours_ago',
$table->data[5][0] = '<strong>'.__('From (Time)').'</strong>'; 'value' => $hours_ago,
$table->data[5][1] = html_print_input_text('time_from_trap', $time_from_trap, false, 15, 10, true); 'step' => 1,
$table->data[5][2] = '<strong>'.__('To (Time)').'</strong>'; 'return' => true,
$table->data[5][3] = html_print_input_text('time_to_trap', $time_to_trap, false, 15, 10, true); ]
);
// Type filter (ColdStart, WarmStart, LinkDown, LinkUp, authenticationFailure, Other). // Type filter (ColdStart, WarmStart, LinkDown, LinkUp, authenticationFailure, Other).
$table->data[6][1] = '<strong>'.__('Trap type').'</strong>'.ui_print_help_tip(__('Search by trap type'), true); $table->data[6][1] = '<strong>'.__('Trap type').'</strong>'.ui_print_help_tip(__('Search by trap type'), true);
@ -634,7 +645,7 @@ if ($config['dbtype'] != 'oracle') {
$table->data[3][4] .= __('No').'&nbsp;'.html_print_radio_button('group_by', 0, '', $group_by, true); $table->data[3][4] .= __('No').'&nbsp;'.html_print_radio_button('group_by', 0, '', $group_by, true);
} }
$filter = '<form method="POST" action="index.php?sec=snmpconsole&sec2=operation/snmpconsole/snmp_view&refresh='.((int) get_parameter('refresh', 0)).'&pure='.$config['pure'].'">'; $filter = '<form id="filter_form" method="POST" action="index.php?sec=snmpconsole&sec2=operation/snmpconsole/snmp_view&refresh='.((int) get_parameter('refresh', 0)).'&pure='.$config['pure'].'">';
$filter .= html_print_table($table, true); $filter .= html_print_table($table, true);
$filter .= '<div style="width: '.$table->width.'; text-align: right;">'; $filter .= '<div style="width: '.$table->width.'; text-align: right;">';
$filter .= html_print_submit_button(__('Update'), 'search', false, 'class="sub upd"', true); $filter .= html_print_submit_button(__('Update'), 'search', false, 'class="sub upd"', true);
@ -648,10 +659,7 @@ $filter_resume['pagination'] = $paginations[$pagination];
$filter_resume['free_search_string'] = $free_search_string; $filter_resume['free_search_string'] = $free_search_string;
$filter_resume['filter_status'] = $status_array[$filter_status]; $filter_resume['filter_status'] = $status_array[$filter_status];
$filter_resume['group_by'] = $group_by; $filter_resume['group_by'] = $group_by;
$filter_resume['date_from_trap'] = $date_from_trap; $filter_resume['hours_ago'] = $hours_ago;
$filter_resume['time_from_trap'] = $time_from_trap;
$filter_resume['date_to_trap'] = $date_to_trap;
$filter_resume['time_to_trap'] = $time_to_trap;
$filter_resume['trap_type'] = $trap_types[$trap_type]; $filter_resume['trap_type'] = $trap_types[$trap_type];
$traps = db_get_all_rows_sql($sql); $traps = db_get_all_rows_sql($sql);
@ -778,7 +786,12 @@ if (($config['dbtype'] == 'oracle') && ($traps !== false)) {
} }
} }
$url_snmp = 'index.php?sec=snmpconsole&sec2=operation/snmpconsole/snmp_view&filter_severity='.$filter_severity.'&filter_fired='.$filter_fired.'&filter_status='.$filter_status.'&refresh='.((int) get_parameter('refresh', 0)).'&pure='.$config['pure'].'&trap_type='.$trap_type.'&group_by='.$group_by.'&free_search_string='.$free_search_string.'&date_from_trap='.$date_from_trap.'&date_to_trap='.$date_to_trap.'&time_from_trap='.$time_from_trap.'&time_to_trap='.$time_to_trap; $url_snmp = 'index.php?sec=snmpconsole&sec2=operation/snmpconsole/snmp_view';
$url_snmp .= '&filter_severity='.$filter_severity.'&filter_fired='.$filter_fired;
$url_snmp .= '&filter_status='.$filter_status.'&refresh='.((int) get_parameter('refresh', 0));
$url_snmp .= '&pure='.$config['pure'].'&trap_type='.$trap_type;
$url_snmp .= '&group_by='.$group_by.'&free_search_string='.$free_search_string;
$url_snmp .= '&hours_ago='.$hours_ago;
$urlPagination = $url_snmp.'&pagination='.$pagination.'&offset='.$offset; $urlPagination = $url_snmp.'&pagination='.$pagination.'&offset='.$offset;
@ -786,6 +799,7 @@ ui_pagination($trapcount, $urlPagination, $offset, $pagination);
echo '<form name="eventtable" method="POST" action="'.$urlPagination.'">'; echo '<form name="eventtable" method="POST" action="'.$urlPagination.'">';
$table = new StdClass();
$table->cellpadding = 0; $table->cellpadding = 0;
$table->cellspacing = 0; $table->cellspacing = 0;
$table->width = '100%'; $table->width = '100%';
@ -1005,7 +1019,14 @@ if ($traps !== false) {
<td align="left" >'; <td align="left" >';
if ($group_by) { if ($group_by) {
$new_url = 'index.php?sec=snmpconsole&sec2=operation/snmpconsole/snmp_view&filter_severity='.$filter_severity.'&filter_fired='.$filter_fired.'&filter_status='.$filter_status.'&refresh='.((int) get_parameter('refresh', 0)).'&pure='.$config['pure'].'&group_by=0&free_search_string='.$free_search_string.'&date_from_trap='.$date_from_trap.'&date_to_trap='.$date_to_trap.'&time_from_trap='.$time_from_trap.'&time_to_trap='.$time_to_trap; $new_url = 'index.php?sec=snmpconsole&sec2=operation/snmpconsole/snmp_view';
$new_url .= '&filter_severity='.$filter_severity;
$new_url .= '&filter_fired='.$filter_fired;
$new_url .= '&filter_status='.$filter_status;
$new_url .= '&refresh='.((int) get_parameter('refresh', 0));
$new_url .= '&pure='.$config['pure'];
$new_url .= '&group_by=0&free_search_string='.$free_search_string;
$new_url .= '&hours_ago='.$hours_ago;
$string .= '<a href='.$new_url.'>'.__('See more details').'</a>'; $string .= '<a href='.$new_url.'>'.__('See more details').'</a>';
} else { } else {
@ -1208,48 +1229,6 @@ ui_include_time_picker();
<script language="JavaScript" type="text/javascript"> <script language="JavaScript" type="text/javascript">
$(document).ready( function() { $(document).ready( function() {
var $startDate = $("#text-date_from_trap");
var $startTime = $("#text-time_from_trap");
var $endDate = $("#text-date_to_trap");
var $endTime = $("#text-time_to_trap");
$startDate.datepicker({
dateFormat: "<?php echo DATE_FORMAT_JS; ?>",
onClose: function(selectedDate) {
$endDate.datepicker("option", "minDate", selectedDate);
}
});
$endDate.datepicker({
dateFormat: "<?php echo DATE_FORMAT_JS; ?>",
onClose: function(selectedDate) {
$startDate.datepicker("option", "maxDate", selectedDate);
}
});
$startTime.timepicker({
showSecond: true,
timeFormat: '<?php echo TIME_FORMAT_JS; ?>',
timeOnlyTitle: '<?php echo __('Choose time'); ?>',
timeText: '<?php echo __('Time'); ?>',
hourText: '<?php echo __('Hour'); ?>',
minuteText: '<?php echo __('Minute'); ?>',
secondText: '<?php echo __('Second'); ?>',
currentText: '<?php echo __('Now'); ?>',
closeText: '<?php echo __('Close'); ?>'
});
$endTime.timepicker({
showSecond: true,
timeFormat: '<?php echo TIME_FORMAT_JS; ?>',
timeOnlyTitle: '<?php echo __('Choose time'); ?>',
timeText: '<?php echo __('Time'); ?>',
hourText: '<?php echo __('Hour'); ?>',
minuteText: '<?php echo __('Minute'); ?>',
secondText: '<?php echo __('Second'); ?>',
currentText: '<?php echo __('Now'); ?>',
closeText: '<?php echo __('Close'); ?>'
});
var controls = document.getElementById('dashboard-controls'); var controls = document.getElementById('dashboard-controls');
autoHideElement(controls, 1000); autoHideElement(controls, 1000);