Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chronograf/Kapacitor tick exec script - argument passing #6006

Open
tmihaldinec opened this issue Oct 26, 2022 · 1 comment
Open

Chronograf/Kapacitor tick exec script - argument passing #6006

tmihaldinec opened this issue Oct 26, 2022 · 1 comment

Comments

@tmihaldinec
Copy link

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
Copy link
Author

tmihaldinec commented Oct 26, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant