mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
InfluxDBv2 allow filter by group and disable debug by default (#16186)
* CHG: Dynamic debug flag and ability to exclude networks. * Update config_definitions.json * Update settings.php * Update documentation. * FIX: StyleCI Fixes. * FIX: StyleCI Fixes. * CHG: Changed excluding by network to by group membership * Update settings.php * Update config_definitions.json * Update documentation. * FIX: StyleCI Fixes. * FIX: StyleCI Fixes. * FIX: Fetch device data from cache. * Add a check to see if we are trying to exclude by group before fetching groups. * remove whitespace --------- Co-authored-by: Tony Murray <[email protected]>
This commit is contained in:
co-authored by
Tony Murray
parent
ac8a69fa3b
commit
99f72823bb
@@ -26,6 +26,7 @@
|
||||
|
||||
namespace LibreNMS\Data\Store;
|
||||
|
||||
use App\Facades\DeviceCache;
|
||||
use App\Polling\Measure\Measurement;
|
||||
use InfluxDB2\Client;
|
||||
use InfluxDB2\Model\WritePrecision;
|
||||
@@ -62,6 +63,21 @@ class InfluxDBv2 extends BaseDatastore
|
||||
*/
|
||||
public function put($device, $measurement, $tags, $fields)
|
||||
{
|
||||
$device_data = DeviceCache::get($device['device_id']);
|
||||
$excluded_groups = Config::get('influxdbv2.groups-exclude');
|
||||
|
||||
if (! empty($excluded_groups)) {
|
||||
$device_groups = $device_data->groups;
|
||||
foreach ($device_groups as $group) {
|
||||
// The group name will always be parsed as lowercase, even when uppercase in the GUI.
|
||||
if (in_array(strtoupper($group->name), array_map('strtoupper', $excluded_groups))) {
|
||||
Log::warning('Skipped parsing to InfluxDBv2, device is in group: ' . $group->name);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$stat = Measurement::start('write');
|
||||
$tmp_fields = [];
|
||||
$tmp_tags['hostname'] = $device['hostname'];
|
||||
@@ -87,11 +103,13 @@ class InfluxDBv2 extends BaseDatastore
|
||||
return;
|
||||
}
|
||||
|
||||
Log::debug('InfluxDB data: ', [
|
||||
'measurement' => $measurement,
|
||||
'tags' => $tmp_tags,
|
||||
'fields' => $tmp_fields,
|
||||
]);
|
||||
if (Config::get('influxdbv2.debug') === true) {
|
||||
Log::debug('InfluxDB data: ', [
|
||||
'measurement' => $measurement,
|
||||
'tags' => $tmp_tags,
|
||||
'fields' => $tmp_fields,
|
||||
]);
|
||||
}
|
||||
|
||||
// Get a WriteApi instance from the client
|
||||
$client = self::createFromConfig();
|
||||
@@ -133,7 +151,7 @@ class InfluxDBv2 extends BaseDatastore
|
||||
$organization = Config::get('influxdbv2.organization', '');
|
||||
$allow_redirects = Config::get('influxdbv2.allow_redirects', true);
|
||||
$token = Config::get('influxdbv2.token', '');
|
||||
|
||||
$debug = Config::get('influxdbv2.debug', false);
|
||||
$client = new Client([
|
||||
'url' => $transport . '://' . $host . ':' . $port,
|
||||
'token' => $token,
|
||||
@@ -141,7 +159,7 @@ class InfluxDBv2 extends BaseDatastore
|
||||
'org' => $organization,
|
||||
'precision' => WritePrecision::S,
|
||||
'allow_redirects' => $allow_redirects,
|
||||
'debug' => true,
|
||||
'debug' => $debug,
|
||||
]);
|
||||
|
||||
return $client;
|
||||
|
||||
@@ -39,8 +39,12 @@ continue to function as normal.
|
||||
lnms config:set influxdbv2.token 'admin'
|
||||
lnms config:set influxdbv2.allow_redirect true
|
||||
lmns config:set influxdbv2.organization 'librenms'
|
||||
lmns config:set influxdbv2.debug false
|
||||
lmns config:set influxdbv2.groups-exclude ["group_name_1","group_name_2"]
|
||||
```
|
||||
|
||||
The same data stored within rrd will be sent to InfluxDB and
|
||||
recorded. You can then create graphs within Grafana or InfluxDB to display the
|
||||
information you need.
|
||||
|
||||
Please note that polling will slow down when the poller isn't able to reach or write data to InfluxDBv2.
|
||||
|
||||
@@ -978,7 +978,14 @@ return [
|
||||
'description' => 'Allow Redirects',
|
||||
'help' => 'To allow redirect from the InfluxDB server',
|
||||
],
|
||||
|
||||
'debug' => [
|
||||
'description' => 'Debug',
|
||||
'help' => 'To enable or disable verbose output to CLI',
|
||||
],
|
||||
'groups-exclude' => [
|
||||
'description' => 'Excluded device groups',
|
||||
'help' => 'Device groups excluded from sending data to InfluxDBv2',
|
||||
],
|
||||
],
|
||||
'ipmitool' => [
|
||||
'description' => 'Path to ipmtool',
|
||||
|
||||
@@ -4122,6 +4122,21 @@
|
||||
"section": "influxdbv2",
|
||||
"order": 7
|
||||
},
|
||||
"influxdbv2.debug": {
|
||||
"default": false,
|
||||
"type": "boolean",
|
||||
"group": "poller",
|
||||
"section": "influxdbv2",
|
||||
"order": 8
|
||||
},
|
||||
"influxdbv2.groups-exclude": {
|
||||
"group": "poller",
|
||||
"section": "influxdbv2",
|
||||
"order": 9,
|
||||
"type": "array",
|
||||
"default": [
|
||||
]
|
||||
},
|
||||
"install_dir": {
|
||||
"type": "directory"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user