Skip to content

Commit bf9f819

Browse files
authored
Fix mtu status changed event log 1 -> 1 (librenms#18683)
* Fix mtu status changed event log 1 -> 1 Add attribute name to eventlog Only update/log specific attributes * Use common log message format
1 parent 7b48a9d commit bf9f819

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

LibreNMS/Modules/Core.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use App\Facades\LibrenmsConfig;
3030
use App\Models\Device;
3131
use App\Models\Eventlog;
32+
use App\Observers\DeviceObserver;
3233
use Illuminate\Support\Facades\Cache;
3334
use Illuminate\Support\Str;
3435
use LibreNMS\Enum\Severity;
@@ -70,9 +71,12 @@ public function discover(OS $os): void
7071
'sysDescr' => $snmpdata['.1.3.6.1.2.1.1.1.0'] ?? null,
7172
]);
7273

73-
foreach ($device->getDirty() as $attribute => $value) {
74-
Eventlog::log($value . ' -> ' . $device->$attribute, $device, 'system', Severity::Notice);
75-
$os->getDeviceArray()[$attribute] = $value; // update device array
74+
foreach (['sysObjectID', 'sysName', 'sysDescr'] as $attribute) {
75+
if ($device->isDirty($attribute)) {
76+
$message = DeviceObserver::attributeChangedMessage($attribute, $device->$attribute, $device->getOriginal($attribute));
77+
Eventlog::log($message, $device, 'system', Severity::Notice);
78+
$os->getDeviceArray()[$attribute] = $device->$attribute; // update device array
79+
}
7680
}
7781

7882
// detect OS

app/Models/Device.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ protected function casts(): array
9999
'last_polled' => 'datetime',
100100
'last_ping' => 'datetime',
101101
'status' => 'boolean',
102+
'mtu_status' => 'boolean',
102103
'ignore' => 'boolean',
103104
'ignore_status' => 'boolean',
104105
'disabled' => 'boolean',

app/Observers/DeviceObserver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public function pivotAttached(Device $device, $relationName, $pivotIds, $pivotId
237237
}
238238
}
239239

240-
public static function attributeChangedMessage($attribute, $value, $previous)
240+
public static function attributeChangedMessage($attribute, $value, $previous): string
241241
{
242242
return trans("device.attributes.$attribute") . ': '
243243
. (($previous && $previous != $value) ? "$previous -> " : '')

lang/en/device.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
'location' => 'Location',
1212
'os' => 'Device OS',
1313
'serial' => 'Serial',
14+
'sysDescr' => 'sysDescr',
1415
'sysName' => 'sysName',
16+
'sysObjectID' => 'sysObjectID',
1517
'version' => 'OS Version',
1618
'type' => 'Device type',
1719
],

0 commit comments

Comments
 (0)