Coder Social home page Coder Social logo

check_http_json's Introduction

Bonjour 👋

Hi there! I'm Dan (phrawzty on all the things). I have previously done computer stuff at Scaleway, Datadog, Mozilla, and Ubisoft. I'm also a Global Core member of the devopsdays conference series. My pronouns are he / him. Ask me about time zones or French wine! 😀

check_http_json's People

Contributors

candux avatar dbenesj avatar jonasverhofste avatar kohenkatz avatar kwolf avatar phrawzty avatar project0 avatar slawekp avatar stepanstipl avatar xorpaul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

check_http_json's Issues

Optionally return performance data

Please consider adding the ability to specify 'performance attributes' to be returned, ex "-p attr1,attr2" would result in:

OK: xxxx|attr1=122565 attr2=97443921 as extracted from the JSON.

Issue Parsing JSON

I'm attempting to pull the Graylog status JSON for the cluster using the check script but despite the output of a -v showing the content I'm looking for, it's returning a "not found in response" reply.

Example:

root@munged:/usr/lib/nagios/plugins# ./check_http_json -u 'http://munged:12900/cluster?pretty=true' --user 'munged' --pass 'token' -e 'facility' -r 'graylog-server' -v
+ RESPONSE:
---
{
  "3d5326a9-f09d-4c8e-9d16-ea70add94bb2" : {
    "facility" : "graylog-server",
    "codename" : "Stiegl",
    "node_id" : "3d5326a9-f09d-4c8e-9d16-ea70add94bb2",
    "cluster_id" : "72649b5c-ff32-4365-909d-5edee2f56311",
    "version" : "2.2.3+7adc951",
    "started_at" : "2017-07-18T20:52:26.859Z",
    "hostname" : "munged",
    "lifecycle" : "running",
    "lb_status" : "alive",
    "timezone" : "America/Chicago",
    "operating_system" : "Linux 3.13.0-121-generic",
    "is_processing" : true
  }
}
---
WARN: facility not found in response.

I've removed and added the ?pretty=true, but used it in the example to make it easier to read. The item is there, it's spelled correctly, just not sure why it's not responding? Thanks!

Add delimiter argument

As noted in my comment on issue #6, it would be handy to allow the element delimiter (currently a period) to be specified via an argument. It must default to a period in order to preserve the expected behaviour.

error if protocol is not present in Uri

When calling script with uri parameter which does not contain protocol, e.g.
./check_http_json.rb -v -u 'node.office.de:9200/_cluster/health' -e number_of_data_nodes -c 2:2 -w 2:2
there's an error displayed:
+ Exception occured: undefined method 'request_uri' for #<URI::Generic:0x7fe0b41e5770>.
UNKNOWN: HTTP connection failed.
My guess would be that request_uri is not present if protocol is absent, so we can not start timeout request.

HTTPS exception

When using HTTPS with this check I get an exception:

./check_http_json.rb:153:in `uri_target': undefined method `use_ssl=' for #<Net::HTTP box.example.com:443 open=false> (NoMethodError)
    from ./check_http_json.rb:371

I think there are 2 solutions to this problem. (and a 3rd just for fun)

  1. Add require 'net/https' to the top of the file
  2. Change the Net::HTTP instantiation to pass in use_ssl and remove the use_ssl = true line (then you get an OpenSSL constant error so you have to add require 'openssl' at the top, too):
    http = Net::HTTP.new(uri.host, uri.port, :use_ssl => uri.scheme == 'https')

    if uri.scheme == 'https' then
        http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    end
  1. Change to rest_client because it's awesome ;)

warning when running on windows host

Windows: Windows Server 2008 R2
ruby: 2.7.1
check_http_json from the master branch

C:\Program Files\NSClient++\scripts>check_http_json.rb -u http://localhost:1701/
status -E CpuUsage -w 40 -c 100 -p CpuUsage
C:/Program Files/NSClient++/scripts/check_http_json.rb:605: warning: deprecated
Object#=~ is called on Float; it always returns nil
OK: First 'CpuUsage' (regex) within treshold W:40 C:100 | CpuUsage=14.0619164304
68136

Performance Counters

Hello,

firstly: Thank you phrawzty for your great script!

Unfortunately I am not able to retrieve the performance values I need.

This is working:

check_http_json.rb -u 'http://x/jolokia/read/jboss.as:subsystem=datasources,data-source=*,statistics=pool/ActiveCount' -E '^ActiveCount' -w 5 -c 10 --element_regex_global -p request.type
OK: All 'ActiveCount' (regex) within treshold W:5 C:10 | request.type=read

But this do not give any performance values:

check_http_json.rb -u 'http://x/jolokia/read/jboss.as:subsystem=datasources,data-source=*,statistics=pool/ActiveCount' -E '^ActiveCount' -w 5 -c 10 --element_regex_global -p value.jboss.as:data-source=product1,statistics=pool,subsystem=datasources.ActiveCount
OK: All 'ActiveCount' (regex) within treshold W:5 C:10 |

this is my json:

