mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
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
This commit is contained in:
@@ -58,6 +58,7 @@ class GraylogController extends SimpleTableController
|
|||||||
'stream' => 'nullable|alpha_num',
|
'stream' => 'nullable|alpha_num',
|
||||||
'device' => 'nullable|int',
|
'device' => 'nullable|int',
|
||||||
'range' => 'nullable|int',
|
'range' => 'nullable|int',
|
||||||
|
'loglevel' => 'nullable|int|min:0|max:7',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$search = $request->get('searchPhrase');
|
$search = $request->get('searchPhrase');
|
||||||
@@ -67,7 +68,10 @@ class GraylogController extends SimpleTableController
|
|||||||
$limit = $request->get('rowCount', 10);
|
$limit = $request->get('rowCount', 10);
|
||||||
$page = $request->get('current', 1);
|
$page = $request->get('current', 1);
|
||||||
$offset = ($page - 1) * $limit;
|
$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;
|
$sort = null;
|
||||||
foreach ($request->get('sort', []) as $field => $direction) {
|
foreach ($request->get('sort', []) as $field => $direction) {
|
||||||
|
@@ -38,6 +38,7 @@ class GraylogController extends WidgetController
|
|||||||
'device' => null,
|
'device' => null,
|
||||||
'range' => null,
|
'range' => null,
|
||||||
'limit' => 15,
|
'limit' => 15,
|
||||||
|
'loglevel' => null,
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -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
|
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';
|
$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
|
## 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:
|
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:
|
||||||
|
|
||||||
|
@@ -80,6 +80,18 @@ if (\LibreNMS\Config::has('graylog.timezone')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$tmp_output .= '
|
$tmp_output .= '
|
||||||
|
"<div class=\"form-group\">"+
|
||||||
|
"<select name=\"loglevel\" id=\"loglevel\" class=\"form-control\">"+
|
||||||
|
"<option value=\"\" disabled selected>Log Level</option>"+
|
||||||
|
"<option value=\"0\">'.("(0) " . __("syslog.severity.0")).'</option>"+
|
||||||
|
"<option value=\"1\">'.("(1) " . __("syslog.severity.1")).'</option>"+
|
||||||
|
"<option value=\"2\">'.("(2) " . __("syslog.severity.2")).'</option>"+
|
||||||
|
"<option value=\"3\">'.("(3) " . __("syslog.severity.3")).'</option>"+
|
||||||
|
"<option value=\"4\">'.("(4) " . __("syslog.severity.4")).'</option>"+
|
||||||
|
"<option value=\"5\">'.("(5) " . __("syslog.severity.5")).'</option>"+
|
||||||
|
"<option value=\"6\">'.("(6) " . __("syslog.severity.6")).'</option>"+
|
||||||
|
"<option value=\"7\">'.("(7) " . __("syslog.severity.7")).'</option>"+
|
||||||
|
"</select> </div>"+
|
||||||
"<div class=\"form-group\"><select name=\"range\" class=\"form-control\">"+
|
"<div class=\"form-group\"><select name=\"range\" class=\"form-control\">"+
|
||||||
"<option value=\"0\">Search all time</option>"+
|
"<option value=\"0\">Search all time</option>"+
|
||||||
"<option value=\"300\">Search last 5 minutes</option>"+
|
"<option value=\"300\">Search last 5 minutes</option>"+
|
||||||
@@ -97,7 +109,7 @@ $tmp_output .= '
|
|||||||
"</select> </div>"+
|
"</select> </div>"+
|
||||||
"<button type=\"submit\" class=\"btn btn-success\">Filter</button> "+
|
"<button type=\"submit\" class=\"btn btn-success\">Filter</button> "+
|
||||||
"</form></div>"+
|
"</form></div>"+
|
||||||
"<div class=\"col-sm-4 actionBar\"><p class=\"{{css.search}}\"></p><p class=\"{{css.actions}}\"></p></div></div></div>"
|
"<div class=\"col-sm-4 actionBar\"><p class=\"{{css.search}}\"></p><p class=\"{{css.actions}}\"></p></div></div></div>";
|
||||||
|
|
||||||
var graylog_grid = $("#graylog").bootgrid({
|
var graylog_grid = $("#graylog").bootgrid({
|
||||||
ajax: true,
|
ajax: true,
|
||||||
@@ -123,7 +135,8 @@ $tmp_output .= '
|
|||||||
return {
|
return {
|
||||||
stream: "' . (isset($_POST['stream']) ? mres($_POST['stream']) : '') . '",
|
stream: "' . (isset($_POST['stream']) ? mres($_POST['stream']) : '') . '",
|
||||||
device: "' . (isset($filter_device) ? $filter_device : '') . '",
|
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') . '",
|
url: "' . url('/ajax/table/graylog') . '",
|
||||||
|
@@ -66,7 +66,7 @@ require 'overview/sensors/waterflow.inc.php';
|
|||||||
require 'overview/eventlog.inc.php';
|
require 'overview/eventlog.inc.php';
|
||||||
require 'overview/services.inc.php';
|
require 'overview/services.inc.php';
|
||||||
require 'overview/syslog.inc.php';
|
require 'overview/syslog.inc.php';
|
||||||
|
require 'overview/graylog.inc.php';
|
||||||
echo('</div></div></div>');
|
echo('</div></div></div>');
|
||||||
|
|
||||||
#require 'overview/current.inc.php");
|
#require 'overview/current.inc.php");
|
||||||
|
73
includes/html/pages/device/overview/graylog.inc.php
Normal file
73
includes/html/pages/device/overview/graylog.inc.php
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use LibreNMS\Config;
|
||||||
|
|
||||||
|
if (Config::get('graylog.server')) {
|
||||||
|
echo '
|
||||||
|
<div class="row" id="graylog-card">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<div class="panel panel-default panel-condensed">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<a href="device/device='.$device['device_id'].'
|
||||||
|
/tab=logs/section=syslog/">
|
||||||
|
<i class="fa fa-clone fa-lg icon-theme"
|
||||||
|
aria-hidden="true"></i>
|
||||||
|
<strong>Recent Graylog</strong>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<table class="table table-hover table-condensed table-striped">';
|
||||||
|
|
||||||
|
$filter_device = $device["device_id"];
|
||||||
|
$tmp_output = '
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table id="graylog" class="table table-hover table-condensed table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th data-column-id="severity"></th>
|
||||||
|
<th data-column-id="timestamp">Timestamp</th>
|
||||||
|
<th data-column-id="level">Level</th>
|
||||||
|
<th data-column-id="message">Message</th>
|
||||||
|
<th data-column-id="facility">Facility</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
';
|
||||||
|
$rowCount = Config::get('graylog.device-page.rowCount', 10);
|
||||||
|
$loglevel = Config::get('graylog.device-page.loglevel', 7);
|
||||||
|
$tmp_output .= '
|
||||||
|
$.ajax({
|
||||||
|
type: "post",
|
||||||
|
data: {
|
||||||
|
device: "' . (isset($filter_device) ? $filter_device : '') . '",
|
||||||
|
'. ($rowCount? 'rowCount: '.$rowCount .',' : '') .'
|
||||||
|
'. ($loglevel? 'loglevel: '.$loglevel .',' : '') .'
|
||||||
|
},
|
||||||
|
url: "' . url('/ajax/table/graylog') . '",
|
||||||
|
success: function(data){
|
||||||
|
if (data.rowCount == 0) {
|
||||||
|
$("#graylog-card").remove();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var html = "<tbody>";
|
||||||
|
$("#graylog").append("<tbody></tbody>");
|
||||||
|
$.each(data.rows, function(i,v){
|
||||||
|
html = html + "<tr><td>"+v.severity+"</td><td>"+
|
||||||
|
v.timestamp+"</td><td>"+v.level+"</td><td>"+
|
||||||
|
v.message+"</td><td>"+v.facility+"</td></tr>";
|
||||||
|
});
|
||||||
|
html = html + "</tbody>";
|
||||||
|
$("#graylog").append(html);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
';
|
||||||
|
$common_output[] = $tmp_output;
|
||||||
|
echo implode('', $common_output);
|
||||||
|
echo '
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>';
|
||||||
|
}
|
@@ -31,7 +31,8 @@
|
|||||||
return {
|
return {
|
||||||
stream: "{{ $stream }}",
|
stream: "{{ $stream }}",
|
||||||
device: "{{ $device }}",
|
device: "{{ $device }}",
|
||||||
range: "{{ $range }}"
|
range: "{{ $range }}",
|
||||||
|
loglevel: "{{ $loglevel }}"
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
url: "{{ url('/ajax/table/graylog') }}"
|
url: "{{ url('/ajax/table/graylog') }}"
|
||||||
|
@@ -29,6 +29,22 @@
|
|||||||
<input type="number" min="1" class="form-control" name="limit" id="limit-{{ $id }}" placeholder="@lang('Page Size')" value="{{ $limit }}">
|
<input type="number" min="1" class="form-control" name="limit" id="limit-{{ $id }}" placeholder="@lang('Page Size')" value="{{ $limit }}">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="loglevel-{{ $id }}" class="control-label">@lang('Log Level')</label>
|
||||||
|
<select name="loglevel" id="loglevel-{{ $id }}" class="form-control">
|
||||||
|
<option value="" disabled @if($loglevel == null) selected @endif>@lang('Minimum log Level')</option>
|
||||||
|
<option value="0" @if($loglevel === 0) selected @endif>(0) @lang('syslog.severity.0')</option>
|
||||||
|
<option value="1" @if($loglevel == 1) selected @endif>(1) @lang('syslog.severity.1')</option>
|
||||||
|
<option value="2" @if($loglevel == 2) selected @endif>(2) @lang('syslog.severity.2')</option>
|
||||||
|
<option value="3" @if($loglevel == 3) selected @endif>(3) @lang('syslog.severity.3')</option>
|
||||||
|
<option value="4" @if($loglevel == 4) selected @endif>(4) @lang('syslog.severity.4')</option>
|
||||||
|
<option value="5" @if($loglevel == 5) selected @endif>(5) @lang('syslog.severity.5')</option>
|
||||||
|
<option value="6" @if($loglevel == 6) selected @endif>(6) @lang('syslog.severity.6')</option>
|
||||||
|
<option value="7" @if($loglevel == 7) selected @endif>(7) @lang('syslog.severity.7')</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="range-{{ $id }}" class="control-label">@lang('Time Range')</label>
|
<label for="range-{{ $id }}" class="control-label">@lang('Time Range')</label>
|
||||||
<select name="range" id="range-{{ $id }}" class="form-control">
|
<select name="range" id="range-{{ $id }}" class="form-control">
|
||||||
|
Reference in New Issue
Block a user