Need to send json in watcher webhook

alerting

(Bharat) #1

I want to send json data in body of watcher webhook. I am defining action like below

my json body should be like {'watcher_id':24}

The following action is returning 404 error.

"actions" : {
"my_webhook" : {
"webhook" : {
"method" : "POST",
"host" : "10.225.117.135",
"port" : 8001,
"path": "/gen/api/v1/watch",
"headers" : {
"Authorization" : "Bearer ROOM_TOKEN",
"Content-Type": "application/json"
},
"body" : "watcher_id: {{ctx.payload.hits.total}}"
}
}
}

Please suggest correct way of sending json in webhook body.


(Bharat) #2

Detailed info:
Errors + logs from my application goes to logstash in JSON format. From Logstash, the messages are stored in elasticsearch. I am running watcher on elastic search. If the condition "watcher_id" is "test", then action can be triggered at 10second interval. The action is webhook. I want to send json data in webhook to remote Django rest server. As per the below configuration, the rest request goes to django rest server goes. But Django rest server returns back 404 error to the watcher. I could see this in output of watcher records. Sample output is given in output part(2)

Even though I gave header as json in action, the django rest server interpreted as text/html. The django rest server has model defined with watcher_id as primary field. There is no error in django rest server. I could admin GUI and post data in django admin GUI.

I tried different combinations for body field to send in json from watcher webhook action. But nothing is successful.

output part (1)
{
"trigger": {
"schedule": {
"interval": "10s"
}
},
"input": {
"search": {
"request": {
"indices": [
"mysecond"
],
"body": {
"query": {
"match": {
"watcher_id": "test"
}
}
}
}
}
},
"condition": {
"compare": {
"ctx.payload.hits.total": {
"gt": 0
}
}
},
"actions": {
"my_webhook": {
"webhook": {
"method": "POST",
"host": "10.225.117.135",
"port": 8001,
"path": "/gen/api/v1/watch",
"headers": {
"Authorization": "Bearer ROOM_TOKEN",
"Content-Type": "application/json"
},
"body": "watcher_id: {{ctx.payload.hits.total}}"
}
}
}
}

output part (2)
"actions": [
{
"id": "my_webhook",
"type": "webhook",
"status": "failure",
"reason": "received [404] status code",
"webhook": {
"request": {
"host": "10.225.117.135",
"port": 8001,
"scheme": "http",
"method": "post",
"path": "/gen/api/v1/watch",
"headers": {
"Authorization": "Bearer ROOM_TOKEN",
"Content-Type": "application/json"
},
"body": "watcher_id: 940"
},
"response": {
"status": 404,
"headers": {
"content-type": [
"text/html"
],
"server": [
"WSGIServer/0.1 Python/2.7.6"
],
"date": [
"Mon, 13 Jun 2016 17:50:36 GMT"
],
"vary": [
"Cookie"
]
}
}
}
}
]


(Alexander Reelsen) #3

Hey,

as already stated in another thread, please use proper formatting, otherwise helping is hard.

The error 404 is returned by your webserver and means the resource/HTTP endpoint (/gen/api/v1/watch) does not exist, which can happen, but it also means that this is not a watcher issue. You should check if the endpoint is reachable using curl (or another HTTP client of your choice) and the parameters from the watch.

--Alex


(Pransh) #4

@spinscale Hi

I want to send the complete payload as a JSON output via webhook, is it possible?

Please let me know

Regards


(Alexander Reelsen) #5

Hey,

please open new topics if you have a question instead of reopening months old topics. Also one message is enough.

What you are searching for has been released with Elasticsearch 2.4.0. It is the #{{toJson}} helper, see https://www.elastic.co/guide/en/elasticsearch/reference/2.4/search-template.html#_converting_parameters_to_json

--Alex


(system) #6