Skip to content
This repository has been archived by the owner on Dec 17, 2021. It is now read-only.

Commit

Permalink
fix: partial fix for dynamic MIB loading
Browse files Browse the repository at this point in the history
- Fixed the find_mib_file method to add a feature that searching the MIBs using the OID without index
  • Loading branch information
lingy1028 committed Jul 20, 2021
1 parent fedde57 commit 0c995c4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
19 changes: 15 additions & 4 deletions splunk_connect_for_snmp_mib_server/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def write_mib_to_load_list(self, mib_name):
)

# Find mib module based on the oid
def find_mib_file(self, oid):
def find_mib_file(self, oid, remove_index=False):
value_tuple = str(oid).replace(".", ", ")
mib_name = None

Expand All @@ -146,7 +146,7 @@ def find_mib_file(self, oid):
logger.warning(
f"Can NOT find the mib file for the oid-{oid} -- {value_tuple}"
)
logger.debug(f"Writing the oid-{oid} into mongo")
logger.debug(f"Writing the no_mapping_mib_oid-{oid} into mongo")
try:
self._mongo_oids_coll.add_oid(str(oid))
logger.debug(
Expand All @@ -156,12 +156,23 @@ def find_mib_file(self, oid):
logger.error(
f"Error happened during add the oid - {oid} into mongo oids collection: {e}"
)
# Find mib module for OID without index (remove the last part of OID)
# Handle the scenario that tries to translate an OID which has index append at the end.
# e.g 1.3.6.1.2.1.25.1.6.0, where 0 is index and it's not part of the OID object
# So we cannot find mapping MIBs for it
# Instead, 1.3.6.1.2.1.25.1.6 is actually the OID that needed to be used for searching MIBs
# Therefore, we should remove index (0) and search the real oid (1.3.6.1.2.1.25.1.6) to detect the MIBs
if not remove_index:
oid_without_index = ".".join(oid.split(".")[:-1])
logger.debug(f"[-] oid_without_index: {oid_without_index}")
self.find_mib_file(oid_without_index, remove_index=True)
return
mib_name = mib_name[:-3]
logger.debug(f"mib_name: {mib_name}")
# load the mib module
self.load_extra_mib(mib_name, oid)



# Load additional mib module
def load_extra_mib(self, mib_module, oid):
try:
Expand Down Expand Up @@ -210,8 +221,8 @@ def mib_translator(self, var_bind):
).resolveWithMib(self._mib_view_controller)
except Exception as e:
logger.error(f"Error happened in translation: {e} trying to lazy load MIBs")
self.find_mib_file(name)
try:
self.find_mib_file(name)
translated_var_bind = rfc1902.ObjectType(
rfc1902.ObjectIdentity(name), val
).resolveWithMib(self._mib_view_controller)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,15 @@ def test_more_mib_files(self):
"val_type": "DisplayString",
},
{
"oid": "1.3.6.1.2.1.25.1.6",
"oid": "1.3.6.1.2.1.25.1.6.0",
"val": "165",
"val_type": "Gauge32",
},
]
expected_values = [
"sc4snmp.VMSTORE-MIB.mirrorLatency",
"sc4snmp.VERITAS-APPLIANCE-MONITORING-MIB.vrtssystemName",
"sc4snmp.NETSERVER-MIB.hrSystemProcesses",
"sc4snmp.NETSERVER-MIB.hrSystemProcesses_0",
]

for i in range(0, len(input_var_binds)):
Expand Down

0 comments on commit 0c995c4

Please sign in to comment.