question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

custom webhook always returns http400

See original GitHub issue

Hoping 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:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lucasalvatorecommented, Jul 26, 2019

the pip method does seem to work better. Thanks for the pointers

0reactions
satterlycommented, Jul 26, 2019

Ahh. Instead of python setup.py install try using pip install -e . – I think that is better for dynamically picking up code changes. Or try running python setup.py install again whenever you change the code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webhook - modify response code based on criteria [GOT ...
For example: If an entry with some id already exists, webhook should return http 400; If an entry with some id does not...
Read more >
ChargeeBee webhook HTTP 400 Error - Chargebee Support
I am trying to test my Spring Boot Java based rest controller to receive Chargebee webhook notifications. Here is my code: ```. @RestController....
Read more >
Stripe ASP.NET Core Webhook always returns BadRequest
The FulfillOrder fails and throws error, which leads to a jump into the catch block, from where HTTP 400 is returned.
Read more >
Any **custom** webhook for Mattermost returns error 400
Normal Mattermost integration works fine. Steps to reproduce. Just add a custom webhook via "Add webhook" and try to test it.
Read more >
Sending messages using Incoming Webhooks - Slack API
Incoming webhooks return more expressive errors than our Web API, including more relevant HTTP status codes (like "HTTP 400 Bad Request" and "HTTP...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found