Skip to content

Commit 37942c7

Browse files
authored
Fix non-utf prefix for device fields (librenms#18956)
* Fix non-utf prefix for device fields * Fixed test data
1 parent 383acba commit 37942c7

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

LibreNMS/Modules/Os.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,11 @@ private function handleChanges(\LibreNMS\OS $os): void
153153
Log::info(trans('device.attributes.location') . ': ' . $device->location?->display());
154154
foreach (['hardware', 'version', 'features', 'serial'] as $attribute) {
155155
if (isset($device->$attribute)) {
156-
$device->$attribute = trim($device->$attribute);
156+
$device->$attribute = trim(preg_replace('/^[\x00-\x1F\x7F-\xFF]+/', '', $device->$attribute));
157+
}
158+
if ($device->isDirty($attribute)) {
159+
Log::info(DeviceObserver::attributeChangedMessage($attribute, $device->$attribute, $device->getOriginal($attribute)));
157160
}
158-
Log::info(DeviceObserver::attributeChangedMessage($attribute, $device->$attribute, $device->getOriginal($attribute)));
159161
}
160162

161163
$device->save();

tests/data/jetdirect_m130nw.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"sysObjectID": ".1.3.6.1.4.1.11.2.3.9.1",
88
"sysDescr": "HP ETHERNET MULTI-ENVIRONMENT,SN:VNCRC48198,FN:4Q817L4,SVCID:31339,PID:HP LaserJet MFP M130nw",
99
"sysContact": "<private>",
10-
"version": "\u0001\u001520201023",
10+
"version": "20201023",
1111
"hardware": "LaserJet MFP M129-M134",
1212
"features": null,
1313
"location": "<private>",

0 commit comments

Comments
 (0)