Skip to content

Commit

Permalink
Merge pull request #261 from nsano-rururu/fix_stomp
Browse files Browse the repository at this point in the history
Added exception handling to stomp.py
  • Loading branch information
jertel authored Jun 11, 2021
2 parents f3cbfc3 + b81e9bb commit 683fccb
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions elastalert/alerters/stomp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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'}

0 comments on commit 683fccb

Please sign in to comment.