Skip to content

Commit 9f5d474

Browse files
committed
Global: Debug mode.
Summary: * Add a debug mode that will display debug messages in the docker logs
1 parent cc01ce1 commit 9f5d474

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

sentry_mattermost/__init__.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

sentry_mattermost/plugin.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# THE SOFTWARE.
2020

2121
import urllib2
22+
import logging
2223

2324
from sentry import tagstore
2425
from sentry.plugins.bases import notify
@@ -27,7 +28,7 @@
2728
from sentry.integrations import FeatureDescription, IntegrationFeatures
2829
from string import Formatter
2930

30-
import sentry_mattermost
31+
logger = logging.getLogger("sentry.integrations.sentry_mattermost.plugin")
3132

3233

3334
def get_rules(rules, group, project):
@@ -49,8 +50,14 @@ class PayloadFactory:
4950
def create(cls, plugin, event, template, rules):
5051
project = event.group.project
5152

53+
if not template:
54+
# In some cases like after updating the plugin, template config variable can be
55+
# None, in that case we need a fallback.
56+
template = "__[{project@get_full_name}]({project@get_absolute_url})__\n__[{group@title}]({group@get_absolute_url})__\n{group@culprit}\n{rules}\n{tags}"
57+
5258
names = [fn for _, fn, _, _ in Formatter().parse(template)
5359
if fn not in {None, "rules", "tags"}]
60+
5461
params = {"rules": "", "tags": ""}
5562
for name in names:
5663
getter = None
@@ -72,7 +79,6 @@ def create(cls, plugin, event, template, rules):
7279
if plugin.get_option('include_tags', project):
7380
params["tags"] = get_tags(event)
7481

75-
7682
# \n is not correctly interpreted from the text field of sentry
7783
template = template.replace("\\n", "\n")
7884
text = template.format(**params)
@@ -88,7 +94,8 @@ def create(cls, plugin, event, template, rules):
8894
def request(url, payload):
8995
data = "payload=" + json.dumps(payload)
9096
# Prevent servers from rejecting webhook calls by adding a existing user agent
91-
req = urllib2.Request(url, data, headers={'User-Agent' : "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0"})
97+
req = urllib2.Request(url, data, headers={
98+
'User-Agent': "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0"})
9299
response = urllib2.urlopen(req)
93100
return response.read()
94101

@@ -97,7 +104,7 @@ class Mattermost(CorePluginMixin, notify.NotificationPlugin):
97104
title = 'Mattermost'
98105
slug = 'mattermost'
99106
description = 'Enables notifications for Mattermost Open Source Chat'
100-
version = sentry_mattermost.VERSION
107+
version = '0.0.5'
101108
author = 'Andre Freitas <[email protected]>, Guillaume Lastecoueres<[email protected]>'
102109
author_url = 'https://github.com/Biekos/sentry-mattermost'
103110
required_field = "webhook"
@@ -143,18 +150,38 @@ def get_config(self, project, **kwargs):
143150
"type": "bool",
144151
"required": False,
145152
"help": "Include tags with notifications."
153+
},
154+
{
155+
"name": "debug",
156+
"label": "Debug mode",
157+
"type": "bool",
158+
"required": False,
159+
"help": "Enable logging",
146160
}]
147161

148162
def is_configured(self, project):
149163
return bool(self.get_option("webhook", project))
150164

151165
def notify_users(self, group, event, triggering_rules, **kwargs):
166+
152167
project = event.group.project
168+
debug_mode = self.get_option('debug', project)
153169
if not self.is_configured(project):
154170
return
155171

156172
webhook = self.get_option('webhook', project)
173+
if debug_mode:
174+
logger.info("DEBUG:webhook used: {}".format(webhook))
157175
template = self.get_option('template', project)
176+
if debug_mode:
177+
logger.info("DEBUG:template used: {}".format(template))
158178
payload = PayloadFactory.create(
159179
self, event, template, triggering_rules)
160-
return request(webhook, payload)
180+
if debug_mode:
181+
logger.info("DEBUG:payload: {}".format(payload))
182+
183+
res = request(webhook, payload)
184+
185+
if debug_mode:
186+
logger.info("DEBUG:request executed: {}".format(res))
187+
return res

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@
1919
# THE SOFTWARE.
2020

2121
from setuptools import setup
22-
from sentry_mattermost import VERSION
2322

2423
setup(
2524
name="sentry_mattermost",
26-
version=VERSION,
25+
version="0.0.5",
2726
author="Andre Freitas, Guillaume Lastecoueres, Biekos TEAM",
2827
2928
description=("A Sentry plugin to send Mattermost notifications."),

0 commit comments

Comments
 (0)