-
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #401 from alonm-totango/master
- Loading branch information
Showing
6 changed files
with
210 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
from ..core import Provider | ||
from ..core import Response | ||
from ..utils import requests | ||
|
||
|
||
class VictorOps(Provider): | ||
"""Send VictorOps webhook notifications""" | ||
|
||
base_url = "https://portal.victorops.com/ui/{ORGANIZATION_ID}/incidents" | ||
site_url = "https://portal.victorops.com/dash/{ORGANIZATION_ID}#/advanced/rest" | ||
name = "victorops" | ||
|
||
_required = { | ||
"required": [ | ||
"rest_url", | ||
"message_type", | ||
"entity_id", | ||
"entity_display_name", | ||
"message", | ||
] | ||
} | ||
_schema = { | ||
"type": "object", | ||
"properties": { | ||
"rest_url": { | ||
"type": "string", | ||
"format": "uri", | ||
"title": "the REST URL to use with routing_key. create one in victorops `integrations` tab.", | ||
}, | ||
"message_type": { | ||
"type": "string", | ||
"title": "severity level can be: " | ||
"- critical or warning: Triggers an incident " | ||
"- acknowledgement: sends Acknowledgment to an incident " | ||
"- info: Creates a timeline event but doesn't trigger an incident " | ||
"- recovery or ok: Resolves an incident", | ||
"enum": [ | ||
"critical", | ||
"warning", | ||
"acknowledgement", | ||
"info", | ||
"recovery", | ||
"ok", | ||
], | ||
}, | ||
"entity_id": { | ||
"type": "string", | ||
"title": "Unique id for the incident for aggregation ,Acknowledging, or resolving.", | ||
}, | ||
"entity_display_name": { | ||
"type": "string", | ||
"title": "Display Name in the UI and Notifications.", | ||
}, | ||
"message": { | ||
"type": "string", | ||
"title": "This is the description that will be posted in the incident.", | ||
}, | ||
"annotations": { | ||
"type": "object", | ||
"patternProperties": { | ||
"^vo_annotate.u.": {"type": "string"}, | ||
"^vo_annotate.s.": {"type": "string"}, | ||
"^vo_annotate.i.": {"type": "string"}, | ||
}, | ||
"minProperties": 1, | ||
"title": "annotations can be of three types: " | ||
"vo_annotate.u.{custom_name}, " | ||
"vo_annotate.s.{custom_name}, " | ||
"vo_annotate.i.{custom_name} .", | ||
"additionalProperties": False, | ||
}, | ||
"additional_keys": { | ||
"type": "object", | ||
"title": "any additional keys that can be passed in the body", | ||
}, | ||
}, | ||
"additionalProperties": False, | ||
} | ||
|
||
def _prepare_data(self, data: dict) -> dict: | ||
annotations = data.pop("annotations", {}) | ||
for annotation, value in annotations.items(): | ||
data[annotation] = value | ||
|
||
additional_keys = data.pop("additional_keys", {}) | ||
for additional_key, value in additional_keys.items(): | ||
data[additional_key] = value | ||
return data | ||
|
||
def _send_notification(self, data: dict) -> Response: | ||
url = data.pop("rest_url") | ||
response, errors = requests.post(url, json=data) | ||
return self.create_response(data, response, errors) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
VictorOps (REST) | ||
-------------------- | ||
|
||
Send `VictorOps <https://alert.victorops.com/integrations/generic>`_ rest integration notifications. | ||
|
||
Minimal example: | ||
|
||
.. code-block:: python | ||
>>> from notifiers import get_notifier | ||
>>> victorops = get_notifier('victorops') | ||
>>> victorops.notify(rest_url='https://alert.victorops.com/integrations/generic/20104876/alert/f7dc2eeb-ms9k-43b8-kd89-0f00000f4ec2/$routing_key', | ||
message_type='CRITICAL', | ||
entity_id='foo testing', | ||
entity_display_name="bla test title text", | ||
message="bla message description") | ||
Full schema: | ||
|
||
.. code-block:: yaml | ||
additionalProperties: false | ||
properties: | ||
rest_url: | ||
type: string | ||
format: uri | ||
title: the REST URL to use with routing_key, create one in victorops integrations tab. | ||
message_type: | ||
type: string | ||
title: severity level can be: | ||
- critical or warning: Triggers an incident | ||
- acknowledgement: Acks an incident | ||
- info: Creates a timeline event but doesn't trigger an incident | ||
- recovery or ok: Resolves an incident | ||
entity_id: | ||
type: string | ||
title: Unique id for the incident for aggregation acking or resolving. | ||
entity_display_name: | ||
type: string | ||
title: Display Name in the UI and Notifications. | ||
message: | ||
type: string | ||
title: This is the description that will be posted in the incident. | ||
annotations: | ||
type: object | ||
format: | ||
vo_annotate.s.{custom_name}: annotation | ||
vo_annotate.u.{custom_name}: annotation | ||
vo_annotate.i.{custom_name}: annotation | ||
title: annotations can be of three types vo_annotate.u.{custom_name} vo_annotate.s.{custom_name} vo_annotate.i.{custom_name}. | ||
additional_keys: | ||
type: object | ||
format: | ||
key: value | ||
key: value | ||
key: value | ||
title: any additional keys that ca be passed in the body | ||
required: | ||
- rest_url | ||
- message_type | ||
- entity_id | ||
- entity_display_name | ||
- message | ||
type: object | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import os | ||
|
||
import pytest | ||
|
||
provider = "victorops" | ||
|
||
|
||
class TestVicrotops: | ||
""" | ||
Victorops rest alert tests | ||
Online test rely on setting the env variable VICTOROPS_REST_URL | ||
""" | ||
|
||
@pytest.mark.online | ||
def test_all_options(self, provider): | ||
VICTOROPS_REST_URL = os.getenv("VICTOROPS_REST_URL") | ||
data = { | ||
"rest_url": VICTOROPS_REST_URL, | ||
"message_type": "info", | ||
"entity_id": "BA tesing", | ||
"entity_display_name": "message test header", | ||
"message": "text in body", | ||
"annotations": { | ||
"vo_annotate.i.Graph": "https://shorturl.at/dAQ28", | ||
"vo_annotate.s.Note": "'You can't have everything. Where would you put it?' Steven Wright", | ||
"vo_annotate.u.Runbook": "https://giphy.com/gifs/win-xNBcChLQt7s9a/fullscreen", | ||
}, | ||
"additional_keys": { | ||
"foo": "this is a custom fields", | ||
"monitoring_tool": "this is an official victorops fields", | ||
}, | ||
} | ||
rsp = provider.notify(**data) | ||
assert rsp.ok | ||
assert rsp.status == "Success" | ||
assert rsp.errors is None |