From f853570091157b5c66b15c87e48bae1077bf7944 Mon Sep 17 00:00:00 2001 From: nsano-rururu Date: Fri, 11 Jun 2021 23:32:28 +0900 Subject: [PATCH] Added exception handling to stomp.py --- elastalert/alerters/stomp.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/elastalert/alerters/stomp.py b/elastalert/alerters/stomp.py index 65e0d310..ee0360fd 100644 --- a/elastalert/alerters/stomp.py +++ b/elastalert/alerters/stomp.py @@ -5,7 +5,7 @@ import stomp from elastalert.alerts import Alerter, BasicMatchString -from elastalert.util import lookup_es_key, elastalert_logger +from elastalert.util import lookup_es_key, elastalert_logger, EAException class StompAlerter(Alerter): @@ -63,13 +63,17 @@ def alert(self, matches): 'stomp_destination', '/queue/ALERT') self.stomp_ssl = self.rule.get('stomp_ssl', False) - conn = stomp.Connection([(self.stomp_hostname, self.stomp_hostport)], use_ssl=self.stomp_ssl) + try: + conn = stomp.Connection([(self.stomp_hostname, self.stomp_hostport)], use_ssl=self.stomp_ssl) - conn.connect(self.stomp_login, self.stomp_password) - # Ensures that the CONNECTED frame is received otherwise, the disconnect call will fail. - time.sleep(1) - conn.send(self.stomp_destination, json.dumps(fullmessage)) - conn.disconnect() + conn.connect(self.stomp_login, self.stomp_password) + # Ensures that the CONNECTED frame is received otherwise, the disconnect call will fail. + time.sleep(1) + conn.send(self.stomp_destination, json.dumps(fullmessage)) + conn.disconnect() + except Exception as e: + raise EAException("Error posting to Stomp: %s" % e) + elastalert_logger.info("Alert sent to Stomp") def get_info(self): return {'type': 'stomp'}