Skip to content

Commit

Permalink
add exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Lex authored and lx183 committed Aug 28, 2024
1 parent 6b69aee commit add7565
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions nagios_checks/check_disk_wbem
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ def convert_size(size, unit=None):
s = round(size/p,2)
return (str(s), size_name[i])

if __name__ == '__main__':

parser = argparse.ArgumentParser(description='WMI memory usage checker')
def check_disk():
parser = argparse.ArgumentParser(description='WMI disk usage checker')
parser.add_argument('-H', '--host', help="Hostname to check", type=str, required=True)
parser.add_argument('-W', '--warning', help="Warning level (default: 2GB)", type=SizeString, default="2GB")
parser.add_argument('-C', '--critical', help="Critical level (default: 500MB)", type=SizeString, default="500MB")
Expand Down Expand Up @@ -145,12 +144,19 @@ if __name__ == '__main__':

sort_results = sorted(results)


if len(sort_results) > 1:
perfs=map(lambda x: x.perf_out, sort_results)
msgs=map(lambda x: x.msg_out, sort_results)
print("%s | %s\n%s" % (next(msgs), " ".join(element for element in perfs), "\n".join(element for element in msgs)))
else:
print("%s | %s" % (next(sort_results).msg_out, next(sort_results).perf_out))
print("%s | %s" % (sort_results[0].msg_out, sort_results[0].perf_out))

sys.exit(ret_status)

if __name__ == '__main__':
try:
check_disk()
except Exception as ex:
print("UNKNOWN: An unknown error occured. %s" % ex)
print(traceback.format_exc())
sys.exit(3)

0 comments on commit add7565

Please sign in to comment.