mirror of
https://github.com/caronc/apprise.git
synced 2025-01-03 20:49:19 +01:00
pagerduty:// severity= override option (#726)
This commit is contained in:
parent
81907af448
commit
184ff48551
@ -61,6 +61,13 @@ PAGERDUTY_SEVERITY_MAP = {
|
|||||||
NotifyType.FAILURE: PagerDutySeverity.CRITICAL,
|
NotifyType.FAILURE: PagerDutySeverity.CRITICAL,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PAGERDUTY_SEVERITIES = (
|
||||||
|
PagerDutySeverity.INFO,
|
||||||
|
PagerDutySeverity.WARNING,
|
||||||
|
PagerDutySeverity.CRITICAL,
|
||||||
|
PagerDutySeverity.ERROR,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# Priorities
|
# Priorities
|
||||||
class PagerDutyRegion:
|
class PagerDutyRegion:
|
||||||
@ -169,6 +176,14 @@ class NotifyPagerDuty(NotifyBase):
|
|||||||
'default': PagerDutyRegion.US,
|
'default': PagerDutyRegion.US,
|
||||||
'map_to': 'region_name',
|
'map_to': 'region_name',
|
||||||
},
|
},
|
||||||
|
# The severity is automatically determined, however you can optionally
|
||||||
|
# over-ride its value and force it to be what you want
|
||||||
|
'severity': {
|
||||||
|
'name': _('Severity'),
|
||||||
|
'type': 'choice:string',
|
||||||
|
'values': PAGERDUTY_SEVERITIES,
|
||||||
|
'map_to': 'severity',
|
||||||
|
},
|
||||||
'image': {
|
'image': {
|
||||||
'name': _('Include Image'),
|
'name': _('Include Image'),
|
||||||
'type': 'bool',
|
'type': 'bool',
|
||||||
@ -188,7 +203,7 @@ class NotifyPagerDuty(NotifyBase):
|
|||||||
def __init__(self, apikey, integrationkey=None, source=None,
|
def __init__(self, apikey, integrationkey=None, source=None,
|
||||||
component=None, group=None, class_id=None,
|
component=None, group=None, class_id=None,
|
||||||
include_image=True, click=None, details=None,
|
include_image=True, click=None, details=None,
|
||||||
region_name=None, **kwargs):
|
region_name=None, severity=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
Initialize Pager Duty Object
|
Initialize Pager Duty Object
|
||||||
"""
|
"""
|
||||||
@ -248,6 +263,19 @@ class NotifyPagerDuty(NotifyBase):
|
|||||||
self.logger.warning(msg)
|
self.logger.warning(msg)
|
||||||
raise TypeError(msg)
|
raise TypeError(msg)
|
||||||
|
|
||||||
|
# The severity (if specified)
|
||||||
|
self.severity = \
|
||||||
|
None if severity is None else next((
|
||||||
|
s for s in PAGERDUTY_SEVERITIES
|
||||||
|
if str(s).lower().startswith(severity)), False)
|
||||||
|
|
||||||
|
if self.severity is False:
|
||||||
|
# Invalid severity specified
|
||||||
|
msg = 'The PagerDuty severity specified ({}) is invalid.' \
|
||||||
|
.format(severity)
|
||||||
|
self.logger.warning(msg)
|
||||||
|
raise TypeError(msg)
|
||||||
|
|
||||||
# A clickthrough option for notifications
|
# A clickthrough option for notifications
|
||||||
self.click = click
|
self.click = click
|
||||||
|
|
||||||
@ -289,8 +317,8 @@ class NotifyPagerDuty(NotifyBase):
|
|||||||
'summary': body,
|
'summary': body,
|
||||||
|
|
||||||
# Set our severity
|
# Set our severity
|
||||||
'severity': PAGERDUTY_SEVERITY_MAP[notify_type],
|
'severity': PAGERDUTY_SEVERITY_MAP[notify_type]
|
||||||
|
if not self.severity else self.severity,
|
||||||
|
|
||||||
# Our Alerting Source/Component
|
# Our Alerting Source/Component
|
||||||
'source': self.source,
|
'source': self.source,
|
||||||
@ -400,6 +428,9 @@ class NotifyPagerDuty(NotifyBase):
|
|||||||
if self.click is not None:
|
if self.click is not None:
|
||||||
params['click'] = self.click
|
params['click'] = self.click
|
||||||
|
|
||||||
|
if self.severity:
|
||||||
|
params['severity'] = self.severity
|
||||||
|
|
||||||
# Append our custom entries our parameters
|
# Append our custom entries our parameters
|
||||||
params.update({'+{}'.format(k): v for k, v in self.details.items()})
|
params.update({'+{}'.format(k): v for k, v in self.details.items()})
|
||||||
|
|
||||||
@ -464,6 +495,10 @@ class NotifyPagerDuty(NotifyBase):
|
|||||||
results['class_id'] = \
|
results['class_id'] = \
|
||||||
NotifyPagerDuty.unquote(results['qsd']['class'])
|
NotifyPagerDuty.unquote(results['qsd']['class'])
|
||||||
|
|
||||||
|
if 'severity' in results['qsd'] and len(results['qsd']['severity']):
|
||||||
|
results['severity'] = \
|
||||||
|
NotifyPagerDuty.unquote(results['qsd']['severity'])
|
||||||
|
|
||||||
# Acquire our full path
|
# Acquire our full path
|
||||||
fullpath = NotifyPagerDuty.split_path(results['fullpath'])
|
fullpath = NotifyPagerDuty.split_path(results['fullpath'])
|
||||||
|
|
||||||
|
@ -59,6 +59,10 @@ apprise_url_tests = (
|
|||||||
# invalid region
|
# invalid region
|
||||||
'instance': TypeError,
|
'instance': TypeError,
|
||||||
}),
|
}),
|
||||||
|
('pagerduty://myroutekey@myapikey?severity=invalid', {
|
||||||
|
# invalid severity
|
||||||
|
'instance': TypeError,
|
||||||
|
}),
|
||||||
('pagerduty://myroutekey@myapikey', {
|
('pagerduty://myroutekey@myapikey', {
|
||||||
# minimum requirements met
|
# minimum requirements met
|
||||||
'instance': NotifyPagerDuty,
|
'instance': NotifyPagerDuty,
|
||||||
@ -74,6 +78,14 @@ apprise_url_tests = (
|
|||||||
# european region
|
# european region
|
||||||
'instance': NotifyPagerDuty,
|
'instance': NotifyPagerDuty,
|
||||||
}),
|
}),
|
||||||
|
('pagerduty://myroutekey@myapikey?severity=critical', {
|
||||||
|
# Severity over-ride
|
||||||
|
'instance': NotifyPagerDuty,
|
||||||
|
}),
|
||||||
|
('pagerduty://myroutekey@myapikey?severity=err', {
|
||||||
|
# Severity over-ride (short-form)
|
||||||
|
'instance': NotifyPagerDuty,
|
||||||
|
}),
|
||||||
# Custom values
|
# Custom values
|
||||||
('pagerduty://myroutekey@myapikey?+key=value&+key2=value2', {
|
('pagerduty://myroutekey@myapikey?+key=value&+key2=value2', {
|
||||||
# minimum requirements and support custom key/value pairs
|
# minimum requirements and support custom key/value pairs
|
||||||
|
Loading…
Reference in New Issue
Block a user