Reject API device_add that are missing snmp info (#16314)

This commit is contained in:
Tony Murray
2024-08-27 07:08:19 -05:00
committed by GitHub
parent 3e3d09bb26
commit 9e4b2fa3a3
2 changed files with 29 additions and 1 deletions

View File

@@ -167,6 +167,30 @@ class Device extends BaseModel
return null;
}
public function hasSnmpInfo(): bool
{
if ($this->snmpver == 'v3') {
if ($this->authlevel == 'authNoPriv') {
return ! empty($this->authname) && ! empty($this->authpass);
}
if ($this->authlevel == 'authPriv') {
return ! empty($this->authname)
&& ! empty($this->authpass)
&& ! empty($this->cryptoalgo)
&& ! empty($this->cryptopass);
}
return $this->authlevel !== 'noAuthNoPriv'; // reject if not noAuthNoPriv
}
if ($this->snmpver == 'v2c' || $this->snmpver == 'v1') {
return ! empty($this->community);
}
return false; // no known snmpver
}
/**
* Get VRF contexts to poll.
* If no contexts are found, return the default context ''