From 9a2369fd76f84fcdab8d0c2bb7a0b5382141b1d2 Mon Sep 17 00:00:00 2001 From: Levi Govaerts Date: Thu, 21 Jul 2022 10:43:50 +0200 Subject: [PATCH] Changed verbosity of logs and changed logger as requested in #353 --- plugins/pagerduty/README.md | 2 +- plugins/pagerduty/alerta_pagerduty.py | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/plugins/pagerduty/README.md b/plugins/pagerduty/README.md index 65670292..c39f2a9d 100644 --- a/plugins/pagerduty/README.md +++ b/plugins/pagerduty/README.md @@ -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. diff --git a/plugins/pagerduty/alerta_pagerduty.py b/plugins/pagerduty/alerta_pagerduty.py index 3616e022..c33aa562 100644 --- a/plugins/pagerduty/alerta_pagerduty.py +++ b/plugins/pagerduty/alerta_pagerduty.py @@ -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'] @@ -22,15 +22,15 @@ 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): @@ -38,7 +38,7 @@ def pre_receive(self, alert, **kwargs): def post_receive(self, alert, **kwargs): - LOG.warning('Sending PagerDuty notice') + LOG.debug('Sending PagerDuty notice') if alert.repeat: return @@ -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)] @@ -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.') \ No newline at end of file + LOG.debug('PagerDuty status change ignored.') +