@@ -65,16 +65,32 @@ def translator():
65
65
# when 'return_multimetric' variable is set up as 'True', mib server should return both metric and
66
66
# non-metric representation of the result
67
67
if return_multimetric == "True" :
68
- result_dict = self ._translator .format_metric_data (var_binds [0 ])
69
- result_string = self ._translator .format_trap_event (var_binds )
70
- result = {'metric_name' : result_dict ['metric_name' ], 'metric' : json .dumps (result_dict ),
71
- 'non_metric' : result_string }
68
+ return self ._return_multimetric_data (var_binds )
72
69
else :
73
70
result = self ._translator .format_trap_event (var_binds )
74
71
return result
75
72
76
73
return app
77
74
75
+ def _return_multimetric_data (self , varbinds : list ) -> dict :
76
+ """
77
+ If field 'return_multimetric' was set to 'True', mib_server returns dictionary containing metric structure,
78
+ non-metric structure and metric name. For example:
79
+
80
+ {'metric_name': 'sc4snmp.IF-MIB.ifDescr_1',
81
+ 'metric': '{"metric_name": "sc4snmp.IF-MIB.ifDescr_1", "_value": "lo", "metric_type": "OctetString"}',
82
+ 'non_metric': 'oid-type1="ObjectIdentity" value1-type="OctetString" 1.3.6.1.2.1.2.2.1.2.1="lo"
83
+ value1="lo" IF-MIB::ifDescr.1="lo" '}
84
+
85
+ :param varbinds: list of varbinds
86
+ :return: dictionary of the above structure
87
+ """
88
+ result_dict = self ._translator .format_metric_data (varbinds [0 ])
89
+ result_string = self ._translator .format_trap_event (varbinds )
90
+ result = {'metric_name' : result_dict ['metric_name' ], 'metric' : json .dumps (result_dict ),
91
+ 'non_metric' : result_string }
92
+ return result
93
+
78
94
def run_mib_server (self ):
79
95
# poetry run fails when debug=True
80
96
self ._flask_app .run (host = "0.0.0.0" , port = self ._args .port )
0 commit comments