chronograf icon indicating copy to clipboard operation
chronograf copied to clipboard

Chronograf/Kapacitor tick exec script - argument passing

Open tmihaldinec opened this issue 3 years ago • 1 comments

Hi Chronograf Version: 1.9.1 Kapacitor OSS 1.6.4

We created tick script which should send message to Microfocus opcmsg tool which with argments sends alerts. For this we created python script which should take argments from tick script:

in logs i see all data needed:

{"id":"Server CPU usage above 80%-host=server1.local","message":"host=server1.local CRITICAL Server CPU usage above 80%-host=server1.local cpu CRITICAL"

how can i pass arguments to this opcmsg python script

python', '/opt/opcmsg_alerting/opparser.py', arg1, arg2, arg3, arg4

where arg1 = var measurement = 'cpu' arg2 = var idVar = name + '-{{.Group}}' arg3 = var levelTag = 'level' arg4 = var message = '{{.Group}} {{.Level}} {{.ID}} {{.Name}} {{.Level}}'

and than opcmsg argemnts will be populated

i am not a programmer and i really dont know Go so please help Thanks tomislav

tmihaldinec avatar Oct 26 '22 09:10 tmihaldinec

update: in chronograf i created Tick script with this standard vars

var name = 'Server CPU usage above 80%' var message = '{{.Level}} {{.ID}}' var trigger = data |alert() .crit(lambda: "value" <= crit) .message(message) .id(idVar) .idTag(idTag) .levelTag(levelTag) .messageField(messageField) .durationField(durationField) .exec('/usr/bin/python', '/opt/opcmsg_alerting/opparser.py', name, message ) .log('/tmp/opcmsg.log')

in opparser script log i can see this output:

starting handler in opparser.py printing script args: ['Server CPU usage above 80%', '{{.Level}} {{.ID}}'] output:{} completed handler in opparser.py

but how to populate this name and message arguments with real vaules like: CRITICAL Server CPU usage above 80%-host=server01.local

which i see in opcmsg.log i defined in .log('/tmp/opcmsg.log')

{"id":"Server CPU usage above 80%-host=server01.local","message":"OK Server CPU usage above 80%-host=server01.local cpu","details":"","time":"2022-10-26T14:32:00Z","duration":90000000000,"level":"OK","data":{"series":[{"name":"cpu","tags":{"cpu":"cpu1","environment":"production","host":"server01.local","service":"mediation","vmtype":"vmware"},"columns":["time","usage_guest","usage_guest_nice","usage_iowait","usage_irq","usage_nice","usage_softirq","usage_steal","usage_system","usage_user","value"],"values":[["2022-10-26T14:32:00Z",0,0,1.7311608961421165,0,0,1.5274949083726768,0,11.20162932815274,48.77800407393906,36.76171079359716]]}]},"previousLevel":"CRITICAL","recoverable":true}

thanks

tmihaldinec avatar Oct 26 '22 14:10 tmihaldinec