add eventlog on_create device

* add eventlog on_create device

* add snmpV3 vars

* styleci minor fix
This commit is contained in:
Cupid@zul
2021-10-01 20:04:42 +01:00
committed by GitHub
parent 8ffd573cf2
commit d63656c1e0
3 changed files with 48 additions and 6 deletions

View File

@@ -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',

View File

@@ -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);
}
}

View File

@@ -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');