mirror of https://github.com/caronc/apprise
				
				
				
			pagerduty:// severity= override option (#726)
							parent
							
								
									81907af448
								
							
						
					
					
						commit
						184ff48551
					
				| 
						 | 
				
			
			@ -61,6 +61,13 @@ PAGERDUTY_SEVERITY_MAP = {
 | 
			
		|||
    NotifyType.FAILURE: PagerDutySeverity.CRITICAL,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
PAGERDUTY_SEVERITIES = (
 | 
			
		||||
    PagerDutySeverity.INFO,
 | 
			
		||||
    PagerDutySeverity.WARNING,
 | 
			
		||||
    PagerDutySeverity.CRITICAL,
 | 
			
		||||
    PagerDutySeverity.ERROR,
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# Priorities
 | 
			
		||||
class PagerDutyRegion:
 | 
			
		||||
| 
						 | 
				
			
			@ -169,6 +176,14 @@ class NotifyPagerDuty(NotifyBase):
 | 
			
		|||
            'default': PagerDutyRegion.US,
 | 
			
		||||
            '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': {
 | 
			
		||||
            'name': _('Include Image'),
 | 
			
		||||
            'type': 'bool',
 | 
			
		||||
| 
						 | 
				
			
			@ -188,7 +203,7 @@ class NotifyPagerDuty(NotifyBase):
 | 
			
		|||
    def __init__(self, apikey, integrationkey=None, source=None,
 | 
			
		||||
                 component=None, group=None, class_id=None,
 | 
			
		||||
                 include_image=True, click=None, details=None,
 | 
			
		||||
                 region_name=None, **kwargs):
 | 
			
		||||
                 region_name=None, severity=None, **kwargs):
 | 
			
		||||
        """
 | 
			
		||||
        Initialize Pager Duty Object
 | 
			
		||||
        """
 | 
			
		||||
| 
						 | 
				
			
			@ -248,6 +263,19 @@ class NotifyPagerDuty(NotifyBase):
 | 
			
		|||
            self.logger.warning(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
 | 
			
		||||
        self.click = click
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -289,8 +317,8 @@ class NotifyPagerDuty(NotifyBase):
 | 
			
		|||
                'summary': body,
 | 
			
		||||
 | 
			
		||||
                # 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
 | 
			
		||||
                'source': self.source,
 | 
			
		||||
| 
						 | 
				
			
			@ -400,6 +428,9 @@ class NotifyPagerDuty(NotifyBase):
 | 
			
		|||
        if self.click is not None:
 | 
			
		||||
            params['click'] = self.click
 | 
			
		||||
 | 
			
		||||
        if self.severity:
 | 
			
		||||
            params['severity'] = self.severity
 | 
			
		||||
 | 
			
		||||
        # Append our custom entries our parameters
 | 
			
		||||
        params.update({'+{}'.format(k): v for k, v in self.details.items()})
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -464,6 +495,10 @@ class NotifyPagerDuty(NotifyBase):
 | 
			
		|||
            results['class_id'] = \
 | 
			
		||||
                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
 | 
			
		||||
        fullpath = NotifyPagerDuty.split_path(results['fullpath'])
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -59,6 +59,10 @@ apprise_url_tests = (
 | 
			
		|||
        # invalid region
 | 
			
		||||
        'instance': TypeError,
 | 
			
		||||
    }),
 | 
			
		||||
    ('pagerduty://myroutekey@myapikey?severity=invalid', {
 | 
			
		||||
        # invalid severity
 | 
			
		||||
        'instance': TypeError,
 | 
			
		||||
    }),
 | 
			
		||||
    ('pagerduty://myroutekey@myapikey', {
 | 
			
		||||
        # minimum requirements met
 | 
			
		||||
        'instance': NotifyPagerDuty,
 | 
			
		||||
| 
						 | 
				
			
			@ -74,6 +78,14 @@ apprise_url_tests = (
 | 
			
		|||
        # european region
 | 
			
		||||
        '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
 | 
			
		||||
    ('pagerduty://myroutekey@myapikey?+key=value&+key2=value2', {
 | 
			
		||||
        # minimum requirements and support custom key/value pairs
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue