Пример #1
0
 def __init__(self, opts):
     """constructor provides access to the configuration options"""
     super(FunctionComponent, self).__init__(opts)
     self.res_options = opts.get("resilient", {})
     self.options = opts.get("pagerduty", {})
     validateFields(['api_token', 'from_email'], self.options)
     self.log = logging.getLogger(__name__)
Пример #2
0
    def _pagerduty_create_incident_function(self, event, *args, **kwargs):
        """Function: create an incident"""
        try:
            # validate required fields
            validateFields(['incidentID', 'pd_title', 'pd_service', 'pd_escalation_policy'], kwargs)

            createDict = self._buildIncidentPayload(kwargs, self.options, self.res_options)
            #
            yield StatusMessage("starting...")
            resp = create_incident(self.log, createDict)
            yield StatusMessage("pagerduty incident created")

            # Produce a FunctionResult with the results
            yield FunctionResult({"pd": resp})
        except Exception as err:
            yield FunctionError(err)
Пример #3
0
    def _pagerduty_create_note_function(self, event, *args, **kwargs):
        """Function: """
        try:
            # validate the function parameters:
            validateFields([u'pd_incident_id', u'pd_description'], kwargs)

            incident_id = kwargs.get(u'pd_incident_id')  # text
            description = clean_html(kwargs.get(u'pd_description'))  # text

            yield StatusMessage("starting...")
            resp = create_note(self.log, self.options, incident_id,
                               description, self.create_note_callback)
            yield StatusMessage("pagerduty note created")

            # Produce a FunctionResult with the results - if not error, the response is not used
            yield FunctionResult(resp)
        except Exception as err:
            yield FunctionError(err)
Пример #4
0
    def _pagerduty_transition_incident_function(self, event, *args, **kwargs):
        """Function: transition an indident"""
        try:
            validateFields(['pd_incident_id'], kwargs)

            # Get the function parameters:
            incident_id = kwargs.get("pd_incident_id")  # text
            status = self.get_select_param(
                kwargs.get("pd_status")
            )  # select, values: "acknowledge", "resolve", "esclate"
            priority = kwargs.get("pd_priority")  # text
            resolution = clean_html(kwargs.get("pd_description"))  # text

            yield StatusMessage("starting...")
            resp = update_incident(self.log, self.options, incident_id, status,
                                   priority, resolution, self.callback)
            yield StatusMessage("pagerduty incident updated")

            # Produce a FunctionResult with the results
            yield FunctionResult(resp)
        except Exception as err:
            yield FunctionError(err)
Пример #5
0
 def _reload(self, event, opts):
     """Configuration options have changed, save new values"""
     self.options = opts.get("pagerduty", {})
     validateFields(['api_token', 'from_email'], self.options)
     self.res_options = opts.get("resilient", {})