alerta / alerta-contrib

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

MS_TEAMS webhook ? #280

Closed jjh74 closed 5 years ago

jjh74 commented 5 years ago

Hello,

I'm interested in writing a msteams webhook (so it would be possible to add "possibleactions" (ack, close, blackout buttons) to msteams messages). Adding the buttons is fairly easy (probably needs few helper functions to pymsteams(issues 45 and 44)), but I have few questions about the alerta webhook part:

satterly commented 5 years ago

Webhooks can return anything that flask supports so yes, you can return custom headers. See the description of this PR https://github.com/alerta/alerta/pull/844

Webhooks can authenticate using basic auth, API key or Bearer token. I suggest an API key passed as a header X-API-Key

jjh74 commented 5 years ago

Thanks, I'll take a look at the PR.

One follow up question, I'm assuming that alerta/webhooks/custom.py L19 (@permission(Scope.write_webhooks)) takes care of checking X-API-Key and the webhook doesn't have to do it ?

I see one possible problem with alerta/auth/decorators.py: MSteams sends Authorization: Bearer ... header so permission() doesn't look for X-API-Key if it first sees Authorization header ? Perhaps L27 could be: if 'Authorization' in request.headers and request.headers['Authorization'].find('Key ', 0, 4) == 0:

satterly commented 5 years ago

Alerta does the work of verifying the request before calling the custom webhook.

Yes, I see a potential problem there if an Authorization header is passed but should be ignored. Perhaps L32 could be if not key and ...

jjh74 commented 5 years ago

Thanks, L32 change should also work. I'll create a PR if/when I have something usable. I'll close this issue for now.