puppet: Annotate Nagios plugins.

This commit is contained in:
Tim Abbott 2016-10-15 22:43:21 -07:00
parent 458e455b75
commit 913d913c90
4 changed files with 11 additions and 0 deletions

View File

@ -25,7 +25,10 @@ import scripts.lib.setup_path_on_import
import django import django
from typing import Any, Dict, List, Optional
def total_seconds(timedelta): def total_seconds(timedelta):
# type: (datetime.timedelta) -> float
return (timedelta.microseconds + (timedelta.seconds + timedelta.days * 24 * 3600) * 10**6) / 10.**6 return (timedelta.microseconds + (timedelta.seconds + timedelta.days * 24 * 3600) * 10**6) / 10.**6
usage = """Usage: send-receive.py [options] [config] usage = """Usage: send-receive.py [options] [config]
@ -90,6 +93,7 @@ states = {
} }
def report(state, timestamp, msg=None): def report(state, timestamp, msg=None):
# type: (str, Any, Optional[str]) -> None
now = int(time.time()) now = int(time.time())
if msg is None: if msg is None:
msg = "send time was %s" % (timestamp,) msg = "send time was %s" % (timestamp,)
@ -101,11 +105,13 @@ def report(state, timestamp, msg=None):
exit(states[state]) exit(states[state])
def send_zulip(sender, message): def send_zulip(sender, message):
# type: (zulip.Client, Dict[str, Any]) -> None
result = sender.send_message(message) result = sender.send_message(message)
if result["result"] != "success" and options.nagios: if result["result"] != "success" and options.nagios:
report("CRITICAL", "Error sending Zulip, args were: %s, %s" % (message, result)) report("CRITICAL", "Error sending Zulip, args were: %s, %s" % (message, result))
def get_zulips(): def get_zulips():
# type: () -> List[Dict[str, Any]]
global queue_id, last_event_id global queue_id, last_event_id
res = zulip_recipient.get_events(queue_id=queue_id, last_event_id=last_event_id) res = zulip_recipient.get_events(queue_id=queue_id, last_event_id=last_event_id)
if 'error' in res.get('result'): if 'error' in res.get('result'):

View File

@ -17,10 +17,12 @@ states = {
} }
def report(state, msg): def report(state, msg):
# type: (str, str) -> None
print("%s: %s" % (state, msg)) print("%s: %s" % (state, msg))
exit(states[state]) exit(states[state])
def get_loc_over_ssh(host, func): def get_loc_over_ssh(host, func):
# type: (str, str) -> str
try: try:
return subprocess.check_output(['ssh', host, return subprocess.check_output(['ssh', host,
'psql zulip -t -c "SELECT %s()"' % (func,)], 'psql zulip -t -c "SELECT %s()"' % (func,)],
@ -30,6 +32,7 @@ def get_loc_over_ssh(host, func):
report('CRITICAL', 'ssh failed: %s: %s' % (str(e), e.output)) report('CRITICAL', 'ssh failed: %s: %s' % (str(e), e.output))
def loc_to_abs_offset(loc_str): def loc_to_abs_offset(loc_str):
# type: (str) -> int
m = re.match(r'^\s*([0-9a-fA-F]+)/([0-9a-fA-F]+)\s*$', loc_str) m = re.match(r'^\s*([0-9a-fA-F]+)/([0-9a-fA-F]+)\s*$', loc_str)
if not m: if not m:
raise ValueError("Unknown xlog location format: " + loc_str) raise ValueError("Unknown xlog location format: " + loc_str)

View File

@ -22,6 +22,7 @@ states = {
} }
def report(state, num): def report(state, num):
# type: (str, str) -> None
print("%s: %s rows in fts_update_log table" % (state, num)) print("%s: %s rows in fts_update_log table" % (state, num))
exit(states[state]) exit(states[state])

View File

@ -16,6 +16,7 @@ states = {
} }
def report(state, msg): def report(state, msg):
# type: (str, str) -> None
print("%s: %s" % (state, msg)) print("%s: %s" % (state, msg))
exit(states[state]) exit(states[state])