Page 1 of 1

curl, json and -d query

Posted: Fri Mar 19, 2021 4:55 am
by nov1c3
Hello,

I'd like to monitoring the value of count (if it's 0 then trigger CRITICAL) from the following curl command:

Code: Select all

curl -u login:pass 192.168.100.9:9200/events/_count?pretty=true -H 'Content-Type: application/json' -d'{"query": {"range": {"recordTime": {"gte": "now-12h"}}}}'

{
  "count" : 2073,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  }
}
I tried several check_json plugins, but I can't figure out how to pass -d'{"query": {"range": {"recordTime": {"gte": "now-12h"}}}}'.

Any tips would be greatly appreciated. I'm using Nagios Core 4.4.6 under Debian 10.

Thank you.

Re: curl, json and -d query

Posted: Fri Mar 19, 2021 2:29 pm
by mcapra
jq is pretty dope IMO. Widely available on many linux distros via the package manager. Easy to stuff in a Bash script. Feed your cURL output into it, do a simple -eq evaluation afterwards.

Re: curl, json and -d query

Posted: Mon Mar 22, 2021 4:14 am
by nov1c3
Thank you!