Skip to content

Commit

Permalink
Move to notification plugin (v1)
Browse files Browse the repository at this point in the history
To integrate with notification rules.
  • Loading branch information
eagletmt committed Feb 13, 2015
1 parent 1ba29db commit eb0b60c
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions sentry_notify_hipchat/plugin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django import forms
from hipchat import HipChat
from sentry.plugins import Plugin
from sentry.plugins.bases.notify import NotificationPlugin
from sentry.utils.strings import strip
import xml.sax.saxutils as saxutils

Expand All @@ -13,13 +13,11 @@
class NotifyHipchatForm(forms.Form):
token = forms.CharField(help_text='HipChat API v1 token')
room = forms.CharField(help_text='Room name or ID')
new_only = forms.BooleanField(help_text='Notify new messages only', required=False)
ignore_muted = forms.BooleanField(help_text="Don't notify muted events", required=False, initial=True)
notify = forms.BooleanField(help_text='Enable "notify" flag', required=False, initial=True)
endpoint = forms.CharField(help_text='HipChat API endpoint', required=False)


class NotifyHipchatPlugin(Plugin):
class NotifyHipchatPlugin(NotificationPlugin):
title = 'HipChat Notification'
slug = 'notify-hipchat'
description = 'A notification plugin for HipChat'
Expand All @@ -29,22 +27,9 @@ class NotifyHipchatPlugin(Plugin):
conf_key = 'notify-hipchat'
project_conf_form = NotifyHipchatForm

def post_process(self, group, event, is_new, is_sample, **kwargs):
if self.__should_notify(group, event, is_new):
self.__notify(group, event, is_new)

def __should_notify(self, group, event, is_new):
if self.get_option('new_only', group.project) and not is_new:
return False
if self.get_option('ignore_muted', group.project) and group.is_muted():
return False
return True

def __notify(self, group, event, is_new):
def notify_users(self, group, event, fail_silently=False):
project_name = '<strong>{0}</strong>'.format(saxutils.escape(group.project.name))
times_seen = group.times_seen+1
if is_new:
times_seen = 1
times_seen = group.times_seen

message = '''[{level}] {project} {message}<br>
{culprit} ({count} times seen)<br>
Expand Down

0 comments on commit eb0b60c

Please sign in to comment.