# Path: doorman/utils.py
# class DateTimeEncoder(json.JSONEncoder):
#     def default(self, o):
#         if isinstance(o, dt.datetime):
#             return o.isoformat()
# 
#         return json.JSONEncoder.default(self, o)
# 
# Path: doorman/plugins/alerters/base.py
# class AbstractAlerterPlugin(with_metaclass(ABCMeta)):
#     """
#     AbstractAlerterPlugin is the base class for all alerters in Doorman. It
#     defines the interface that an alerter should implement in order to support
#     sending an alert.
#     """
#     @abstractmethod
#     def handle_alert(self, node, match):
#         raise NotImplementedError()


import json
import logging
import requests
from doorman.utils import DateTimeEncoder
from .base import AbstractAlerterPlugin
# -*- coding: utf-8 -*-




DEFAULT_KEY_FORMAT = 'doorman-incident-{count}'


class PagerDutyAlerter(AbstractAlerterPlugin):
    def __init__(self, config):
        # Required configuration
        self.service_key = config['service_key']

        # Optional
        self.client_url = config.get('client_url', '')
        self.key_format = config.get('key_format', DEFAULT_KEY_FORMAT)

        # Other
        self.incident_count = 0
        self.logger = logging.getLogger(__name__ + '.PagerDutyAlerter')

    def handle_alert(self, node, match):
        self.incident_count += 1
        key = self.key_format.format(

# Path: doorman/utils.py
# class DateTimeEncoder(json.JSONEncoder):
#     def default(self, o):
#         if isinstance(o, dt.datetime):
#             return o.isoformat()
# 
#         return json.JSONEncoder.default(self, o)
# 
# Path: doorman/plugins/alerters/base.py
# class AbstractAlerterPlugin(with_metaclass(ABCMeta)):
#     """
#     AbstractAlerterPlugin is the base class for all alerters in Doorman. It
#     defines the interface that an alerter should implement in order to support
#     sending an alert.
#     """
#     @abstractmethod
#     def handle_alert(self, node, match):
#         raise NotImplementedError()


# Path: doorman/plugins/alerters/pagerduty.py
import json
import logging
import requests
from doorman.utils import DateTimeEncoder
from .base import AbstractAlerterPlugin

# -*- coding: utf-8 -*-




DEFAULT_KEY_FORMAT = 'doorman-incident-{count}'


class PagerDutyAlerter(AbstractAlerterPlugin):
    def __init__(self, config):
        # Required configuration
        self.service_key = config['service_key']

        # Optional
        self.client_url = config.get('client_url', '')
        self.key_format = config.get('key_format', DEFAULT_KEY_FORMAT)

        # Other
        self.incident_count = 0
        self.logger = logging.getLogger(__name__ + '.PagerDutyAlerter')

    def handle_alert(self, node, match):
        self.incident_count += 1
        key = self.key_format.format(

            count=self.incident_count