Minor fix and tweak for graylog integration (#15455)

* Minor fix and tweak for graylog integration

* More flexible in other use cases

* fix again?
This commit is contained in:
Wheel
2023-11-02 04:35:44 +01:00
committed by GitHub
parent 9ca95a9ba5
commit f0bbab2419
7 changed files with 22 additions and 4 deletions

View File

@@ -97,13 +97,14 @@ class GraylogApi
*/
public function buildSimpleQuery(?string $search = null, ?Device $device = null): string
{
$field = Config::get('graylog.query.field');
$query = [];
if ($search) {
$query[] = 'message:"' . $search . '"';
}
if ($device) {
$query[] = 'source: ("' . $this->getAddresses($device)->implode('" OR "') . '")';
$query[] = $field . ': ("' . $this->getAddresses($device)->implode('" OR "') . '")';
}
if (empty($query)) {

View File

@@ -111,14 +111,16 @@ class GraylogController extends SimpleTableController
$displayTime = $message['message']['timestamp'];
}
$device = $this->deviceFromSource($message['message']['source']);
$origin = $this->deviceFromSource($message['message']['gl2_remote_ip']);
$source = $this->deviceFromSource($message['message']['source']);
$level = $message['message']['level'] ?? '';
$facility = $message['message']['facility'] ?? '';
return [
'origin' => $origin ? Url::deviceLink($origin) : htmlspecialchars($message['message']['gl2_remote_ip']),
'severity' => $this->severityLabel($level),
'timestamp' => $displayTime,
'source' => $device ? Url::deviceLink($device) : htmlspecialchars($message['message']['source']),
'source' => $source ? Url::deviceLink($source) : htmlspecialchars($message['message']['source']),
'message' => htmlspecialchars($message['message']['message'] ?? ''),
'facility' => is_numeric($facility) ? "($facility) " . __("syslog.facility.$facility") : $facility,
'level' => (is_numeric($level) && $level >= 0) ? "($level) " . __("syslog.severity.$level") : $level,

View File

@@ -29,6 +29,7 @@ $tmp_output = '
<thead>
<tr>
<th data-column-id="severity" data-sortable="false"></th>
<th data-column-id="origin">Origin</th>
<th data-column-id="timestamp" data-formatter="browserTime">Timestamp</th>
<th data-column-id="level">Level</th>
<th data-column-id="source">Source</th>

View File

@@ -57,7 +57,7 @@ if (\LibreNMS\Config::get('enable_syslog') == 1) {
}
}
if (\LibreNMS\Config::get('graylog.port')) {
if (\LibreNMS\Config::get('graylog.server')) {
echo ' | ';
if ($vars['section'] == 'graylog') {
echo '<span class="pagemenu-selected">';

View File

@@ -827,6 +827,12 @@ return [
'description' => 'Version',
'help' => 'This is used to automatically create the base_uri for the Graylog API. If you have modified the API uri from the default, set this to other and specify your base_uri.',
],
'query' => [
'field' => [
'description' => 'Query api field',
'help' => 'Changes the default field to query graylog API.',
],
],
],
'html' => [
'device' => [

View File

@@ -3763,6 +3763,13 @@
"other": "Other"
}
},
"graylog.query.field": {
"default": "source",
"type": "text",
"group": "external",
"section": "graylog",
"order": 10
},
"group": {
"type": "text",
"default": "librenms"

View File

@@ -3,6 +3,7 @@
<thead>
<tr>
<th data-column-id="severity" data-sortable="false"></th>
<th data-column-id="origin">{{ __('Origin') }}</th>
<th data-column-id="timestamp" data-formatter="browserTime">{{ __('Timestamp') }}</th>
<th data-column-id="level" data-sortable="false">{{ __('Level') }}</th>
<th data-column-id="source">{{ __('Source') }}</th>