Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added exception handling to stomp.py #261

Merged
merged 2 commits into from
Jun 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'}