curl, json and -d query

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
nov1c3
Posts: 3
Joined: Fri Mar 19, 2021 3:33 am

curl, json and -d query

Post 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.
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: curl, json and -d query

Post 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.
Former Nagios employee
https://www.mcapra.com/
nov1c3
Posts: 3
Joined: Fri Mar 19, 2021 3:33 am

Re: curl, json and -d query

Post by nov1c3 »

Thank you!
Locked