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

Commit

Permalink
fix: suffix parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
weliasz committed Nov 4, 2021
1 parent 01949f3 commit 6eeeaea
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
30 changes: 27 additions & 3 deletions splunk_connect_for_snmp_mib_server/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,29 @@ def mib_translator(self, var_bind):
else:
return None

return translated_var_bind.prettyPrint().replace(" = ", "=")
index_result = self.parse_index(translated_var_bind)
return translated_var_bind.prettyPrint().replace(" = ", "="), index_result

def parse_index(self, translated_var_bind):
object_identity, object_value = translated_var_bind
index_tuple = object_identity.getMibSymbol()[2]
family = object_identity.getMibSymbol()[0]
label_index = -1
label = object_identity.getLabel()[label_index]
index_row = self._mib_view_controller.mibBuilder.mibSymbols[family].get(label)
index_result = dict()

while abs(label_index) < len(object_identity.getLabel()) and type(index_row).__name__ == 'MibTableColumn':
label_index = label_index - 1
label = object_identity.getLabel()[label_index]
index_row = self._mib_view_controller.mibBuilder.mibSymbols[family].get(label)

if index_row and type(index_row).__name__ == 'MibTableRow':
index_tuple = [v.prettyPrint() for v in index_tuple]
index_names = [v[2] for v in index_row.getIndexNames()]
index_result = dict(zip(index_names, index_tuple))

return index_result

# Translate SNMP PDU varBinds into MIB objects using custom translation table
def custom_translator(self, oid):
Expand Down Expand Up @@ -270,7 +292,7 @@ def format_text_event(self, var_binds: list):
oid_type_string = 'oid-type{offset}="{oid_type}"'.format(
offset=offset, oid_type=name_type
)
translated_mib_string = self.mib_translator(var_bind)
translated_mib_string, parsed_index = self.mib_translator(var_bind)
if translated_mib_string:
translated_mib_string = '{translated_oid}="{translated_value}"'.format(
translated_oid=translated_mib_string.split("=")[0],
Expand Down Expand Up @@ -329,7 +351,7 @@ def format_metric_data(self, var_bind, index=0):
val_type = var_bind["val_type"]

# mib translation for oid (val keep same for original, mib translation, custom translation)
translated_mib_string = self.mib_translator(var_bind)
translated_mib_string, parsed_index = self.mib_translator(var_bind)
if translated_mib_string:
translated_oid = translated_mib_string.split("=")[0]
translated_val = translated_mib_string.split("=")[1]
Expand All @@ -351,6 +373,8 @@ def format_metric_data(self, var_bind, index=0):
metric_data["metric_type"] = val_type
if custom_translated_oid:
metric_data["custom_metric_name"] = custom_translated_oid
if parsed_index:
metric_data["parsed_index"] = parsed_index
logger.debug(f"metric_data: {json.dumps(metric_data)}")
return metric_data

Expand Down
5 changes: 1 addition & 4 deletions tests/local-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,4 @@ mongo:
collection: "oids"
mib:
database: "files"
collection: "mib_files"
profile:
database: "profiles"
collection: "profiles"
collection: "mib_files"

0 comments on commit 6eeeaea

Please sign in to comment.