fix: grabled characters when oid already UTF-8 (#15615)

This commit is contained in:
Mitt
2023-12-05 21:13:16 +08:00
committed by GitHub
parent c88fba0b64
commit 273c6c5b97
2 changed files with 7 additions and 3 deletions

View File

@@ -22,6 +22,9 @@
* @copyright 2020 Denny Friebe
* @author Denny Friebe <denny.friebe@icera-network.de>
*/
use LibreNMS\Util\StringHelpers;
$cmc_iii_var_table = snmpwalk_cache_oid($device, 'cmcIIIVarTable', [], 'RITTAL-CMC-III-MIB', null);
$cmc_iii_sensors = [];
@@ -77,7 +80,7 @@ foreach ($cmc_iii_var_table as $index => $entry) {
}
// encode string to ensure that degree sign may be used properly for unit comparison
$unit = utf8_encode($entry['cmcIIIVarUnit']);
$unit = StringHelpers::inferEncoding($entry['cmcIIIVarUnit']);
$type = 'state';
$temperature_units = ['degree C', 'degree F', '°C', '°F'];
if ($unit == 'mA') {

View File

@@ -6,6 +6,7 @@ use LibreNMS\RRD\RrdDefinition;
use LibreNMS\Util\Debug;
use LibreNMS\Util\Mac;
use LibreNMS\Util\Number;
use LibreNMS\Util\StringHelpers;
// Build SNMP Cache Array
$data_oids = [
@@ -676,9 +677,9 @@ foreach ($ports as $port) {
// handle legacy '1' setting, otherwise use value set by override
$current_oid = $ifAlias_override === '1' ? $port['ifAlias'] : $ifAlias_override;
} else {
$current_oid = \LibreNMS\Util\StringHelpers::inferEncoding($this_port['ifAlias']);
$current_oid = $this_port['ifAlias'];
}
$current_oid = utf8_encode($current_oid); // prevent invalid non-utf8 characters
$current_oid = StringHelpers::inferEncoding($current_oid); // prevent invalid non-utf8 characters
}
if ($oid == 'ifSpeed') {
$ifSpeed_override = DeviceCache::getPrimary()->getAttrib('ifSpeed:' . $port['ifName']);