diff --git a/app/Models/Device.php b/app/Models/Device.php index b533e77456..42c4376ea5 100644 --- a/app/Models/Device.php +++ b/app/Models/Device.php @@ -35,7 +35,37 @@ class Device extends BaseModel public $timestamps = false; protected $primaryKey = 'device_id'; - protected $fillable = ['hostname', 'ip', 'status', 'status_reason', 'sysName', 'sysDescr', 'sysObjectID', 'hardware', 'version', 'features', 'serial', 'icon']; + protected $fillable = [ + 'hostname', + 'ip', + 'status', + 'status_reason', + 'sysName', + 'sysDescr', + 'sysObjectID', + 'hardware', + 'version', + 'features', + 'serial', + 'icon', + 'overwrite_ip', + 'os', + 'community', + 'port', + 'transport', + 'snmpver', + 'poller_group', + 'port_association_mode', + 'snmp_disable', + // ---- snmpV3 fields ---- + 'authlevel', + 'authname', + 'authpass', + 'authalgo', + 'cryptopass', + 'cryptoalgo', + ]; + protected $casts = [ 'last_polled' => 'datetime', 'status' => 'boolean', diff --git a/app/Observers/DeviceObserver.php b/app/Observers/DeviceObserver.php index 955d3ca601..47e7f9ecf9 100644 --- a/app/Observers/DeviceObserver.php +++ b/app/Observers/DeviceObserver.php @@ -3,9 +3,21 @@ namespace App\Observers; use App\Models\Device; +use Log; class DeviceObserver { + /** + * Handle the device "created" event. + * + * @param \App\Models\Device $device + * @return void + */ + public function created(Device $device) + { + Log::event("Device $device->hostname has been created", $device, 'system', 3); + } + /** * Handle the device "updated" event. * @@ -22,11 +34,11 @@ class DeviceObserver // key attribute changes foreach (['os', 'sysName', 'version', 'hardware', 'features', 'serial', 'icon', 'type'] as $attribute) { if ($device->isDirty($attribute)) { - \Log::event(self::attributeChangedMessage($attribute, $device->$attribute, $device->getOriginal($attribute)), $device, 'system', 3); + Log::event(self::attributeChangedMessage($attribute, $device->$attribute, $device->getOriginal($attribute)), $device, 'system', 3); } } if ($device->isDirty('location_id')) { - \Log::event(self::attributeChangedMessage('location', (string) $device->location, null), $device, 'system', 3); + Log::event(self::attributeChangedMessage('location', (string) $device->location, null), $device, 'system', 3); } } diff --git a/includes/functions.php b/includes/functions.php index 6ebcf6c7a5..e1e46bddbd 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -643,9 +643,9 @@ function createHost( } } - $device_id = dbInsert($device, 'devices'); - if ($device_id) { - return $device_id; + $deviceModel = Device::create($device); + if ($deviceModel->device_id) { + return $deviceModel->device_id; } throw new \Exception('Failed to add host to the database, please run ./validate.php');