check_nginx: remove perfdata if no levels

This commit is contained in:
Cyberes 2023-05-29 12:05:07 -06:00
parent e33aeb0eb0
commit 8156a95e05
1 changed files with 11 additions and 8 deletions

View File

@ -44,7 +44,7 @@ def parse_nginx_status(status):
def main(): def main():
parser = argparse.ArgumentParser(description="Check Nginx status using stub_status.") parser = argparse.ArgumentParser(description="Check Nginx status using stub_status.")
parser.add_argument("--url", default="http://localhost/nginx_status", help="URL to Nginx stub_status.") parser.add_argument("--url", required=True, help="URL to Nginx stub_status.")
parser.add_argument("--critical-active", type=int, default=0, help="Critical threshold for active connections. Default: disabled") parser.add_argument("--critical-active", type=int, default=0, help="Critical threshold for active connections. Default: disabled")
parser.add_argument("--warning-active", type=int, default=0, help="Warning threshold for active connections. Default: disabled") parser.add_argument("--warning-active", type=int, default=0, help="Warning threshold for active connections. Default: disabled")
parser.add_argument("--critical-waiting", type=int, default=0, help="Critical threshold for waiting connections. Default: disabled") parser.add_argument("--critical-waiting", type=int, default=0, help="Critical threshold for waiting connections. Default: disabled")
@ -54,16 +54,16 @@ def main():
status = check_nginx_status(args.url) status = check_nginx_status(args.url)
data = parse_nginx_status(status) data = parse_nginx_status(status)
perfdata = "| active_connections={active_connections};{warning};{critical} waiting={waiting};{warning_waiting};{critical_waiting} accepted={accepted} handled={handled} requests={requests} reading={reading} writing={writing}".format(
warning=args.warning_active,
critical=args.critical_active,
warning_waiting=args.warning_waiting,
critical_waiting=args.critical_waiting,
**data
)
status_str = "Active connections: {active_connections}, Waiting: {waiting}, Accepted: {accepted}, Handled: {handled}, Requests: {requests}, Reading: {reading}, Writing: {writing}".format(**data) status_str = "Active connections: {active_connections}, Waiting: {waiting}, Accepted: {accepted}, Handled: {handled}, Requests: {requests}, Reading: {reading}, Writing: {writing}".format(**data)
if args.warning_active > 0 and args.critical_active > 0 and args.warning_waiting > 0 and args.critical_waiting > 0: if args.warning_active > 0 and args.critical_active > 0 and args.warning_waiting > 0 and args.critical_waiting > 0:
perfdata = "| active_connections={active_connections};{warning};{critical} waiting={waiting};{warning_waiting};{critical_waiting} accepted={accepted} handled={handled} requests={requests} reading={reading} writing={writing}".format(
warning=args.warning_active,
critical=args.critical_active,
warning_waiting=args.warning_waiting,
critical_waiting=args.critical_waiting,
**data
)
if data["active_connections"] >= args.critical_active or data["waiting"] >= args.critical_waiting: if data["active_connections"] >= args.critical_active or data["waiting"] >= args.critical_waiting:
print("CRITICAL:", status_str, perfdata) print("CRITICAL:", status_str, perfdata)
sys.exit(nagios.CRITICAL) sys.exit(nagios.CRITICAL)
@ -74,6 +74,9 @@ def main():
print("OK:", status_str) print("OK:", status_str)
sys.exit(nagios.OK) sys.exit(nagios.OK)
else: else:
perfdata = "| active_connections={active_connections} waiting={waiting} accepted={accepted} handled={handled} requests={requests} reading={reading} writing={writing}".format(
**data
)
print("OK:", status_str) print("OK:", status_str)
print('Critical and warning levels disabled.', perfdata) print('Critical and warning levels disabled.', perfdata)
sys.exit(nagios.OK) sys.exit(nagios.OK)