default port_group for new ports (#13166)

* default port_group for new ports

* .

* adding Docs, default Value, change keyname

* .

* Update Configuration.md

Co-authored-by: Tony Murray <murraytony@gmail.com>
This commit is contained in:
SourceDoctor
2021-08-24 20:28:18 +02:00
committed by GitHub
parent c08b203ed7
commit 1544eadd37
3 changed files with 25 additions and 0 deletions

View File

@@ -633,6 +633,15 @@ lnms config:set enable_ports_poe false
Enable / disable additional port statistics.
## Port Group
Assign a new discovered Port automatically to Port Group with this Port Group ID
(0 means no Port Group assignment)
```php
lnms config:set default_port_group 0
```
## External integration
### Rancid

View File

@@ -1,6 +1,7 @@
<?php
// Build SNMP Cache Array
use App\Models\PortGroup;
use LibreNMS\Config;
$port_stats = [];
@@ -54,6 +55,8 @@ if ($device['os'] == 'ekinops') {
require_once 'ports/ekinops.inc.php';
}
$default_port_group = Config::get('default_port_group');
// New interface detection
foreach ($port_stats as $ifIndex => $snmp_data) {
$snmp_data['ifIndex'] = $ifIndex; // Store ifIndex in port entry
@@ -68,6 +71,15 @@ foreach ($port_stats as $ifIndex => $snmp_data) {
if (! is_array($ports_db[$port_id])) {
$snmp_data['device_id'] = $device['device_id'];
$port_id = dbInsert($snmp_data, 'ports');
//default Port Group for new Ports defined?
if (! empty($default_port_group)) {
$port_group = PortGroup::find($default_port_group);
if (isset($port_group)) {
$port_group->ports()->attach([$port_id]);
}
}
$ports[$port_id] = dbFetchRow('SELECT * FROM `ports` WHERE `device_id` = ? AND `port_id` = ?', [$device['device_id'], $port_id]);
echo 'Adding: ' . $snmp_data['ifName'] . '(' . $ifIndex . ')(' . $port_id . ')';
} elseif ($ports_db[$port_id]['deleted'] == 1) {

View File

@@ -862,6 +862,10 @@
"default": false,
"type": "boolean"
},
"default_port_group": {
"default": 0,
"type": "integer"
},
"device_location_map_open": {
"order": 2,
"group": "webui",