mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
webui: Timezone support for graylog (#7799)
* added timezone support for graylog * using default user timezone if none is configured * newline fix, added copyrights * copyright correction * copyright correction * copyright fix
This commit is contained in:
@@ -24,6 +24,13 @@ $config['graylog']['password'] = 'admin';
|
||||
$config['graylog']['version'] = '2.1';
|
||||
```
|
||||
|
||||
Graylog messages are stored using GMT timezone. You can display graylog messages in LibreNMS webui using your desired timezone by setting following option in config.php:
|
||||
|
||||
```php
|
||||
$config['graylog']['timezone'] = 'Europe/Bucharest';
|
||||
```
|
||||
> Timezone must be PHP supported timezones, available at: <a href="http://php.net/manual/en/timezones.php">http://php.net/manual/en/timezones.php</a>
|
||||
|
||||
> Since Graylog 2.1, the default API path is /api/
|
||||
|
||||
If you are running a version earlier than Graylog then please set `$config['graylog']['version']` to the version
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* LibreNMS
|
||||
*
|
||||
@@ -10,6 +9,12 @@
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version. Please see LICENSE.txt at the top level of
|
||||
* the source code distribution for details.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @subpackage webui
|
||||
* @link http://librenms.org
|
||||
* @copyright 2017 LibreNMS
|
||||
* @author LibreNMS Contributors
|
||||
*/
|
||||
|
||||
if (empty($results_limit)) {
|
||||
@@ -21,7 +26,7 @@ $tmp_output = '<h3>Graylog</h3>
|
||||
<table id="graylog" class="table table-hover table-condensed graylog">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-column-id="timestamp">Timestamp</th>
|
||||
<th data-column-id="timestamp" data-formatter="browserTime">Timestamp</th>
|
||||
<th data-column-id="source">Source</th>
|
||||
<th data-column-id="message">Message</th>
|
||||
<th data-column-id="facility" data-visible="false">Facility</th>
|
||||
@@ -71,6 +76,12 @@ if (empty($filter_device) && isset($_POST['hostname'])) {
|
||||
$filter_device = mres($_POST['hostname']);
|
||||
}
|
||||
|
||||
if (isset($config['graylog']['timezone'])) {
|
||||
$timezone = 'row.timestamp;';
|
||||
} else {
|
||||
$timezone = 'moment.parseZone(row.timestamp).local().format("YYYY-MM-DD HH:MM:SS");';
|
||||
}
|
||||
|
||||
$tmp_output .= '
|
||||
"<div class=\"form-group\"><select name=\"range\" class=\"form-group input-sm\">"+
|
||||
"<option value=\"300\">Search last 5 minutes</option>"+
|
||||
@@ -94,6 +105,11 @@ $tmp_output .= '
|
||||
var graylog_grid = $("#graylog").bootgrid({
|
||||
ajax: true,
|
||||
rowCount: ['. $results_limit .', 25,50,100,250,-1],
|
||||
formatters: {
|
||||
"browserTime": function(column, row) {
|
||||
return '.$timezone.'
|
||||
}
|
||||
},
|
||||
';
|
||||
|
||||
if (isset($no_form) && $no_form !== true) {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* LibreNMS
|
||||
*
|
||||
@@ -10,6 +9,12 @@
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version. Please see LICENSE.txt at the top level of
|
||||
* the source code distribution for details.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @subpackage webui
|
||||
* @link http://librenms.org
|
||||
* @copyright 2017 LibreNMS
|
||||
* @author LibreNMS Contributors
|
||||
*/
|
||||
|
||||
$filter_hostname = mres($_POST['hostname']);
|
||||
@@ -62,8 +67,21 @@ $context = stream_context_create(array(
|
||||
$messages = json_decode(file_get_contents($graylog_url, false, $context), true);
|
||||
|
||||
foreach ($messages['messages'] as $message) {
|
||||
if (isset($config['graylog']['timezone'])) {
|
||||
$userTimezone = new DateTimeZone($config['graylog']['timezone']);
|
||||
$graylogTime = new DateTime($message['message']['timestamp']);
|
||||
$offset = $userTimezone->getOffset($graylogTime);
|
||||
|
||||
$timeInterval = DateInterval::createFromDateString((string)$offset . 'seconds');
|
||||
$graylogTime->add($timeInterval);
|
||||
$displayTime = $graylogTime->format('Y-m-d H:i:s');
|
||||
} else {
|
||||
$displayTime = $message['message']['timestamp'];
|
||||
}
|
||||
|
||||
|
||||
$response[] = array(
|
||||
'timestamp' => $message['message']['timestamp'],
|
||||
'timestamp' => $displayTime,
|
||||
'source' => '<a href="'.generate_url(array('page'=>'device', 'device'=>$message['message']['source'])).'">'.$message['message']['source'].'</a>',
|
||||
'message' => $message['message']['message'],
|
||||
'facility' => $message['message']['facility'],
|
||||
|
||||
@@ -1,4 +1,17 @@
|
||||
<?php
|
||||
/*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version. Please see LICENSE.txt at the top level of
|
||||
* the source code distribution for details.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @subpackage webui
|
||||
* @link http://librenms.org
|
||||
* @copyright 2017 LibreNMS
|
||||
* @author LibreNMS Contributors
|
||||
*/
|
||||
|
||||
$no_refresh = true;
|
||||
require_once 'includes/common/graylog.inc.php';
|
||||
|
||||
Reference in New Issue
Block a user