[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [tor-bugs] #13008 [Tor Sysadmin Team]: Create a Nagios check to ensure that Onionoo is updating correctly
#13008: Create a Nagios check to ensure that Onionoo is updating correctly
-----------------------------------+--------------------
Reporter: karsten | Owner:
Type: enhancement | Status: closed
Priority: normal | Milestone:
Component: Tor Sysadmin Team | Version:
Resolution: fixed | Keywords:
Actual Points: | Parent ID:
Points: |
-----------------------------------+--------------------
Comment (by atagar):
Hi Karsten, your script looks real nice!
weasel: karsten emailed a handful of us a few minutes ago asking for
feedback
-----
{{{
# Standard Nagios return codes
OK = 0
WARNING = 1
CRITICAL = 2
UNKNOWN = 3
}}}
This could also be...
{{{
# Standard Nagios return codes
OK, WARNING, CRITICAL, UNKNOWN = range(4)
}}}
-----
{{{
def end(status, message):
"""Exit the plugin with first arg as the return code and second arg as
the message to output."""
if status == OK:
print "ONIONOO OK: %s" % message
sys.exit(OK)
elif status == WARNING:
print "ONIONOO WARNING: %s" % message
sys.exit(WARNING)
elif status == CRITICAL:
print "ONIONOO CRITICAL: %s" % message
sys.exit(CRITICAL)
else:
print "ONIONOO UNKNOWN: %s" % message
sys.exit(UNKNOWN)
}}}
Minor nitpick but the sys.exit() calls are redundant...
{{{
def end(status, message):
"""Exit the plugin with first arg as the return code and second arg as
the message to output."""
if status == OK:
print "ONIONOO OK: %s" % message
elif status == WARNING:
print "ONIONOO WARNING: %s" % message
elif status == CRITICAL:
print "ONIONOO CRITICAL: %s" % message
else:
print "ONIONOO UNKNOWN: %s" % message
status = UNKNOWN
sys.exit(status)
}}}
-----
{{{
def main():
"""Call function to check whether Onionoo service is working."""
result, message = test_onionoo()
end(result, message)
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
end(CRITICAL, "Caught Control-C...")
}}}
This and end() are brief enough that personally I'd just combine it all.
{{{
if __name__ == "__main__":
result, message = None, None
try:
result, message = test_onionoo()
except KeyboardInterrupt:
result, message = CRITICAL, "Caught Control-C..."
finally:
if status == OK:
print "ONIONOO OK: %s" % message
elif status == WARNING:
print "ONIONOO WARNING: %s" % message
elif status == CRITICAL:
print "ONIONOO CRITICAL: %s" % message
else:
print "ONIONOO UNKNOWN: %s" % message
status = UNKNOWN
sys.exit(status)
}}}
--
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/13008#comment:4>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online
_______________________________________________
tor-bugs mailing list
tor-bugs@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-bugs