191191with open (args_Config , 'r' ) as config_file :
192192 Config = json .load (config_file , object_pairs_hook = OrderedDict )
193193
194- StatusOK = ('ok' , 'true' , 'yes' , 'on' , 'online' , 'spunup' , 'full' , 'ready' , 'enabled' , 'presence' , 'non-raid' , 'nonraid' , '0' )
195- StatusWarning = ('noncritical' , 'removed' , 'foreign' , 'offline' )
194+ StatusOK = ('ok' , 'true' , 'yes' , 'on' , 'online' , 'spunup' , 'full' , 'ready' , 'enabled' , 'presence' , 'non-raid' , 'nonraid' , '0' , 'notapplicable' )
195+ StatusWarning = ('noncritical' , 'removed' , 'foreign' , 'offline' , 'rebuild' )
196196StatusCritical = ('fail' , 'failed' , 'critical' , 'nonrecoverable' , 'notredundant' , 'lost' , 'degraded' , 'redundancyoffline' )
197197StatusMap = {
198198 0 : {'status' : 'OK' , 'color' : '\033 [32m{}\033 [00m' , 'severity' : 0 }, # green
@@ -279,14 +279,17 @@ def status_formatter(status: int, alt_text: str = None, with_color: bool = True)
279279 return result
280280
281281
282- def get_row_output (col_val_raw : str , col_type : str ) -> str :
282+ def get_row_output (col_val_raw : str , col_type : str , col_prefix : str = None , col_suffix : str = None ) -> str :
283+ if col_prefix is None : col_prefix = ''
284+ if col_suffix is None : col_suffix = ''
283285 if col_type == 'status' :
284286 col_val = status_converter (col_val_raw )
285287 global category_code
286288 category_code = update_status_code (category_code , col_val )
287- return status_formatter (col_val , StatusMap [col_val ]['status' ] + ' (' + col_val_raw + ')' , args_MoreFormat )
289+ result = status_formatter (col_val , StatusMap [col_val ]['status' ] + ' (' + col_val_raw + ')' , args_MoreFormat )
288290 else :
289- return col_val_raw
291+ result = col_val_raw
292+ return col_prefix + result + col_suffix
290293
291294
292295# execution
@@ -303,10 +306,13 @@ def get_row_output(col_val_raw: str, col_type: str) -> str:
303306 print_and_exit ('Unknown vendor information.' , 3 )
304307
305308
309+ global_list_bullet = Config ['config' ]['global-list-bullet' ]
310+ global_oid_separator = Config ['config' ]['global-oid-separator' ]
306311exitCode , exitCodeImp = - 1 , - 1
307312vendor = Config [Vendor ]
308313mib_dir = vendor ['mib_dir' ]
309314mib = vendor ['mib' ]
315+
310316for category_key in vendor ['categories' ]:
311317 # only show specified categories when applicable
312318 if len (args_Category ) > 0 and category_key not in args_Category : continue
@@ -315,6 +321,11 @@ def get_row_output(col_val_raw: str, col_type: str) -> str:
315321 description = category ['description' ]
316322 imp = category .get ('important' ) is True
317323
324+ list_bullet = category .get ('list-bullet' )
325+ if list_bullet is None : list_bullet = global_list_bullet
326+ oid_separator = category .get ('oid-separator' )
327+ if oid_separator is None : oid_separator = global_oid_separator
328+
318329 oids = category ['oids' ]
319330 if len (oids ) == 0 : continue
320331
@@ -325,20 +336,29 @@ def get_row_output(col_val_raw: str, col_type: str) -> str:
325336 for oid in oids :
326337 oid_result_raw = run (SnmpCommand ('snmpwalk' , args_Host , oid ['oid' ], mib_dir , mib , True ))
327338 if len (oid_result_raw .stderr ) > 0 : print_and_exit (oid_result_raw .stderr , 3 )
328- category_result_raw .append ([(l .strip ('" \n ' ), oid ['type' ]) for l in oid_result_raw .stdout .splitlines ()])
339+ category_result_raw .append ([(l .strip ('" \n ' ),
340+ oid ['type' ],
341+ oid .get ('prefix' ),
342+ oid .get ('suffix' )) for l in oid_result_raw .stdout .splitlines ()])
329343 category_result_raw = [i for i in zip (* category_result_raw )] # swap axis
330344
331345 if len (category_result_raw ) == 1 and len (category_result_raw [0 ]) == 1 : # there is only one status item without anything else
332346 col = category_result_raw [0 ][0 ]
333- category_output = category_output .format (combined_status = get_row_output (col [0 ], col [1 ]))
347+ category_output = category_output .format (combined_status = get_row_output (col [0 ],
348+ col [1 ],
349+ col [2 ],
350+ col [3 ]))
334351
335352 else :
336353 for row in category_result_raw : # row is like (('DIMM.Socket.A1', 'text'), ('failed', 'status'))
337354 cols = []
338355 for col in row : # col is like ('DIMM.Socket.A1', 'text')
339- cols .append (get_row_output (col [0 ], col [1 ]))
356+ cols .append (get_row_output (col [0 ],
357+ col [1 ],
358+ col [2 ],
359+ col [3 ]))
340360
341- category_output += ' - ' + ', ' .join (cols ) + '\n '
361+ category_output += list_bullet + oid_separator .join (cols ) + '\n '
342362 category_output = category_output .format (combined_status = status_formatter (category_code , with_color = args_MoreFormat ))
343363
344364 print (category_output )
0 commit comments