Skip to content

Commit

Permalink
Changed verbosity of logs and changed logger as requested in alerta#353
Browse files Browse the repository at this point in the history
  • Loading branch information
legovaer committed Jul 21, 2022
1 parent 0e82da4 commit 9a2369f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion plugins/pagerduty/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ References
License
-------

Copyright (c) 2016 Nick Satterly. Available under the MIT License.
Copyright (c) 2022 Nick Satterly. Available under the MIT License.
21 changes: 11 additions & 10 deletions plugins/pagerduty/alerta_pagerduty.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from alerta.app import app # alerta < 5.0
from alerta.plugins import PluginBase

LOG = logging.getLogger('alerta.plugins')
LOG = logging.getLogger('alerta.plugins.pagerduty')

PAGERDUTY_SERVICE_KEY = os.environ.get('PAGERDUTY_SERVICE_KEY') or app.config['PAGERDUTY_SERVICE_KEY']
SERVICE_KEY_MATCHERS = os.environ.get('SERVICE_KEY_MATCHERS') or app.config['SERVICE_KEY_MATCHERS']
Expand All @@ -22,23 +22,23 @@ class TriggerEvent(PluginBase):

def pagerduty_service_key(self, resource):
if not SERVICE_KEY_MATCHERS:
LOG.warning('No matchers defined! Default service key: %s' % (PAGERDUTY_SERVICE_KEY))
LOG.debug('No matchers defined! Default service key: %s' % (PAGERDUTY_SERVICE_KEY))
return PAGERDUTY_SERVICE_KEY

for mapping in SERVICE_KEY_MATCHERS:
if re.match(mapping['regex'], resource):
LOG.warning('Matched regex: %s, service key: %s' % (mapping['regex'], mapping['api_key']))
LOG.debug('Matched regex: %s, service key: %s' % (mapping['regex'], mapping['api_key']))
return mapping['api_key']

LOG.warning('No regex match! Default service key: %s' % (PAGERDUTY_SERVICE_KEY))
LOG.debug('No regex match! Default service key: %s' % (PAGERDUTY_SERVICE_KEY))
return PAGERDUTY_SERVICE_KEY

def pre_receive(self, alert, **kwargs):
return alert

def post_receive(self, alert, **kwargs):

LOG.warning('Sending PagerDuty notice')
LOG.debug('Sending PagerDuty notice')

if alert.repeat:
return
Expand All @@ -55,9 +55,9 @@ def post_receive(self, alert, **kwargs):
pd_incident = session.resolve(alert.id)
else:
pd_incident = session.trigger(
message,
alert.resource,
dedup_key=alert.id,
message,
alert.resource,
dedup_key=alert.id,
severity=alert.severity,
custom_details=alert.get_body(history=False),
links=['%s/#/alert/%s' % (DASHBOARD_URL, alert.id)]
Expand All @@ -66,7 +66,8 @@ def post_receive(self, alert, **kwargs):
except Exception as e:
raise RuntimeError("PagerDuty connection error: %s" % e)

LOG.warning('PagerDuty notice sent')
LOG.info('PagerDuty notice sent')

def status_change(self, alert, status, text, **kwargs):
LOG.warn('PagerDuty status change ignored.')
LOG.debug('PagerDuty status change ignored.')

0 comments on commit 9a2369f

Please sign in to comment.