我正在编写一个TickScript,该TickScript作用于一系列点,这些点可能恰好有两个结果。
结果是通过还是“不通过”(通常是NUM出口的某种变体)。
我拥有的脚本看起来像这样:
// RP: autogen
// Monitor the result of updates
// WARNING if the result is anything other than pass
batch
|query('''SELECT * FROM "mydb"."autogen"."measurement"''')
.period(25h)
.every(24h)
.groupBy('host')
|alert()
.id('kapacitor/{{ .TaskName }}/{{ .Group }}')
.infoReset(lambda: TRUE)
.warn(lambda: "result" != 'pass')
.message(
'{{ index .Tags "host" }}' +
'{{ if eq .Level "OK" }} are updating again.' +
'{{ else }}' +
'are failing to update.' +
'{{ end }}'
)
.idField('id')
.levelField('level')
.messageField('description')
.stateChangesOnly()
@alertFilterAdapter()
@alertFilter()
该脚本似乎确实可以完成其工作,但是存在一个关键问题,那就是永远不要将Level设置回OK。
如果我进食这4点:
time host name result
---- ---- ---- ------
1544079584447374994 fakeS176 /usr/bin/yum update -y pass
1544079584447374994 fakeS177 /usr/bin/yum update -y exit 1
1544129084447375177 fakeS176 /usr/bin/yum update -y exit 1
1544129084447375177 fakeS177 /usr/bin/yum update -y pass
我希望收到1条警告和1条OK。上面列出的所有时间戳都在25小时内。
但是实际上发生的是我收到2条警告,但没有任何反应。
有人可以就前进的方向提供一些建议吗?
答案 0 :(得分:0)
更新-一位同事告诉我一个我不知道的节点。添加一个last()节点并添加一个as(),然后删除infoReset()节点似乎可以做到这一点。
// RP: autogen
// Monitor the result of updates
// WARNING if the result is anything other than pass
batch
|query('''SELECT * FROM "mydb"."autogen"."measurement"''')
.period(25h)
.every(24h)
.groupBy('host')
|last('result')
.as('result')
|alert()
.id('kapacitor/{{ .TaskName }}/{{ .Group }}')
.warn(lambda: "result" != 'pass')
.message(
'{{ index .Tags "host" }}' +
'{{ if eq .Level "OK" }} are updating again.' +
'{{ else }}' +
'are failing to update.' +
'{{ end }}'
)
.idField('id')
.levelField('level')
.messageField('description')
.stateChangesOnly()
@alertFilterAdapter()
@alertFilter()
拧开这种爆炸的语言。