# 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

        # 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
        )

        description = match.rule.template.safe_substitute(
            match.result['columns'],
            **node
        ).rstrip()

        description = ":".join(description.split('\r\n\r\n', 1))

        details = {
            'node': node,
            'rule_name': match.rule.name,
            'rule_description': match.rule.description,
            'action': match.result['action'],
            'match': match.result['columns'],
        }

        headers = {
            'Content-type': 'application/json',
        }


# 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


        # 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
        )

        description = match.rule.template.safe_substitute(
            match.result['columns'],
            **node
        ).rstrip()

        description = ":".join(description.split('\r\n\r\n', 1))

        details = {
            'node': node,
            'rule_name': match.rule.name,
            'rule_description': match.rule.description,
            'action': match.result['action'],
            'match': match.result['columns'],
        }

        headers = {
            'Content-type': 'application/json',
        }


        payload = json.dumps({