Hello,
I wanna know please if the webhook in the watcher send output in a JSON format ? cause I am getting some errors in my webhook and I don't know if it's because the output is not in JSON format, or cause I didn't know how to create a webhook test.
I have configured a small webhook just to test, and the configuration looks like that:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from flask import json
from flask import request
from flask import Flask
import re
app = Flask(__name__)
@app.route('/')
def api_root():
return 'Webhook TEST'
@app.route('/webhook', methods=['POST'])
def api_webhook_messages():
my_info = json.loads(request.data)
print(json.dumps(my_info))
return 'Connection sucessful'
if __name__=='__main__':
app.run(port=8080, host='10.10.13.135',debug=True)
When I test it from Kibana I get a successful connection as it's shown in the picture bellow:
And the result in my webhook is working as expected, and show the result as below:
{"body": "test"}
10.13.81.254 - - [14/Dec/2020 09:10:37] "POST /webhook HTTP/1.1" 200 -
But when I configure the webhook directly in my watcher scipt I am getting an error :
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 2464, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 2450, in wsgi_app
response = self.handle_exception(e)
File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1867, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.8/dist-packages/flask/_compat.py", line 39, in reraise
raise value
File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.8/dist-packages/flask/_compat.py", line 39, in reraise
raise value
File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/opt/thehive/webhook3.py", line 20, in api_webhook_messages
my_info = json.loads(request.data)
File "/usr/local/lib/python3.8/dist-packages/flask/json/__init__.py", line 253, in loads
return _json.loads(s, **kwargs)
File "/usr/lib/python3/dist-packages/simplejson/__init__.py", line 535, in loads
return cls(encoding=encoding, **kw).decode(s)
File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 370, in decode
obj, end = self.raw_decode(s)
File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 400, in raw_decode
return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)