How to POST json when the alert occur , Kapacitor/Chronogaf?

kapacitor

#1

Hi,

When an alert happen i would like to do
"curl -X PUT "http://192.168.0.1/ssapi/zb/dev/1/ldev/smartplug/data/onoff" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"value\": false}""

or simply post some json to http://192.168.1.73/ssapi/zb/dev/1/ldev/smartplug/data/onoff

Where should the above information go ?

Thanks


#2

Hi @BhanuKiran

You can define an httppost handler for Kapacitor as follows:

[[httppost]]
  endpoint = "onoff"
  url = "http://192.168.0.1/ssapi/zb/dev/1/ldev/smartplug/data/onoff"
  headers = { "Content-Type" = "application/json" }
  alert-template = "{{.Message}}:{{range .Data.Series}}{{.Tags}},{{range .Values}}{{.}}{{end}}{{end}}"
  row-template = "{{.Name}} host={{index .Tags \"host\"}}{{range .Values}} {{index . "time"}} {{index . "value"}}{{end}}"

This can then be utilised in your TICKscript:

|alert()
  // ...  
  .post()
    .endpoint('onoff')

You can find out more about this within our documentation.

Thanks,
Hope this helps!


#3

Hi @rawkode,

I really appreciate your response. I am completely new to these and went through the documentation but couldn’t understand the nuances between alert-template and row-template.

In my case , I just need to send json { "value": false} ,but i don’t understand where( alert-template/row-template) and how to put it ?

Thanks


#4

Hey @BhanuKiran,

If you don’t need a template message, you can hard code what you require:

alert-template = "{ \"value\": false }"

#5

Hi @rawkode,

I had a problem when i placed the above script in Kapacitor configuration file. I am using the sandbox and the kapacitor Docker is exiting exiting instantly after restarting the sandbox and i have posted the question in here.

Thanks