From 426715bcaa1e4cd311d5ea940f7a69b892db0382 Mon Sep 17 00:00:00 2001 From: Koos85 Date: Thu, 10 Oct 2024 09:23:35 +0200 Subject: [PATCH] filter out object-identity as well --- asyncsnmplib/mib/utils.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/asyncsnmplib/mib/utils.py b/asyncsnmplib/mib/utils.py index e0cc162..417b134 100644 --- a/asyncsnmplib/mib/utils.py +++ b/asyncsnmplib/mib/utils.py @@ -77,7 +77,11 @@ def on_result( base_name = result_name = base['name'] prefixlen = len(base_oid) + 1 - if base['tp'] == 'OBJECT IDENTIFIER': + # check if the type of the base oid is table or scalar object. + # scalar objects have (0, ) as index (oid suffix) + # in some mibs (i.e. SW-MIB) the assignments are done with the + # OBJECT-IDENTITY macro + if base['tp'] in ('OBJECT IDENTIFIER', 'OBJECT-IDENTITY'): # filter out recursive "SEQUENCE" types result = [res for res in result if res[0][prefixlen] == 0] elif base_name.endswith('XEntry'): @@ -123,7 +127,11 @@ def on_result_base( result_name = base['name'] prefixlen = len(base_oid) + 1 - if base['tp'] == 'OBJECT IDENTIFIER': + # check if the type of the base oid is table or scalar object. + # scalar objects have (0, ) as index (oid suffix) + # in some mibs (i.e. SW-MIB) the assignments are done with the + # OBJECT-IDENTITY macro + if base['tp'] in ('OBJECT IDENTIFIER', 'OBJECT-IDENTITY'): # filter out recursive "SEQUENCE" types result = [res for res in result if res[0][prefixlen] == 0]