From 9f3766dd4a9c5698aae05acdf302632122c149bf Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Tue, 8 Oct 2013 14:09:31 -0400 Subject: [PATCH] Use events API in our Nagios monitoring scripts (imported from commit 9b370e420095f17fbb7e9d1e466d51dd2e145de1) --- bots/check-mirroring | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/bots/check-mirroring b/bots/check-mirroring index 926f230..6e94b80 100755 --- a/bots/check-mirroring +++ b/bots/check-mirroring @@ -129,12 +129,12 @@ def send_zephyr(zwrite_args, content): # Subscribe to Zulip try: - res = zulip_client.get_profile() - max_message_id = res.get('max_message_id') - if max_message_id is None: + res = zulip_client.register(event_types=["message"]) + if 'error' in res.get('result'): logging.error("Error subscribing to Zulips!") - logging.error(res) + logging.error(res['msg']) print_status_and_exit(1) + queue_id, last_event_id = (res['queue_id'], res['last_event_id']) except Exception: logger.exception("Unexpected error subscribing to Zulips") print_status_and_exit(1) @@ -265,7 +265,12 @@ receive_zephyrs() logger.info("Starting receiving messages!") # receive zulips -messages = zulip_client.get_messages({'last': str(max_message_id)})['messages'] +res = zulip_client.get_events(queue_id=queue_id, last_event_id=last_event_id) +if 'error' in res.get('result'): + logging.error("Error subscribing to Zulips!") + logging.error(res['msg']) + print_status_and_exit(1) +messages = [event['message'] for event in res['events']] logger.info("Finished receiving Zulip messages!") receive_zephyrs()