From 1544eadd37b8ad115e68615faca54363d2e588fe Mon Sep 17 00:00:00 2001 From: SourceDoctor Date: Tue, 24 Aug 2021 20:28:18 +0200 Subject: [PATCH] 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 --- doc/Support/Configuration.md | 9 +++++++++ includes/discovery/ports.inc.php | 12 ++++++++++++ misc/config_definitions.json | 4 ++++ 3 files changed, 25 insertions(+) diff --git a/doc/Support/Configuration.md b/doc/Support/Configuration.md index 49b5900f52..bbfc39280a 100644 --- a/doc/Support/Configuration.md +++ b/doc/Support/Configuration.md @@ -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 diff --git a/includes/discovery/ports.inc.php b/includes/discovery/ports.inc.php index 86f0db0779..4cac9dd845 100644 --- a/includes/discovery/ports.inc.php +++ b/includes/discovery/ports.inc.php @@ -1,6 +1,7 @@ $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) { diff --git a/misc/config_definitions.json b/misc/config_definitions.json index a562c706fd..209074e010 100644 --- a/misc/config_definitions.json +++ b/misc/config_definitions.json @@ -862,6 +862,10 @@ "default": false, "type": "boolean" }, + "default_port_group": { + "default": 0, + "type": "integer" + }, "device_location_map_open": { "order": 2, "group": "webui",