alerta / alerta-contrib

Contributed integrations, plugins and custom webhooks
http://alerta.io
MIT License
119 stars 170 forks source link

Added mapping from alert attributes to 1..n teams channel #358

Open SimoneFalzone opened 3 years ago

SimoneFalzone commented 3 years ago

Problem: Currently it is not possible to send alarms to multiple channels. Also, it is not possible to filter alarms based on their attributes and assign them to a specific channel.

Proposal for a solution:

The MS_TEAMS_ALERT_WEBHOOK_MAPPING configuration variable can be used to form a mapping based on attribute values from an alert to a specific teams webhook. Also custom attributes are supported. For example:

MS_TEAMS_ALERT_WEBHOOK_MAPPING = [
    {
        "attributes" : {
            "event": "NodeDown",
        },
        "ms_teams_webhook": 'https://outlook.office.com/webhook/.../IncomingWebhook/.../...'
    },
        {
        "attributes" : {
            "custom_attribute_1": "custom_value_1",
            "custom_attribute_2": "custom_value_2",
            "severity": "critical",
        },
        "ms_teams_webhook": 'https://outlook.office.com/webhook/.../IncomingWebhook/.../...'
    }
]

If all attributes of an alarm are matched for multiple mappings, the alarm is sent to each matching channel.

jjh74 commented 3 years ago

I like this idea, you could probably do the same with routing plugin, but with this there's no need to code the logic in routing plugin.

Is MS_TEAMS_WEBHOOK_URL used as a default/catchall channel ? If so could you explain that in README.md. Is it possible to all attributes from https://docs.alerta.io/en/latest/api/alert.html#attributes to do matching/mapping ?

(Slack plugin seems to use configuration ending in _MAP, so perhaps MS_TEAMS_ALERT_WEBHOOK_MAP instead of MAPPING ?)

SimoneFalzone commented 3 years ago

@jjh74

Is MS_TEAMS_WEBHOOK_URL used as a default/catchall channel ? If so could you explain that in README.md. Is it possible to all attributes from https://docs.alerta.io/en/latest/api/alert.html#attributes to do matching/mapping ?

Yes it can be used as default channel. I have added the missing documentation.

(Slack plugin seems to use configuration ending in _MAP, so perhaps MS_TEAMS_ALERT_WEBHOOK_MAP instead of MAPPING ?)

Good point that I have not seen that. I renamed the MS_TEAMS_ALERT_WEBHOOK_MAPPING to MS_TEAMS_ALERT_WEBHOOK_MAP.

SimoneFalzone commented 3 years ago

Hey @jjh74 any good news on this PR?

jjh74 commented 2 years ago

@SimoneFalzone Nick(@satterly ) maintains alerta. Perhaps Nick has some time to take a look at this.