3434with open (args_Config , 'r' ) as config_file :
3535 Config = json .load (config_file , object_pairs_hook = OrderedDict )
3636
37- # status strings need to be all lower case
38- StatusOK = ('ok' , 'true' , 'yes' , 'on' , 'online' , 'spunup' , 'full' , 'ready' , 'enabled' , 'presence' , 'non-raid' , 'nonraid' , '0' , 'notapplicable' )
39- StatusWarning = ('noncritical' , 'removed' , 'foreign' , 'offline' , 'rebuild' )
40- StatusCritical = ('fail' , 'failed' , 'critical' , 'nonrecoverable' , 'notredundant' , 'lost' , 'degraded' , 'redundancyoffline' )
37+ CustomMappings = Config ['config' ].get ('custom-mappings' ) # type: OrderedDict[str, OrderedDict]
38+
39+ StatusOK = Config ['config' ]['status-ok' ]
40+ StatusWarning = Config ['config' ]['status-warning' ]
41+ StatusCritical = Config ['config' ]['status-critical' ]
4142
4243StatusMap = {
4344 0 : {'status' : 'OK' , 'color' : '\033 [32m{}\033 [00m' , 'severity' : 0 }, # green
@@ -124,11 +125,20 @@ def status_formatter(status: int, alt_text: str = None, with_color: bool = True)
124125 return result
125126
126127
127- def get_row_output (col_val_raw : str , col_type : str , col_prefix : str = None , col_suffix : str = None ) -> str :
128+ def get_row_output (col_val_raw : str ,
129+ col_type : str ,
130+ col_prefix : str = None ,
131+ col_suffix : str = None ,
132+ col_mapping : str = None ) -> str :
128133 if col_prefix is None : col_prefix = ''
129134 if col_suffix is None : col_suffix = ''
130- if col_type == 'status' :
131- col_val = status_converter (col_val_raw )
135+ if col_type == 'custom' and col_mapping is None : col_type = 'text'
136+
137+ if col_type in ('status' , 'custom' ):
138+ if col_type == 'status' :
139+ col_val = status_converter (col_val_raw )
140+ else : # convert to status based on custom mapping
141+ col_val = status_converter (CustomMappings [col_mapping ][col_val_raw ])
132142 global category_code
133143 category_code = update_status_code (category_code , col_val )
134144 result = status_formatter (col_val , StatusMap [col_val ]['status' ] + ' (' + col_val_raw + ')' , args_MoreFormat )
@@ -184,13 +194,14 @@ def get_row_output(col_val_raw: str, col_type: str, col_prefix: str = None, col_
184194 category_result_raw .append ([(l .strip ('" \n ' ),
185195 oid ['type' ],
186196 oid .get ('prefix' ),
187- oid .get ('suffix' )) for l in oid_result_raw .stdout .splitlines ()])
197+ oid .get ('suffix' ),
198+ oid .get ('mapping' )) for l in oid_result_raw .stdout .splitlines ()])
188199 category_result_raw = [i for i in zip (* category_result_raw )] # swap axis
189200
190201 # generate output
191202 if len (category_result_raw ) == 1 and len (category_result_raw [0 ]) == 1 : # there is only one status item without anything else
192203 col = category_result_raw [0 ][0 ]
193- row_output = get_row_output (col [0 ], col [1 ], col [2 ], col [3 ])
204+ row_output = get_row_output (col [0 ], col [1 ], col [2 ], col [3 ], col [ 4 ] )
194205 if not args_Brief :
195206 combined_status = row_output
196207 else :
@@ -200,7 +211,7 @@ def get_row_output(col_val_raw: str, col_type: str, col_prefix: str = None, col_
200211 for row in category_result_raw : # row is like (('DIMM.Socket.A1', 'text'), ('failed', 'status'))
201212 cols = []
202213 for col in row : # col is like ('DIMM.Socket.A1', 'text')
203- cols .append (get_row_output (col [0 ], col [1 ], col [2 ], col [3 ]))
214+ cols .append (get_row_output (col [0 ], col [1 ], col [2 ], col [3 ], col [ 4 ] ))
204215
205216 if not args_Brief :
206217 category_output += list_bullet + oid_separator .join (cols ) + '\n '
0 commit comments