Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Add support for alerts #10

Merged
merged 2 commits into from about 1 year ago

2 participants

David Cramer Xavier Ordoquy
David Cramer
Collaborator

No description provided.

Xavier Ordoquy xordoquy merged commit f05c15e into from
Xavier Ordoquy xordoquy closed this
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 1 changed file with 22 additions and 10 deletions. Show diff stats Hide diff stats

  1. +22 10 sentry_hipchat/models.py
32 sentry_hipchat/models.py
@@ -8,7 +8,6 @@
8 8
9 9 from django import forms
10 10
11   -from sentry.conf import settings
12 11 from sentry.plugins import Plugin
13 12
14 13 import sentry_hipchat
@@ -19,6 +18,7 @@
19 18 import logging
20 19
21 20 COLORS = {
  21 + 'ALERT': 'orange',
22 22 'ERROR': 'red',
23 23 'WARNING': 'yellow',
24 24 'INFO': 'green',
@@ -52,6 +52,20 @@ class HipchatMessage(Plugin):
52 52 def is_configured(self, project):
53 53 return all((self.get_option(k, project) for k in ('room', 'token')))
54 54
  55 + def on_alert(self, alert, **kwargs):
  56 + project = alert.project
  57 + token = self.get_option('token', project)
  58 + room = self.get_option('room', project)
  59 + notify = self.get_option('notify', project) or False
  60 + include_project_name = self.get_option('include_project_name', project) or False
  61 +
  62 + if token and room:
  63 + self.send_payload(token, room, '[ALERT]%(project_name)s %(message)s %(link)s' % {
  64 + 'project_name': (' <strong>%s</strong>' % project.name) if include_project_name else '',
  65 + 'message': alert.message,
  66 + 'link': alert.get_absolute_url(),
  67 + }, notify, color=COLORS['ALERT'])
  68 +
55 69 def post_process(self, group, event, is_new, is_sample, **kwargs):
56 70 new_only = self.get_option('new_only', event.project)
57 71 if new_only and not is_new:
@@ -62,17 +76,15 @@ def post_process(self, group, event, is_new, is_sample, **kwargs):
62 76 notify = self.get_option('notify', event.project) or False
63 77 include_project_name = self.get_option('include_project_name', event.project) or False
64 78 level = event.get_level_display().upper()
65   - link = '<a href="%s/%s/group/%d/">(link)</a>' % (settings.URL_PREFIX, group.project.slug, group.id)
  79 + link = self.get_group_url(group)
66 80
67 81 if token and room:
68   - self.send_payload(token, room, '%(site)s[%(server)s]%(project_name)s %(message)s %(link)s' % {
69   - 'server': event.server_name,
70   - 'site': ('%s ' % event.site) if event.site else '',
71   - 'project_name': (' <strong>%s</strong>' % event.project.name) if include_project_name else '',
72   - 'message': event.message,
73   - 'link': link,
74   - },
75   - notify, color=COLORS.get(level, 'purple'))
  82 + self.send_payload(token, room, '[%(level)s]%(project_name)s %(message)s %(link)s' % {
  83 + 'level': level,
  84 + 'project_name': (' <strong>%s</strong>' % event.project.name) if include_project_name else '',
  85 + 'message': event.message,
  86 + 'link': link,
  87 + }, notify, color=COLORS.get(level, 'purple'))
76 88
77 89 def send_payload(self, token, room, message, notify, color='red'):
78 90 url = "https://api.hipchat.com/v1/rooms/message"

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.