custom webhook always returns http400
See original GitHub issueHoping for some guidance with a custom webhook i’m trying to implement to use with Kentik. Kentik is a very popular NetFlow SaaS app.
Version info root@alerta-dev:~# /opt/alerta/bin/alerta version alerta 7.3.0 alerta client 7.3.0
Install info
- Ubuntu 18.04
- MongoDB
- self hosted
- nginx/uwsgi
- No auth
Webhook code
from typing import Any, Dict
import json
from alerta.models.alert import Alert
from alerta.webhooks import WebhookBase
JSON = Dict[str, Any]
class KentikWebhook(WebhookBase):
"""
Kentik
https://kb.kentik.com/Gc04.htm#Gc04-JSON_Notification_Settings
"""
def incoming(self, query_string, payload):
if payload['AlarmState'] == 'ALARM':
severity = 'critical'
else:
severity = 'normal'
return Alert(
resource=payload['AlertPolicyName'],
event=payload['AlarmID'],
environment='Production',
severity=severity,
group='Network',
origin='Kentik',
raw_data=payload
)
setup.py
from setuptools import setup, find_packages
version = '5.0.19'
setup(
name="alerta-kentik",
version=version,
description='Alerta webhook for Kentik',
url='http://localhost/',
license='',
author='',
author_email='',
packages=find_packages(),
py_modules=['alerta_kentik'],
install_requires=[
],
include_package_data=True,
zip_safe=True,
entry_points={
'alerta.webhooks': [
'kentik = alerta_kentik:KentikWebhook'
]
}
)
It seems to install just fine:
python setup.py install
running install
running bdist_egg
running egg_info
writing alerta_kentik.egg-info/PKG-INFO
writing dependency_links to alerta_kentik.egg-info/dependency_links.txt
writing entry points to alerta_kentik.egg-info/entry_points.txt
writing top-level names to alerta_kentik.egg-info/top_level.txt
file alerta_kentik.py (for module alerta_kentik) not found
reading manifest file 'alerta_kentik.egg-info/SOURCES.txt'
writing manifest file 'alerta_kentik.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
file alerta_kentik.py (for module alerta_kentik) not found
file alerta_kentik.py (for module alerta_kentik) not found
creating build/bdist.linux-x86_64/egg
copying build/lib/alerta_kentik.py -> build/bdist.linux-x86_64/egg
copying build/lib/alerta_sentry.py -> build/bdist.linux-x86_64/egg
byte-compiling build/bdist.linux-x86_64/egg/alerta_kentik.py to alerta_kentik.cpython-36.pyc
byte-compiling build/bdist.linux-x86_64/egg/alerta_sentry.py to alerta_sentry.cpython-36.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying alerta_kentik.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying alerta_kentik.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying alerta_kentik.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying alerta_kentik.egg-info/entry_points.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying alerta_kentik.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying alerta_kentik.egg-info/zip-safe -> build/bdist.linux-x86_64/egg/EGG-INFO
creating 'dist/alerta_kentik-5.0.19-py3.6.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing alerta_kentik-5.0.19-py3.6.egg
Copying alerta_kentik-5.0.19-py3.6.egg to /opt/alerta/lib/python3.6/site-packages
Removing alerta-kentik 5.0.18 from easy-install.pth file
Adding alerta-kentik 5.0.19 to easy-install.pth file
Installed /opt/alerta/lib/python3.6/site-packages/alerta_kentik-5.0.19-py3.6.egg
Processing dependencies for alerta-kentik==5.0.19
Finished processing dependencies for alerta-kentik==5.0.19
I see this in the logs when restarting uwsgi:
{"name": "alerta.app", "levelno": 20, "levelname": "INFO", "pathname": "/opt/alerta/lib/python3.6/site-packages/alerta/utils/webhook.py", "filename": "webhook.py", "module": "webhook", "lineno": 31, "funcName": "register", "created": 1564080005.5671494, "thread": 140252583941952, "threadName": "MainThread", "process": 4065, "message": "Server webhook 'kentik' loaded."}
And i see the webhook loaded under http://my-alerta-server/api/webhooks/kentik
So everything seems fine, but no matter what the response is always a 400.
I’m testing with something simple like this:
curl -XPOST http://localhost/api/webhooks/kentik -H 'Content-type: application/json' -d '{ "AlarmID": "1234", "AlertPolicyName": "BlahBlahBlah", "AlarmState": "ALARM" }'
No matter what, the response is always:
root@alerta-dev:/opt/alerta# curl -XPOST http://localhost/api/webhooks/kentik -H 'Content-type: application/json' -d '{
"AlarmID": "1234",
"AlertPolicyName": "BlahBlahBlah",
"AlarmState": "ALARM"
}'
{
"code": 400,
"errors": null,
"message": "'data'",
"requestId": null,
"status": "error"
}
Any suggestions would be greatly appreciated
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
the pip method does seem to work better. Thanks for the pointers
Ahh. Instead of
python setup.py install
try usingpip install -e .
– I think that is better for dynamically picking up code changes. Or try runningpython setup.py install
again whenever you change the code.