Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add support for alerts #10

Merged
merged 2 commits into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 22 additions and 10 deletions.
  1. +22 −10 sentry_hipchat/models.py
View
32 sentry_hipchat/models.py
@@ -8,7 +8,6 @@
from django import forms
-from sentry.conf import settings
from sentry.plugins import Plugin
import sentry_hipchat
@@ -19,6 +18,7 @@
import logging
COLORS = {
+ 'ALERT': 'orange',
'ERROR': 'red',
'WARNING': 'yellow',
'INFO': 'green',
@@ -52,6 +52,20 @@ class HipchatMessage(Plugin):
def is_configured(self, project):
return all((self.get_option(k, project) for k in ('room', 'token')))
+ def on_alert(self, alert, **kwargs):
+ project = alert.project
+ token = self.get_option('token', project)
+ room = self.get_option('room', project)
+ notify = self.get_option('notify', project) or False
+ include_project_name = self.get_option('include_project_name', project) or False
+
+ if token and room:
+ self.send_payload(token, room, '[ALERT]%(project_name)s %(message)s %(link)s' % {
+ 'project_name': (' <strong>%s</strong>' % project.name) if include_project_name else '',
+ 'message': alert.message,
+ 'link': alert.get_absolute_url(),
+ }, notify, color=COLORS['ALERT'])
+
def post_process(self, group, event, is_new, is_sample, **kwargs):
new_only = self.get_option('new_only', event.project)
if new_only and not is_new:
@@ -62,17 +76,15 @@ def post_process(self, group, event, is_new, is_sample, **kwargs):
notify = self.get_option('notify', event.project) or False
include_project_name = self.get_option('include_project_name', event.project) or False
level = event.get_level_display().upper()
- link = '<a href="%s/%s/group/%d/">(link)</a>' % (settings.URL_PREFIX, group.project.slug, group.id)
+ link = self.get_group_url(group)
if token and room:
- self.send_payload(token, room, '%(site)s[%(server)s]%(project_name)s %(message)s %(link)s' % {
- 'server': event.server_name,
- 'site': ('%s ' % event.site) if event.site else '',
- 'project_name': (' <strong>%s</strong>' % event.project.name) if include_project_name else '',
- 'message': event.message,
- 'link': link,
- },
- notify, color=COLORS.get(level, 'purple'))
+ self.send_payload(token, room, '[%(level)s]%(project_name)s %(message)s %(link)s' % {
+ 'level': level,
+ 'project_name': (' <strong>%s</strong>' % event.project.name) if include_project_name else '',
+ 'message': event.message,
+ 'link': link,
+ }, notify, color=COLORS.get(level, 'purple'))
def send_payload(self, token, room, message, notify, color='red'):
url = "https://api.hipchat.com/v1/rooms/message"
Something went wrong with that request. Please try again.