{
  "timestamp": 1515660256,
  "status": 200,
  "request": {
    "mbean": "jboss.as:data-source=*,statistics=pool,subsystem=datasources",
    "attribute": "ActiveCount",
    "type": "read"
  },
  "value": {
    "jboss.as:data-source=product1,statistics=pool,subsystem=datasources": {
      "ActiveCount": 0
    },
    "jboss.as:data-source=product2,statistics=pool,subsystem=datasources": {
      "ActiveCount": 0
    },
    "jboss.as:data-source=product3,statistics=pool,subsystem=datasources": {
      "ActiveCount": 0
    }
  }
}

Not actually an issue...

Was unsure of the best way to simply ask you a question, so I jumped to here.

Just for my own edification, since this was my first contribution to someone else's project, is there anything I can do to make my name in the "Commits" listing go back to my github account (like yours do)?

I'm not asking for you to change anything; just curious if I could do something differently to make it link back to my profile if/when I contribute to someone else's project again.

Thanks,
Jay

feature request: performance data

First of thanks for this plugin, super useful to me, there is one little thing that would improve my config of this plugin a lot as im monitoring larger arrays with a lot of subarrays.

let's say i have a simple array

{
"Main": {
"Sub1": 1,
"Sub2": 2
}
}

at the moment i would have to specify Main.Sub1,Main.Sub2 to get all "Sub" elements. this is okey for small arrays for bigger arrays it would be easier to simply specifiy -p Main ( and then get all Sub elements automatically ) or maybe even a -p Main.* to get all of them.

I don't know ruby at all but i think this could easily be achived with some small if around

# If performance metrics have been requested...
here

keep up the good work!

Escape or remove pipes in plugin output

On using pipes (|) in regex the performance label will have wrong names:

# /srv/icinga/linux/check_http_json.rb -u http://heizung:4321/xyz1/all -e pe1.L_state -R "^(1|2|3|4|5|99)$" --perf "pe1.L_usb_stick" 
OK: 'pe1.L_state' (regex) does match ^(1|2|3|4|5|99)$ | system.L_usb_stick=0

image

Define Host

How would the Host config look like for Nagios?

Possible bug with arrays

Given the following JSON structure, I do not get the expected results:

{"tests":[{"name":"valueAddGiftCard","time":1240,"valid":true},{"name":"chargeGiftCard","time":218,"valid":true},{"name":"lookupGiftCard","time":2454,"valid":true}]}

I would expect to be able to reference the name of a given element as so:
tests.0.name (valueAddGiftCard) and
tests.1.valid (true)

The actual result is that you only get tests.<key> such as tests.name which actually equals the last element in the array - tests.name equals lookupGiftCard.

Is this expected, or is this a bug?

Is there a way to check multiple values?

from @mimmus:

I have:

{
"units": [
{
"id": "service1",
"health": 0,
},
{
"id": "service2",
"health": 0,
},
....
{
"id": "serviceN",
"health": 0,
}
]
}

What's the best way to check that ALL health keys are equal to 0?

Dynamic Perf Counters

Hello,

Would it be possible to get all Perf Counters by one query without know the perf value exactly?

For now it is working with that query:

check_http_json.rb -u 'xx' -E 'ActiveCount' -w 5 -c 10 --element_regex_global -p value§jboss.as:data-source=productx,statistics=pool,subsystem=datasources§ActiveCount?value§jboss.as:data-source=producty,statistics=pool,subsystem=datasources§ActiveCount?value§jboss.as:data-source=db2-productz,statistics=pool,subsystem=datasources§ActiveCount -d § --perf_splitter=?

But I do not really always know the names of the products like 'productx', 'producty' etc. so I need to get the value for all products as perf counters.

Json:

{
  "timestamp": 1515998720,
  "status": 200,
  "request": {
    "mbean": "jboss.as:data-source=*,statistics=pool,subsystem=datasources",
    "attribute": "ActiveCount",
    "type": "read"
  },
  "value": {
    "jboss.as:data-source=productx,statistics=pool,subsystem=datasources": {
      "ActiveCount": 0
    },
    "jboss.as:data-source=producty,statistics=pool,subsystem=datasources": {
      "ActiveCount": 0
    },
    "jboss.as:data-source=db2-productz,statistics=pool,subsystem=datasources": {
      "ActiveCount": 0
    }
  }
}

Return critical error upon 404 response

Hi,

It would be useful for us if the check could return a critical error if the URL responds with a 404.
At the moment it's returning a warning and I can't see a way to make it critical from the available options.

Thanks.

If response is array of ints, only the last int is evaluated

$ cat ~/blah.txt
[
   {
      "datapoints" : [
            0,
            1457976120
      ]
   }
]

$ ruby work/nagios_config/plugins/check_http_json.rb -f ~/blah.txt -c 4 -w 10 -v -e datapoints
+ The value of datapoints is: 1457976120
CRIT: datapoints is above threshold value 4 (1457976120)

$ ruby work/nagios_config/plugins/check_http_json.rb -f ~/blah.txt -c 4 -w 10 -v -e datapoints.0
WARN: datapoints.0 not found in response.  
$ ruby work/nagios_config/plugins/check_http_json.rb -f ~/blah.txt -c 4 -w 10 -v -e datapoints.1
WARN: datapoints.1 not found in response. 

I'm trying to catch the first int in the response array (the '0').

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.