|
13 | 13 | _parser.add_argument('-c', '--community', help='The community string to use.', default='public') |
14 | 14 | _parser.add_argument('-r', '--respect', help='Respect properties marked as important when other results contain errors.', action='store_true') |
15 | 15 | _parser.add_argument('-f', '--format', help='Include additional format like colors in the output.', action='store_true') |
16 | | -_parser.add_argument('-b', '--brief', help='Output brief information (only combined status etc.).', action='store_true') |
| 16 | +_parser.add_argument('-b', '--brief', help='Output brief information (only description and combined status).', action='store_true') |
17 | 17 | _parser.add_argument('host', help='The host to connect to.') |
18 | 18 | _parser.add_argument('--config', nargs='?', help='The configuration file to load.', default='config_default.json') |
19 | 19 | _parser.add_argument('category', nargs='*', help='One or more of the categories from the configuration separated by spaces.') |
|
34 | 34 | with open(args_Config, 'r') as config_file: |
35 | 35 | Config = json.load(config_file, object_pairs_hook=OrderedDict) |
36 | 36 |
|
| 37 | +# status strings need to be all lower case |
37 | 38 | StatusOK = ('ok', 'true', 'yes', 'on', 'online', 'spunup', 'full', 'ready', 'enabled', 'presence', 'non-raid', 'nonraid', '0', 'notapplicable') |
38 | 39 | StatusWarning = ('noncritical', 'removed', 'foreign', 'offline', 'rebuild') |
39 | 40 | StatusCritical = ('fail', 'failed', 'critical', 'nonrecoverable', 'notredundant', 'lost', 'degraded', 'redundancyoffline') |
| 41 | + |
40 | 42 | StatusMap = { |
41 | 43 | 0: {'status': 'OK', 'color': '\033[32m{}\033[00m', 'severity': 0}, # green |
42 | 44 | 1: {'status': 'WARNING', 'color': '\033[33m{}\033[00m', 'severity': 2}, # orange |
@@ -185,33 +187,29 @@ def get_row_output(col_val_raw: str, col_type: str, col_prefix: str = None, col_ |
185 | 187 | oid.get('suffix')) for l in oid_result_raw.stdout.splitlines()]) |
186 | 188 | category_result_raw = [i for i in zip(*category_result_raw)] # swap axis |
187 | 189 |
|
| 190 | + # generate output |
188 | 191 | if len(category_result_raw) == 1 and len(category_result_raw[0]) == 1: # there is only one status item without anything else |
189 | 192 | col = category_result_raw[0][0] |
190 | | - row_output = get_row_output(col[0], |
191 | | - col[1], |
192 | | - col[2], |
193 | | - col[3]) |
| 193 | + row_output = get_row_output(col[0], col[1], col[2], col[3]) |
194 | 194 | if not args_Brief: |
195 | | - category_output = category_output.format(combined_status=row_output) |
| 195 | + combined_status = row_output |
196 | 196 | else: |
197 | | - category_output = category_output.format(combined_status=status_formatter(category_code, with_color=args_MoreFormat)) |
198 | | - |
| 197 | + combined_status = status_formatter(category_code, with_color=args_MoreFormat) |
| 198 | + category_output = category_output.format(combined_status=combined_status) |
199 | 199 | else: |
200 | 200 | for row in category_result_raw: # row is like (('DIMM.Socket.A1', 'text'), ('failed', 'status')) |
201 | 201 | cols = [] |
202 | 202 | for col in row: # col is like ('DIMM.Socket.A1', 'text') |
203 | | - cols.append(get_row_output(col[0], |
204 | | - col[1], |
205 | | - col[2], |
206 | | - col[3])) |
| 203 | + cols.append(get_row_output(col[0], col[1], col[2], col[3])) |
207 | 204 |
|
208 | 205 | if not args_Brief: |
209 | 206 | category_output += list_bullet + oid_separator.join(cols) + '\n' |
210 | | - |
211 | 207 | category_output = category_output.format(combined_status=status_formatter(category_code, with_color=args_MoreFormat)) |
212 | | - |
| 208 | + |
| 209 | + # write output |
213 | 210 | sys.stdout.write(category_output if args_Brief else category_output + '\n') |
214 | 211 |
|
| 212 | + # set exit code |
215 | 213 | if imp: exitCodeImp = update_status_code(exitCodeImp, category_code) |
216 | 214 | exitCode = update_status_code(exitCode, category_code) |
217 | 215 |
|
|
0 commit comments