0
votes

I know it's possible to send post with json body in alert notification(like here Bosun send alert specifc data via json post body)

But since post with json is now deprecated in Influx I wonder if it's possible to send a post with --data-binary to write a status to specific influx series whenever an alert occurs. Writing to influx with post:

curl -i -XPOST 'http://localhost:8086/write?db=mydb' --data-binary 'cpu_load_short,host=server01,region=us-west value=0.64 1434055562000000000'

more on writing to influx: https://influxdb.com/docs/v0.9/guides/writing_data.html

Thanks in advance

1

1 Answers

2
votes

Have you tried just setting the body of the post notification? When testing the curl command you listed above I believe it is still using content-type application/x-www-form-urlencoded which is the default for notifications. I think this would work:

notification influx{
    post = http://localhost:8086/write?db=mydb
    body = cpu_load_short,host=server01,region=us-west value=0.64 1434055562000000000
}

If you need to customize the values you would have to get the subject to render the correct text and use {{.}} to inject it into the post notification.

template influx.testing {
    subject = `
        {{ if .IsEmail }}
            normal email template details here
        {{else}}
            {{.Group.host}} value={{.Eval .Alert.Vars.value_variable | printf "%.2f"}} {{.State.Touched.UnixNano}}
        {{end}}`
    body = `email body details here`
}

notification influx{
    post = http://localhost:8086/write?db=mydb
    body = cpu_load_short,region=us-west,host={{.}}
}

The post subject would be server01 value=0.64 1434055562000000000 assuming $value_variable is an expression that returns the 0.64 value.

also note when testing in the rule page last touched is always 0 so the timestamp would be -6795364578871345152 but it should work correctly for actual alerts.