scrutiny: add html

This commit is contained in:
Cyberes 2023-05-28 14:49:34 -06:00
parent 0ae80b939f
commit 60f4329009
1 changed files with 41 additions and 7 deletions

View File

@ -89,23 +89,49 @@ def main(args):
'display_name': item['metadata']['display_name'] 'display_name': item['metadata']['display_name']
}) })
dt = '<dt>' if args.html else ''
dts = '</dt>' if args.html else ''
dd = '<dd>' if args.html else '\t- '
dds = '</dd>' if args.html else ''
return_code = nagios.OK return_code = nagios.OK
if len(crit_disks): if len(crit_disks):
return_code = nagios.CRITICAL return_code = nagios.CRITICAL
print(f'CRITICAL: {len(crit_disks)} {"error" if len(results) == 0 else "errors"} - {args.scrutiny_endpoint}') if len(warn_disks):
print('Disks with Errors:') x = f' and {len(warn_disks)} {"warning" if len(results) > 1 else "warnings"}'
else:
x = ''
print(f'CRITICAL: {len(crit_disks)} {"error" if len(results) > 1 else "errors"}{x}')
print('<dl>')
print(f'{dt}Disks with Errors:{dts}')
for disk, warns in crit_disks.items(): for disk, warns in crit_disks.items():
print(f'\t- /dev/{disk}: {", ".join([x["display_name"] for x in warns])}') if args.html:
disk_name = f'- <a href="{args.pretty_url}/web/device/{results[disk]["wwn_id"]}">/dev/{disk}</a>'
else:
disk_name = f'\t- /dev/{disk}'
print(f'{dd}{disk_name}: {", ".join([x["display_name"] for x in warns])}{dds}')
print('</dl>', end='')
if len(warn_disks): if len(warn_disks):
if return_code < nagios.CRITICAL: if return_code < nagios.CRITICAL:
return_code = nagios.WARNING return_code = nagios.WARNING
print(f'WARNING: {len(crit_disks)} {"warning" if len(results) == 0 else "warnings"} - {args.scrutiny_endpoint}') print(f'WARNING: {len(crit_disks)} {"warning" if len(results) > 1 else "warnings"}')
print('Disks with issues:')
print('<dl>')
print(f'{dt}Disks with issues:{dts}')
for disk, warns in warn_disks.items(): for disk, warns in warn_disks.items():
print(f'\t- /dev/{disk}: {", ".join([x["display_name"] for x in warns])}') if args.html:
disk_name = f'- <a href="{args.pretty_url}/web/device/{results[disk]["wwn_id"]}">/dev/{disk}</a>'
else:
disk_name = f'\t- /dev/{disk}'
print(f'{dd}{disk_name}: {", ".join([x["display_name"] for x in warns])}{dds}')
print('</dl>', end='')
if not len(crit_disks) and not len(warn_disks): if not len(crit_disks) and not len(warn_disks):
print(f'OK: all {len(results)} {"disk" if len(results) == 0 else "disks"} are healthy!', end='') print(f'OK: all {len(results)} {"disk" if len(results) > 1 else "disks"} are healthy!', end='')
print(f"|'warnings'={len(warn_disks)};;; 'errors'={len(crit_disks)};;; 'num_disks'={len(results)};;;") print(f"|'warnings'={len(warn_disks)};;; 'errors'={len(crit_disks)};;; 'num_disks'={len(results)};;;")
sys.exit(return_code) sys.exit(return_code)
@ -115,8 +141,16 @@ if __name__ == "__main__":
parser = argparse.ArgumentParser(description='') parser = argparse.ArgumentParser(description='')
parser.add_argument('--scrutiny-endpoint', required=True, help='Base URL for scrutiny.') parser.add_argument('--scrutiny-endpoint', required=True, help='Base URL for scrutiny.')
parser.add_argument('--warn-non-critical', action='store_true', help='Warn when a non-critical metric is marked as failed.') parser.add_argument('--warn-non-critical', action='store_true', help='Warn when a non-critical metric is marked as failed.')
parser.add_argument('--html', action='store_true', help='Print HTML.')
parser.add_argument('--pretty-url', help='The pretty URL to link to when printing HTML.')
args = parser.parse_args() args = parser.parse_args()
if args.html and not args.pretty_url:
print('UKNOWN: when using --html you must also set --pretty-url')
sys.exit(nagios.UNKNOWN)
args.scrutiny_endpoint = args.scrutiny_endpoint.strip('/') args.scrutiny_endpoint = args.scrutiny_endpoint.strip('/')
args.pretty_url = args.pretty_url.strip('/') if args.pretty_url else None
try: try:
main(args) main(args)
except Exception as e: except Exception as e: