From 3cb971e33f0484f4331d2e7a75888ce730d5b474 Mon Sep 17 00:00:00 2001 From: rsys-dev <46318454+rsys-dev@users.noreply.github.com> Date: Tue, 27 Aug 2019 19:44:27 +0200 Subject: [PATCH] Added Graylog to device overview and log level filter mechanism (#10509) * Added Recent Graylog Entries to Device Overview (WIP) * Improved "Recent Graylog" entries on device overview (WIP) Added $config['graylog']['device-page']['rowCount'] to set maximum rows shown in "Recent Graylog" on device overview (Default: 10) Added $config['graylog']['device-page']['maxLevel'] to set the maximum message level shown in "Recent Graylog" on device overview (Default: 7, validates value to be >= 0 and <= 7) * Fixed code styling issue * Added Log Level filter to Graylog widget Added Log Level filter to Graylog pages (device pages and graylog overview) * Added documentation for new configuration options * Removed unneccesary (and already commented) using Renamed "maxLevel" to "loglevel" as suggested by a colleague * Added doc for $config['graylog']['loglevel'] * Removed includes/html/print-graylog.inc.php and inlined it in includes/html/pages/device/overview/graylog.inc.php Removed comma in json object in resources/views/widgets/graylog.blade.php Replaced translation strings in resources/views/widgets/settings/graylog.blade.php with existing translation strings * log level -> minimum log level * Use Config::get() default functionality * Oops --- .../Controllers/Table/GraylogController.php | 6 +- .../Controllers/Widgets/GraylogController.php | 1 + doc/Extensions/Graylog.md | 7 ++ includes/html/common/graylog.inc.php | 17 ++++- includes/html/pages/device/overview.inc.php | 2 +- .../pages/device/overview/graylog.inc.php | 73 +++++++++++++++++++ resources/views/widgets/graylog.blade.php | 3 +- .../views/widgets/settings/graylog.blade.php | 16 ++++ 8 files changed, 120 insertions(+), 5 deletions(-) create mode 100644 includes/html/pages/device/overview/graylog.inc.php diff --git a/app/Http/Controllers/Table/GraylogController.php b/app/Http/Controllers/Table/GraylogController.php index adc8503016..53c28a8826 100644 --- a/app/Http/Controllers/Table/GraylogController.php +++ b/app/Http/Controllers/Table/GraylogController.php @@ -58,6 +58,7 @@ class GraylogController extends SimpleTableController 'stream' => 'nullable|alpha_num', 'device' => 'nullable|int', 'range' => 'nullable|int', + 'loglevel' => 'nullable|int|min:0|max:7', ]); $search = $request->get('searchPhrase'); @@ -67,7 +68,10 @@ class GraylogController extends SimpleTableController $limit = $request->get('rowCount', 10); $page = $request->get('current', 1); $offset = ($page - 1) * $limit; - $query = $api->buildSimpleQuery($search, $device); + $loglevel = $request->get('loglevel') ?? Config::get('graylog.loglevel'); + + $query = $api->buildSimpleQuery($search, $device). + ($loglevel !== null ? ' AND level: <='. $loglevel : ''); $sort = null; foreach ($request->get('sort', []) as $field => $direction) { diff --git a/app/Http/Controllers/Widgets/GraylogController.php b/app/Http/Controllers/Widgets/GraylogController.php index eb3845ed15..394fb006c9 100644 --- a/app/Http/Controllers/Widgets/GraylogController.php +++ b/app/Http/Controllers/Widgets/GraylogController.php @@ -38,6 +38,7 @@ class GraylogController extends WidgetController 'device' => null, 'range' => null, 'limit' => 15, + 'loglevel' => null, ]; /** diff --git a/doc/Extensions/Graylog.md b/doc/Extensions/Graylog.md index a9cb78468b..e514215f69 100644 --- a/doc/Extensions/Graylog.md +++ b/doc/Extensions/Graylog.md @@ -47,6 +47,13 @@ If you want to match the source address of the log entries against any IP addres the primary address and the host name to assign the log entries to a device, you can activate this function using $config['graylog']['match-any-address'] = 'true'; +There are 2 configuration parameters to influence the behaviour of the "Recent Graylog" table on the overview page of the devices. +$config['graylog']['device-page']['rowCount'] sets the maximum number of rows to be displayed (default: 10) +With $config['graylog']['device-page']['loglevel'] you can set which loglevels should be displayed on the overview page. (default: 7, min: 0, max: 7) +$config['graylog']['device-page']['loglevel'] = 4 shows only entries with a log level less than or equal to 4 (Emergency, Alert, Critical, Error, Warning). + +You can set a default Log Level Filter with $config['graylog']['loglevel'] (applies to /graylog and /device/device=/tab=logs/section=graylog/ (min: 0, max: 7) + ## Suppressing/enabling the domain part of a hostname for specific platforms You should see if what you get in syslog/Graylog matches up with your configured hosts first. If you need to modify the syslog messages from specific platforms, this may be of assistance: diff --git a/includes/html/common/graylog.inc.php b/includes/html/common/graylog.inc.php index 9d1e082d54..6b62af885a 100644 --- a/includes/html/common/graylog.inc.php +++ b/includes/html/common/graylog.inc.php @@ -80,6 +80,18 @@ if (\LibreNMS\Config::has('graylog.timezone')) { } $tmp_output .= ' + "
"+ + " 
"+ "
 
"+ " "+ ""+ - "

" + "

"; var graylog_grid = $("#graylog").bootgrid({ ajax: true, @@ -123,7 +135,8 @@ $tmp_output .= ' return { stream: "' . (isset($_POST['stream']) ? mres($_POST['stream']) : '') . '", device: "' . (isset($filter_device) ? $filter_device : '') . '", - range: "' . (isset($_POST['range']) ? mres($_POST['range']) : '') . '" + range: "' . (isset($_POST['range']) ? mres($_POST['range']) : '') . '", + loglevel: "' . (isset($_POST['loglevel']) ? mres($_POST['loglevel']) : '') . '", }; }, url: "' . url('/ajax/table/graylog') . '", diff --git a/includes/html/pages/device/overview.inc.php b/includes/html/pages/device/overview.inc.php index f5f4f66cbf..cca746c03e 100644 --- a/includes/html/pages/device/overview.inc.php +++ b/includes/html/pages/device/overview.inc.php @@ -66,7 +66,7 @@ require 'overview/sensors/waterflow.inc.php'; require 'overview/eventlog.inc.php'; require 'overview/services.inc.php'; require 'overview/syslog.inc.php'; - +require 'overview/graylog.inc.php'; echo(''); #require 'overview/current.inc.php"); diff --git a/includes/html/pages/device/overview/graylog.inc.php b/includes/html/pages/device/overview/graylog.inc.php new file mode 100644 index 0000000000..2d8021282d --- /dev/null +++ b/includes/html/pages/device/overview/graylog.inc.php @@ -0,0 +1,73 @@ + +
+
+ + '; + + $filter_device = $device["device_id"]; + $tmp_output = ' +
+
+ + + + + + + + + +
TimestampLevelMessageFacility
+
+ + '; + $common_output[] = $tmp_output; + echo implode('', $common_output); + echo ' + +
+ + '; +} diff --git a/resources/views/widgets/graylog.blade.php b/resources/views/widgets/graylog.blade.php index f86a989adc..718fbbe3d9 100644 --- a/resources/views/widgets/graylog.blade.php +++ b/resources/views/widgets/graylog.blade.php @@ -31,7 +31,8 @@ return { stream: "{{ $stream }}", device: "{{ $device }}", - range: "{{ $range }}" + range: "{{ $range }}", + loglevel: "{{ $loglevel }}" }; }, url: "{{ url('/ajax/table/graylog') }}" diff --git a/resources/views/widgets/settings/graylog.blade.php b/resources/views/widgets/settings/graylog.blade.php index 99d3521f9b..d5b4e52854 100644 --- a/resources/views/widgets/settings/graylog.blade.php +++ b/resources/views/widgets/settings/graylog.blade.php @@ -29,6 +29,22 @@ +
+ + +
+ +