mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
API: device_add support display field (#13846)
* API: device_add support display field remove legacy code path update docs A few improvements to the new code too * some fixes, port_association_mode was not available * hand version -> snmpver translation
This commit is contained in:
@@ -28,6 +28,7 @@ namespace App\Actions\Device;
|
||||
use App\Models\Device;
|
||||
use Illuminate\Support\Arr;
|
||||
use LibreNMS\Config;
|
||||
use LibreNMS\Enum\PortAssociationMode;
|
||||
use LibreNMS\Exceptions\HostIpExistsException;
|
||||
use LibreNMS\Exceptions\HostnameExistsException;
|
||||
use LibreNMS\Exceptions\HostSysnameExistsException;
|
||||
@@ -79,11 +80,7 @@ class ValidateDeviceAndCreate
|
||||
}
|
||||
|
||||
$this->exceptIfHostnameExists();
|
||||
|
||||
// defaults
|
||||
$this->device->os = $this->device->os ?: 'generic';
|
||||
$this->device->status_reason = '';
|
||||
$this->device->sysName = $this->device->sysName ?: $this->device->hostname;
|
||||
$this->fillDefaults();
|
||||
|
||||
if (! $this->force) {
|
||||
$this->exceptIfIpExists();
|
||||
@@ -181,6 +178,20 @@ class ValidateDeviceAndCreate
|
||||
}
|
||||
}
|
||||
|
||||
private function fillDefaults(): void
|
||||
{
|
||||
$this->device->port = $this->device->port ?: Config::get('snmp.port', 161);
|
||||
$this->device->transport = $this->device->transport ?: Config::get('snmp.transports.0', 'udp');
|
||||
$this->device->poller_group = $this->device->poller_group ?: Config::get('default_poller_group', 0);
|
||||
$this->device->os = $this->device->os ?: 'generic';
|
||||
$this->device->status_reason = '';
|
||||
$this->device->sysName = $this->device->sysName ?: $this->device->hostname;
|
||||
$this->device->port_association_mode = $this->device->port_association_mode ?: Config::get('default_port_association_mode', 'ifIndex');
|
||||
if (! is_int($this->device->port_association_mode)) {
|
||||
$this->device->port_association_mode = PortAssociationMode::getId($this->device->port_association_mode) ?? 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \LibreNMS\Exceptions\HostExistsException
|
||||
*/
|
||||
|
Reference in New Issue
Block a user