@@ -196,22 +196,7 @@ def prepare(self, work):
196
196
"index" : SPLUNK_HEC_INDEX_METRICS ,
197
197
"fields" : {},
198
198
}
199
- if "frequency" in work :
200
- metric ["fields" ]["frequency" ] = work ["frequency" ]
201
- if "profiles" in data :
202
- metric ["fields" ]["profiles" ] = data ["profiles" ]
203
- if work .get ("group" ):
204
- metric ["fields" ]["group" ] = work .get ("group" )
205
- for field , values in data ["fields" ].items ():
206
- short_field = field .split ("." )[- 1 ]
207
- metric ["fields" ][short_field ] = value_as_best (values ["value" ])
208
- for field , values in data ["metrics" ].items ():
209
- metric ["fields" ][f"metric_name:sc4snmp.{ field } " ] = value_as_best (
210
- values ["value" ]
211
- )
212
- if METRICS_INDEXING_ENABLED and "indexes" in data :
213
- indexes_to_string = [str (index ) for index in data ["indexes" ]]
214
- metric ["fields" ]["mibIndex" ] = "." .join (indexes_to_string )
199
+ set_metrics_fields (data , metric , work )
215
200
metrics .append (json .dumps (metric , indent = None ))
216
201
else :
217
202
event = {
@@ -227,6 +212,25 @@ def prepare(self, work):
227
212
return {"metrics" : metrics , "events" : events }
228
213
229
214
215
+ def set_metrics_fields (data , metric , work ):
216
+ if "frequency" in work :
217
+ metric ["fields" ]["frequency" ] = work ["frequency" ]
218
+ if "profiles" in data :
219
+ metric ["fields" ]["profiles" ] = data ["profiles" ]
220
+ if work .get ("group" ):
221
+ metric ["fields" ]["group" ] = work .get ("group" )
222
+ for field , values in data ["fields" ].items ():
223
+ short_field = field .split ("." )[- 1 ]
224
+ metric ["fields" ][short_field ] = value_as_best (values ["value" ])
225
+ for field , values in data ["metrics" ].items ():
226
+ metric ["fields" ][f"metric_name:sc4snmp.{ field } " ] = value_as_best (
227
+ values ["value" ]
228
+ )
229
+ if METRICS_INDEXING_ENABLED and "indexes" in data :
230
+ indexes_to_string = [str (index ) for index in data ["indexes" ]]
231
+ metric ["fields" ]["mibIndex" ] = "." .join (indexes_to_string )
232
+
233
+
230
234
def prepare_trap_data (work ):
231
235
events = []
232
236
for key , data in work ["result" ].items ():
0 commit comments