check_nginx: remove perfdata if no levels
This commit is contained in:
parent
e33aeb0eb0
commit
8156a95e05
|
@ -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,6 +54,9 @@ def main():
|
||||||
status = check_nginx_status(args.url)
|
status = check_nginx_status(args.url)
|
||||||
data = parse_nginx_status(status)
|
data = parse_nginx_status(status)
|
||||||
|
|
||||||
|
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:
|
||||||
perfdata = "| active_connections={active_connections};{warning};{critical} waiting={waiting};{warning_waiting};{critical_waiting} accepted={accepted} handled={handled} requests={requests} reading={reading} writing={writing}".format(
|
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,
|
warning=args.warning_active,
|
||||||
critical=args.critical_active,
|
critical=args.critical_active,
|
||||||
|
@ -61,9 +64,6 @@ def main():
|
||||||
critical_waiting=args.critical_waiting,
|
critical_waiting=args.critical_waiting,
|
||||||
**data
|
**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 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)
|
||||||
|
|
Loading…
Reference in New Issue