|
| 1 | +from ..core import Provider |
| 2 | +from ..core import Response |
| 3 | +from ..utils import requests |
| 4 | + |
| 5 | + |
| 6 | +class VictorOps(Provider): |
| 7 | + """Send VictorOps webhook notifications""" |
| 8 | + |
| 9 | + base_url = "https://portal.victorops.com/ui/{ORGANIZATION_ID}/incidents" |
| 10 | + site_url = "https://portal.victorops.com/dash/{ORGANIZATION_ID}#/advanced/rest" |
| 11 | + name = "victorops" |
| 12 | + |
| 13 | + _required = { |
| 14 | + "required": [ |
| 15 | + "rest_url", |
| 16 | + "message_type", |
| 17 | + "entity_id", |
| 18 | + "entity_display_name", |
| 19 | + "message", |
| 20 | + ] |
| 21 | + } |
| 22 | + _schema = { |
| 23 | + "type": "object", |
| 24 | + "properties": { |
| 25 | + "rest_url": { |
| 26 | + "type": "string", |
| 27 | + "format": "uri", |
| 28 | + "title": "the REST URL to use with routing_key. create one in victorops `integrations` tab.", |
| 29 | + }, |
| 30 | + "message_type": { |
| 31 | + "type": "string", |
| 32 | + "title": "severity level can be: " |
| 33 | + "- critical or warning: Triggers an incident " |
| 34 | + "- acknowledgement: sends Acknowledgment to an incident " |
| 35 | + "- info: Creates a timeline event but doesn't trigger an incident " |
| 36 | + "- recovery or ok: Resolves an incident", |
| 37 | + "enum": [ |
| 38 | + "critical", |
| 39 | + "warning", |
| 40 | + "acknowledgement", |
| 41 | + "info", |
| 42 | + "recovery", |
| 43 | + "ok", |
| 44 | + ], |
| 45 | + }, |
| 46 | + "entity_id": { |
| 47 | + "type": "string", |
| 48 | + "title": "Unique id for the incident for aggregation ,Acknowledging, or resolving.", |
| 49 | + }, |
| 50 | + "entity_display_name": { |
| 51 | + "type": "string", |
| 52 | + "title": "Display Name in the UI and Notifications.", |
| 53 | + }, |
| 54 | + "message": { |
| 55 | + "type": "string", |
| 56 | + "title": "This is the description that will be posted in the incident.", |
| 57 | + }, |
| 58 | + "annotations": { |
| 59 | + "type": "object", |
| 60 | + "patternProperties": { |
| 61 | + "^vo_annotate.u.": {"type": "string"}, |
| 62 | + "^vo_annotate.s.": {"type": "string"}, |
| 63 | + "^vo_annotate.i.": {"type": "string"}, |
| 64 | + }, |
| 65 | + "minProperties": 1, |
| 66 | + "title": "annotations can be of three types: " |
| 67 | + "vo_annotate.u.{custom_name}, " |
| 68 | + "vo_annotate.s.{custom_name}, " |
| 69 | + "vo_annotate.i.{custom_name} .", |
| 70 | + "additionalProperties": False, |
| 71 | + }, |
| 72 | + "additional_keys": { |
| 73 | + "type": "object", |
| 74 | + "title": "any additional keys that can be passed in the body", |
| 75 | + }, |
| 76 | + }, |
| 77 | + "additionalProperties": False, |
| 78 | + } |
| 79 | + |
| 80 | + def _prepare_data(self, data: dict) -> dict: |
| 81 | + annotations = data.pop("annotations", {}) |
| 82 | + for annotation, value in annotations.items(): |
| 83 | + data[annotation] = value |
| 84 | + |
| 85 | + additional_keys = data.pop("additional_keys", {}) |
| 86 | + for additional_key, value in additional_keys.items(): |
| 87 | + data[additional_key] = value |
| 88 | + return data |
| 89 | + |
| 90 | + def _send_notification(self, data: dict) -> Response: |
| 91 | + url = data.pop("rest_url") |
| 92 | + response, errors = requests.post(url, json=data) |
| 93 | + return self.create_response(data, response, errors) |
0 commit comments