Skip to content

Commit

Permalink
fix, alert notification to hipchat.
Browse files Browse the repository at this point in the history
  • Loading branch information
toyama0919 committed Dec 1, 2015
1 parent 995659e commit 9c1fda4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
2 changes: 2 additions & 0 deletions redash/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import urlparse
import redis
import hipchat
from statsd import StatsClient
from flask_mail import Mail

Expand Down Expand Up @@ -36,6 +37,7 @@ def create_redis_connection():
mail = Mail()
mail.init_mail(settings.all_settings())
statsd_client = StatsClient(host=settings.STATSD_HOST, port=settings.STATSD_PORT, prefix=settings.STATSD_PREFIX)
hipchat_client = hipchat.HipChat(token=settings.HIPCHAT_API_TOKEN)

import_query_runners(settings.QUERY_RUNNERS)

Expand Down
3 changes: 3 additions & 0 deletions redash/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ def all_settings():

HOST = os.environ.get('REDASH_HOST', '')

HIPCHAT_API_TOKEN = os.environ.get('REDASH_HIPCHAT_API_TOKEN', None)
HIPCHAT_ROOM_ID = os.environ.get('REDASH_HIPCHAT_ROOM_ID', None)

# CORS settings for the Query Result API (and possbily future external APIs).
# In most cases all you need to do is set REDASH_CORS_ACCESS_CONTROL_ALLOW_ORIGIN
# to the calling domain (or domains in a comma separated list).
Expand Down
25 changes: 19 additions & 6 deletions redash/tasks.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import time
import logging
import signal
import traceback
from flask.ext.mail import Message
import redis
from celery import Task
from celery.result import AsyncResult
from celery.utils.log import get_task_logger
from redash import redis_connection, models, statsd_client, settings, utils, mail
from redash import redis_connection, models, statsd_client, settings, utils, mail, hipchat_client
from redash.utils import gen_query_hash
from redash.worker import celery
from redash.query_runner import get_query_runner, InterruptException
Expand Down Expand Up @@ -258,12 +259,24 @@ def check_alerts_for_query(self, query_id):
Check <a href="{host}/alerts/{alert_id}">alert</a> / check <a href="{host}/queries/{query_id}">query</a>.
""".format(host=settings.HOST, alert_id=alert.id, query_id=query.id)

with app.app_context():
message = Message(recipients=recipients,
subject="[{1}] {0}".format(alert.name, new_state.upper()),
html=html)

mail.send(message)
try:
with app.app_context():
message = Message(recipients=recipients,
subject="[{1}] {0}".format(alert.name, new_state.upper()),
html=html)

mail.send(message)
except:
tb = traceback.format_exc()
logger.error(tb)

try:
if settings.HIPCHAT_API_TOKEN:
hipchat_client.message_room(settings.HIPCHAT_ROOM_ID, settings.NAME, alert.name + '<br />' + html, message_format='html')
except:
tb = traceback.format_exc()
logger.error(tb)


def signal_handler(*args):
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ pycrypto==2.6.1
funcy==1.5
raven==5.6.0
semver==2.2.1
python-simple-hipchat==0.4.0

0 comments on commit 9c1fda4

Please sign in to comment.