mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
add eventlog on_create device
* add eventlog on_create device * add snmpV3 vars * styleci minor fix
This commit is contained in:
@@ -35,7 +35,37 @@ class Device extends BaseModel
|
|||||||
|
|
||||||
public $timestamps = false;
|
public $timestamps = false;
|
||||||
protected $primaryKey = 'device_id';
|
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 = [
|
protected $casts = [
|
||||||
'last_polled' => 'datetime',
|
'last_polled' => 'datetime',
|
||||||
'status' => 'boolean',
|
'status' => 'boolean',
|
||||||
|
@@ -3,9 +3,21 @@
|
|||||||
namespace App\Observers;
|
namespace App\Observers;
|
||||||
|
|
||||||
use App\Models\Device;
|
use App\Models\Device;
|
||||||
|
use Log;
|
||||||
|
|
||||||
class DeviceObserver
|
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.
|
* Handle the device "updated" event.
|
||||||
*
|
*
|
||||||
@@ -22,11 +34,11 @@ class DeviceObserver
|
|||||||
// key attribute changes
|
// key attribute changes
|
||||||
foreach (['os', 'sysName', 'version', 'hardware', 'features', 'serial', 'icon', 'type'] as $attribute) {
|
foreach (['os', 'sysName', 'version', 'hardware', 'features', 'serial', 'icon', 'type'] as $attribute) {
|
||||||
if ($device->isDirty($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')) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -643,9 +643,9 @@ function createHost(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$device_id = dbInsert($device, 'devices');
|
$deviceModel = Device::create($device);
|
||||||
if ($device_id) {
|
if ($deviceModel->device_id) {
|
||||||
return $device_id;
|
return $deviceModel->device_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new \Exception('Failed to add host to the database, please run ./validate.php');
|
throw new \Exception('Failed to add host to the database, please run ./validate.php');
|
||||||
|
Reference in New Issue
Block a user