0

我知道可以在警报通知中发送带有 json body 的帖子(就像这里Bosun 通过 json post body 发送警报特定数据

但是由于现在 Influx 不推荐使用带有 json 的帖子,我想知道是否可以发送带有 --data-binary 的帖子,以便在发生警报时将状态写入特定的涌入系列。写作涌入帖子:

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

更多关于写入涌入:https ://influxdb.com/docs/v0.9/guides/writing_data.html

提前致谢

4

1 回答 1

2

您是否尝试过设置帖子通知的正文?在测试上面列出的 curl 命令时,我相信它仍在使用 content-type application/x-www-form-urlencoded,这是通知的默认设置。我认为这会起作用:

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

如果您需要自定义值,则必须让主题呈现正确的文本并使用 {{.}} 将其注入到发布通知中。

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={{.}}
}

帖子主题将server01 value=0.64 1434055562000000000假设 $value_variable 是一个返回 0.64 值的表达式。

另请注意,在最后一次触摸的规则页面中进行测试时始终为 0,因此时间戳将为 -6795364578871345152,但对于实际警报,它应该可以正常工作。

于 2015-11-19T18:47:09.327 回答