From 9e9f5f787f63c4acacfd14ea0ff926f9ec9d111c Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Sun, 17 Jan 2016 13:57:34 +1000 Subject: [PATCH 1/2] Fix short name generation Should only replace first occurrence of prefix in the string. Also only strips the prefix if it saves more than 2 characters. This fixes a bug where, e.g., 'casnDisconnect' would be shortened to 'asnDisonnet'. --- includes/snmp.inc.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/includes/snmp.inc.php b/includes/snmp.inc.php index 6d1c32238..d2f3c2323 100644 --- a/includes/snmp.inc.php +++ b/includes/snmp.inc.php @@ -1189,8 +1189,10 @@ function load_mibdefs($module, $name) // add shortname to each element $prefix = longest_matching_prefix($name, $object_types); - foreach ($result as $mib => $m) { - $result[$mib]['shortname'] = str_replace($prefix, '', $m['object_type']); + if (strlen($prefix) > 2) { + foreach ($result as $mib => $m) { + $result[$mib]['shortname'] = preg_replace("/^$prefix/", '', $m['object_type'], 1); + } } d_print_r($result); From fc6a4b7076321fb7c30750ae2c35a5a85f083241 Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Sun, 17 Jan 2016 14:05:37 +1000 Subject: [PATCH 2/2] Include shortname in all cases --- includes/snmp.inc.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/includes/snmp.inc.php b/includes/snmp.inc.php index d2f3c2323..8a7cb8069 100644 --- a/includes/snmp.inc.php +++ b/includes/snmp.inc.php @@ -1189,10 +1189,13 @@ function load_mibdefs($module, $name) // add shortname to each element $prefix = longest_matching_prefix($name, $object_types); - if (strlen($prefix) > 2) { - foreach ($result as $mib => $m) { + foreach ($result as $mib => $m) { + if (strlen($prefix) > 2) { $result[$mib]['shortname'] = preg_replace("/^$prefix/", '', $m['object_type'], 1); } + else { + $result[$mib]['shortname'] = $m['object_type']; + } } d_print_r($result);