diff --git a/elastalert/elastalert.py b/elastalert/elastalert.py index a933eff0f..2cb3ffc27 100755 --- a/elastalert/elastalert.py +++ b/elastalert/elastalert.py @@ -6,6 +6,7 @@ import logging import os import signal +import socket import sys import time import timeit @@ -48,6 +49,9 @@ from util import ts_now from util import ts_to_dt from util import unix_to_dt +from raven import Client +from raven.conf import setup_logging +from raven.handlers.logging import SentryHandler class ElastAlerter(): @@ -127,6 +131,16 @@ def __init__(self, args): tracer.setLevel(logging.INFO) tracer.addHandler(logging.FileHandler(self.args.es_debug_trace)) + if os.environ.get('SENTRY_DSN') is not None: + sentry = Client( + dsn=os.getenv('SENTRY_DSN'), + name=os.environ.get('HOST', socket.getfqdn()) + ) + handler = SentryHandler(sentry) + handler.setLevel(logging.WARNING) + setup_logging(handler) + elastalert_logger.info("Configured errors reporting to Sentry: %s" % os.getenv('SENTRY_DSN')) + self.conf = load_rules(self.args) self.max_query_size = self.conf['max_query_size'] self.scroll_keepalive = self.conf['scroll_keepalive'] diff --git a/requirements-dev.txt b/requirements-dev.txt index 36daa0ebd..b2c720857 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -6,3 +6,4 @@ pytest<3.3.0 setuptools sphinx_rtd_theme tox<2.0 +raven>=6.4.0 diff --git a/requirements.txt b/requirements.txt index 47676fc9b..edebfb7e9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,6 +13,7 @@ PyStaticConfiguration>=0.10.3 python-dateutil>=2.6.0,<2.7.0 PyYAML>=3.12 requests>=2.0.0 +raven>=6.4.0 stomp.py>=4.1.17 texttable>=0.8.8 twilio==6.0.0