mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 20:44:04 +00:00
nagios: Clean up check_send_receive_time arguments.
This commit is contained in:
@@ -93,7 +93,7 @@ states = {
|
||||
"UNKNOWN": 3
|
||||
}
|
||||
|
||||
def report(state, timestamp, msg=None):
|
||||
def report(state, timestamp=None, msg=None):
|
||||
# type: (str, Any, Optional[str]) -> None
|
||||
now = int(time.time())
|
||||
if msg is None:
|
||||
@@ -112,20 +112,20 @@ def send_zulip(sender, message):
|
||||
# type: (zulip.Client, Dict[str, Any]) -> None
|
||||
result = sender.send_message(message)
|
||||
if result["result"] != "success" and options.nagios:
|
||||
report("CRITICAL", "Error sending Zulip, args were: %s, %s" % (message, result))
|
||||
report("CRITICAL", msg="Error sending Zulip, args were: %s, %s" % (message, result))
|
||||
|
||||
def get_zulips():
|
||||
# type: () -> List[Dict[str, Any]]
|
||||
global queue_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'):
|
||||
report("CRITICAL", "Error receiving Zulips, error was: %s" % (res["msg"]))
|
||||
report("CRITICAL", msg="Error receiving Zulips, error was: %s" % (res["msg"]))
|
||||
for event in res['events']:
|
||||
last_event_id = max(last_event_id, int(event['id']))
|
||||
# If we get a heartbeat event, that means we've been hanging for
|
||||
# 40s, and we should bail.
|
||||
if 'heartbeat' in set(event['type'] for event in res['events']):
|
||||
report("CRITICAL", "Got heartbeat waiting for Zulip, which means get_events is hanging")
|
||||
report("CRITICAL", msg="Got heartbeat waiting for Zulip, which means get_events is hanging")
|
||||
return [event['message'] for event in res['events']]
|
||||
|
||||
def send_message_via_websocket(websocket_client, recepient_email, content):
|
||||
@@ -159,10 +159,10 @@ zulip_recipient = zulip.Client(
|
||||
try:
|
||||
res = zulip_recipient.register(event_types=["message"])
|
||||
if 'error' in res.get('result'):
|
||||
report("CRITICAL", "Error subscribing to Zulips: %s" % (res['msg']))
|
||||
report("CRITICAL", msg="Error subscribing to Zulips: %s" % (res['msg']))
|
||||
queue_id, last_event_id = (res['queue_id'], res['last_event_id'])
|
||||
except Exception:
|
||||
report("CRITICAL", "Error subscribing to Zulips:\n%s" % (traceback.format_exc()))
|
||||
report("CRITICAL", msg="Error subscribing to Zulips:\n%s" % (traceback.format_exc()))
|
||||
msg_to_send = str(random.getrandbits(64))
|
||||
time_start = time.time()
|
||||
|
||||
@@ -192,11 +192,11 @@ zulip_recipient.deregister(queue_id)
|
||||
|
||||
if options.nagios:
|
||||
if seconds_diff > 12:
|
||||
report('CRITICAL', seconds_diff)
|
||||
report('CRITICAL', timestamp=seconds_diff)
|
||||
if seconds_diff > 3:
|
||||
report('WARNING', seconds_diff)
|
||||
report('WARNING', timestamp=seconds_diff)
|
||||
|
||||
if options.munin:
|
||||
print("sendreceive.value %s" % (seconds_diff,))
|
||||
elif options.nagios:
|
||||
report('OK', seconds_diff)
|
||||
report('OK', timestamp=seconds_diff)
|
||||
|
||||
Reference in New Issue
Block a user