Esempio n. 1
0
    def note(self, message, params=None, **kwargs):
        """Create a note for the current incident (ex: .note <message>)."""
        number = self.get_incident_number()
        if number is None:
            msg = "Could not get incident number for current incident."
            message.dispatch(msg)
            return

        url = "%s/api/v1/incidents/%s/notes" % (self.subdomain, number)
        user = self.find_user_like(message.source)
        if user is None:
            message.dispatch("Could not find PagerDuty user matching: %s" %
                             message.source)
            return

        data = {
            "note": {
                "content": params
            },
            "requester_id": user["id"]
        }

        req = request.post(url, headers=self.api_headers, json=data)

        if request.ok(req):
            message.dispatch("Noted.")
        else:
            message.dispatch("Unable to create note: %d" % req.status_code)
            message.dispatch(req.text)
Esempio n. 2
0
File: ops.py Progetto: jk0/pyhole
    def note(self, message, params=None, **kwargs):
        """Create a note for an incident (ex: .note <ID> <message>)."""
        params = params.split(" ")
        incident_id = params.pop(0)

        self.api_headers["From"] = self._find_user(message.source)
        data = {
            "note": {
                "content": " ".join(params)
            }
        }

        url = "%s/incidents/%s/notes" % (self.endpoint, incident_id)
        req = request.post(url, headers=self.api_headers, json=data)

        if request.ok(req):
            message.dispatch("Noted.")
        else:
            message.dispatch("Unable to create note: %d" % req.status_code)
            message.dispatch(req.text)
Esempio n. 3
0
    def create_incident(self, message, description):
        """Create a PagerDuty incident with specified description."""
        # would have been called url, but flake8 complains that line is 81 long
        u = "https://events.pagerduty.com/generic/2010-04-15/create_event.json"
        data = {
            "service_key": self.integration_key,
            "event_type": "trigger",
            "description": description,
            "incident_key": utils.datetime_now_string(),
            "details": {"triggered by": message.source}
        }

        req = request.post(u, json=data)
        response_json = req.json()
        if request.ok(req):
            self.set_incident_key(response_json["incident_key"])
            message.dispatch("Created incident with incident_key: %s" %
                             self.get_incident_key())
        else:
            message.dispatch("Error creating incident: %d" % req.status_code)
            message.dispatch(response_json["message"])
Esempio n. 4
0
File: ops.py Progetto: jk0/pyhole
    def alert(self, message, params=None, **kwargs):
        """Trigger a custom alert (ex: .alert <service_key> <description>."""
        params = params.split(" ")
        service_key = params.pop(0)
        description = " ".join(params)

        data = {
            "service_key": service_key,
            "event_type": "trigger",
            "description": description,
            "details": description,
            "client": "pyhole %s" % version.version(),
            "client_url": "https://github.com/jk0/pyhole"
        }

        events_host = "https://events.pagerduty.com/"
        url = "%s/generic/2010-04-15/create_event.json" % events_host
        req = request.post(url, headers=self.api_headers, json=data)

        if request.ok(req):
            message.dispatch("Triggered.")
        else:
            message.dispatch("Unable to trigger alert: %d" % req.status_code)
            message.dispatch(req.text)