alerta / alerta-contrib

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

Sentry webhook test failing #304

Closed FloSew closed 4 years ago

FloSew commented 4 years ago

The test on Sentry webhook is failing.

Test result:

[in C:\Projects\alerta\alerta-contrib\venv\lib\site-packages\alerta\webhooks\__init__.py:23]
2019-12-18 12:18:47,888 - alerta.plugins[10936]: WARNING - [POLICY] Alert environment does not match one of Production, Staging, Sandbox [in C:\Projects\alerta\alerta-contrib\venv\lib\site-packages\alerta\plugins\reject.py:32]

201 != 403

Expected :403
Actual   :201

self = <test_sentry.SentryWebhookTestCase testMethod=test_sentry_webhook>
first = 403, second = 201, msg = None

    def _patched_equals(self, first, second, msg=None):
        try:
>           old(self, first, second, msg)

I have custom environments: ALLOWED_ENVIRONMENTS=['Production','Staging', 'Sandbox']

I didn't understand at first because I still had Production in the list, so it should be working. But then, digging a little I found this in alerta_sentry.py:

        if payload.get('event')['sentry.interfaces.Http']['env'] == 'prod':
            environment = 'Production'
        else:
            environment = 'Development'

The condition is always False because payload.get('event')['sentry.interfaces.Http']['env'] is wrong. We should do payload.get('event')['sentry.interfaces.Http']['env']['ENV'] which is what is in the payload.

I'll do a PR to correct this.

satterly commented 4 years ago

Thanks for the fixes. 😃

FloSew commented 4 years ago

@satterly You are welcome 😃