Giter Site home page Giter Site logo

drewkerrigan / nagios-http-json Goto Github PK

View Code? Open in Web Editor NEW
66.0 66.0 58.0 179 KB

A generic plugin for Nagios which checks json values from a given HTTP endpoint against argument specified rules and determines the status and performance data for that service.

License: Other

Python 99.40% Makefile 0.60%

nagios-http-json's Introduction

CI

Nagios Json Plugin

This is a generic plugin for Nagios which checks json values from a given HTTP endpoint against argument specified rules and determines the status and performance data for that service.

Links

CLI Usage

Executing ./check_http_json.py -h will yield the following details:

usage: check_http_json.py [-h] [-d] [-s] -H HOST [-k] [-V] [--cacert CACERT]
                          [--cert CERT] [--key KEY] [-P PORT] [-p PATH]
                          [-t TIMEOUT] [-B AUTH] [-D DATA] [-A HEADERS]
                          [-f FIELD_SEPARATOR] [-F VALUE_SEPARATOR]
                          [-w [KEY_THRESHOLD_WARNING [KEY_THRESHOLD_WARNING ...]]]
                          [-c [KEY_THRESHOLD_CRITICAL [KEY_THRESHOLD_CRITICAL ...]]]
                          [-e [KEY_LIST [KEY_LIST ...]]]
                          [-E [KEY_LIST_CRITICAL [KEY_LIST_CRITICAL ...]]]
                          [-q [KEY_VALUE_LIST [KEY_VALUE_LIST ...]]]
                          [-Q [KEY_VALUE_LIST_CRITICAL [KEY_VALUE_LIST_CRITICAL ...]]]
                          [-u [KEY_VALUE_LIST_UNKNOWN [KEY_VALUE_LIST_UNKNOWN ...]]]
                          [-y [KEY_VALUE_LIST_NOT [KEY_VALUE_LIST_NOT ...]]]
                          [-Y [KEY_VALUE_LIST_NOT_CRITICAL [KEY_VALUE_LIST_NOT_CRITICAL ...]]]
                          [-m [METRIC_LIST [METRIC_LIST ...]]]

Check HTTP JSON Nagios Plugin

Generic Nagios plugin which checks json values from a given endpoint against
argument specified rules and determines the status and performance data for
that service.

Version: 2.2.0 (2024-05-14)

options:
  -h, --help            show this help message and exit
  -d, --debug           debug mode
  -v, --verbose         Verbose mode. Multiple -v options increase the verbosity
  -s, --ssl             use TLS to connect to remote host
  -H HOST, --host HOST  remote host to query
  -k, --insecure        do not check server SSL certificate
  -X {GET,POST}, --request {GET,POST}
                        Specifies a custom request method to use when communicating with the HTTP server
  -V, --version         print version of this plugin
  --cacert CACERT       SSL CA certificate
  --cert CERT           SSL client certificate
  --key KEY             SSL client key ( if not bundled into the cert )
  -P PORT, --port PORT  TCP port
  -p PATH, --path PATH  Path
  -t TIMEOUT, --timeout TIMEOUT
                        Connection timeout (seconds)
  --unreachable-state UNREACHABLE_STATE
                        Exit with specified code if URL unreachable. Examples: 1 for Warning, 2 for Critical, 3 for Unknown (default: 3)
  -B AUTH, --basic-auth AUTH
                        Basic auth string "username:password"
  -D DATA, --data DATA  The http payload to send as a POST
  -A HEADERS, --headers HEADERS
                        The http headers in JSON format.
  -f SEPARATOR, --field_separator SEPARATOR
                        JSON Field separator, defaults to "."; Select element in an array with "(" ")"
  -F VALUE_SEPARATOR, --value_separator VALUE_SEPARATOR
                        JSON Value separator, defaults to ":"
  -w [KEY_THRESHOLD_WARNING ...], --warning [KEY_THRESHOLD_WARNING ...]
                        Warning threshold for these values (key1[>alias],WarnRange key2[>alias],WarnRange). WarnRange is in the format
                        [@]start:end, more information at nagios-plugins.org/doc/guidelines.html.
  -c [KEY_THRESHOLD_CRITICAL ...], --critical [KEY_THRESHOLD_CRITICAL ...]
                        Critical threshold for these values (key1[>alias],CriticalRange key2[>alias],CriticalRange. CriticalRange is in
                        the format [@]start:end, more information at nagios-plugins.org/doc/guidelines.html.
  -e [KEY_LIST ...], --key_exists [KEY_LIST ...]
                        Checks existence of these keys to determine status. Return warning if key is not present.
  -E [KEY_LIST_CRITICAL ...], --key_exists_critical [KEY_LIST_CRITICAL ...]
                        Same as -e but return critical if key is not present.
  -q [KEY_VALUE_LIST ...], --key_equals [KEY_VALUE_LIST ...]
                        Checks equality of these keys and values (key[>alias],value key2,value2) to determine status. Multiple key values
                        can be delimited with colon (key,value1:value2). Return warning if equality check fails
  -Q [KEY_VALUE_LIST_CRITICAL ...], --key_equals_critical [KEY_VALUE_LIST_CRITICAL ...]
                        Same as -q but return critical if equality check fails.
  -u [KEY_VALUE_LIST_UNKNOWN ...], --key_equals_unknown [KEY_VALUE_LIST_UNKNOWN ...]
                        Same as -q but return unknown if equality check fails.
  -y [KEY_VALUE_LIST_NOT ...], --key_not_equals [KEY_VALUE_LIST_NOT ...]
                        Checks equality of these keys and values (key[>alias],value key2,value2) to determine status. Multiple key values
                        can be delimited with colon (key,value1:value2). Return warning if equality check succeeds
  -Y [KEY_VALUE_LIST_NOT_CRITICAL ...], --key_not_equals_critical [KEY_VALUE_LIST_NOT_CRITICAL ...]
                        Same as -q but return critical if equality check succeeds.
  -m [METRIC_LIST ...], --key_metric [METRIC_LIST ...]
                        Gathers the values of these keys (key[>alias], UnitOfMeasure,WarnRange,CriticalRange,Min,Max) for Nagios
                        performance data. More information about Range format and units of measure for nagios can be found at nagios-
                        plugins.org/doc/guidelines.html Additional formats for this parameter are: (key[>alias]),
                        (key[>alias],UnitOfMeasure), (key[>alias],UnitOfMeasure,WarnRange, CriticalRange).

Examples

Key Naming

Data for key value:

{ "value": 1000 }

Data for key capacity.value:

{
    "capacity": {
        "value": 1000
    }
}

Data for key (0).capacity.value:

[
    {
        "capacity": {
            "value": 1000
        }
    }
]

Data for keys of all items in a list (*).capacity.value:

[
    {
        "capacity": {
            "value": 1000
        }
    },
    {
        "capacity": {
            "value": 2200
        }
    }
]

Data for separator -f _ and key (0)_gauges_jvm.buffers.direct.capacity_value:

[
    {
        "gauges": {
            "jvm.buffers.direct.capacity":
                "value": 1000
            }
        }
    }
]

Data for keys ring_members(0), ring_members(1), ring_members(2):

Thresholds and Ranges

Data:

{ "metric": 1000 }

Relevant Commands

  • Warning: ./check_http_json.py -H <host>:<port> -p <path> -w "metric,RANGE"

  • Critical: ./check_http_json.py -H <host>:<port> -p <path> -c "metric,RANGE"

  • Metrics with Warning: ./check_http_json.py -H <host>:<port> -p <path> -w "metric,RANGE"

  • Metrics with Critical:

      ./check_http_json.py -H <host>:<port> -p <path> -w "metric,,,RANGE"
      ./check_http_json.py -H <host>:<port> -p <path> -w "metric,,,,MIN,MAX"
    

Range Definitions

  • Format: [@]START:END
  • Generates a Warning or Critical if...
    • Value is less than 0 or greater than 1000: 1000 or 0:1000
    • Value is greater than or equal to 1000, or less than or equal to 0: @1000 or @0:1000
    • Value is less than 1000: 1000:
    • Value is greater than 1000: ~:1000
    • Value is greater than or equal to 1000: @1000:

More info about Nagios Range format and Units of Measure can be found at https://nagios-plugins.org/doc/guidelines.html.

Using Headers

  • ./check_http_json.py -H <host>:<port> -p <path> -A '{"content-type": "application/json"}' -w "metric,RANGE"

Nagios Installation

Requirements

  • Python 3.6+

Configuration

Assuming a standard installation of Nagios, the plugin can be executed from the machine that Nagios is running on.

cp check_http_json.py /usr/local/nagios/libexec/plugins/check_http_json.py
chmod +x /usr/local/nagios/libexec/plugins/check_http_json.py

Add the following service definition to your server config (localhost.cfg):


define service {
        use                             local-service
        host_name                       localhost
        service_description             <command_description>
        check_command                   <command_name>
        }

Add the following command definition to your commands config (commands.config):


define command{
        command_name    <command_name>
        command_line    /usr/bin/python /usr/local/nagios/libexec/plugins/check_http_json.py -H <host>:<port> -p <path> [-e|-q|-w|-c <rules>] [-m <metrics>]
        }

Icinga2 configuration

The Icinga2 command definition can be found here: (contrib/icinga2_check_command_definition.conf)

License

Copyright 2014-2015 Drew Kerrigan.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

nagios-http-json's People

Contributors

alesc avatar artschwagerb avatar bb-ricardo avatar billmoritz avatar drewkerrigan avatar k0nne avatar kovacshuni avatar luban8 avatar martialblog avatar martinsura avatar marxin avatar nejec avatar peon-pasado-zeitnot avatar riton avatar roobert avatar thmshmm 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nagios-http-json's Issues

how to add $SERVICEEXECUTIONTIME$ to output of check_http_json

hi, I want to import $SERVICEEXECUTIONTIME$ param to pnp, so I can get a graphic overview of my api cost.

And I check the format that pnp can parse, I must add $SERVICEEXECUTIONTIME$ to output of check_http_json.

Is it right? If so , how can I manage it ?

401 Unauthorized should not be OK

Pretty much the title. There is no indication to the user if a request is not authorized, instead giving an OK exit code. This could lead to false monitoring data if the user does not realize their mistake.

Include API Method

Hi,
right now the script uses only the Method GET. We have now some API-Calls which requires instead of GET a POST Method.
In our case no further parameters are needed. The return data is in json format an contains only "value: 12345".
Would be great to add a parameter where it can be switched between GET and POST.
Thx

Replace deprecated encodestring

While adding pylint to the CI, I notices that encodestring() is used.

check_http_json.py:589:24: W1505: Using deprecated method encodestring() (deprecated-method)

PERFDATA : nagios status code

Hello
Is that possible to add an optionnal perfdata for nagios status code ?
this would make it possible to monitor the validity of the probe in boolean mode: 0 for a CRITICAL status and 1 for an OK status.
availability can be calculated either on a threshold or on an anomaly in reading the URL
Thank's

Enhanced plugin output without critical information

Hello,

is it possible to add a switch to enhance the plugin output with the pprint'ed json object?
I know this is already part of the debug switch, but we cant use -d, because we need to hide the used credentials, which are part of the -d output.

Bytes encoding issue

Hello, I had an issue with the encoding, I got some json_data as 'bytes' and not 'str':

./check_http_json.py -H X.X.X.X -P **** -p 'path' -f '.count' -c '...:' -t 15 -k
Traceback (most recent call last):
  File "check_http_json.py", line 644, in <module>
    main(sys.argv[1:])
  File "check_http_json.py", line 623, in main
    data = json.loads(json_data)
  File "/usr/lib/python3.5/json/__init__.py", line 312, in loads
    s.__class__.__name__))
TypeError: the JSON object must be str, not 'bytes'

JSON received:
b'{"count": 167}'

I resolved it by catching the encoding:

      json_data = response.read()
+     encoding = response.info().get_content_charset('utf-8')
...
-        data = json.loads(json_data)
+        data = json.loads(json_data.decode(encoding))

SSL as argument with yes/no value

I'd like to pass a yes/no to the -s Argument. Then I only have to have one command and would be able to set SSL on/off in the host.

key with brackets ()

We have a status, which contains a key like
"last data received (minutes)", i.e. the key string contains round brackets.

If i try to address this key, the array-selection mechanism kicks in. Can i somehow quote "(" and ")"?

IndexError when multiple array elements are expected

Hello Drew,

we tried to monitor our consul system with this check, which works great except the json response of consul is empty. For example consul responds with an empty json if both of two services are shut down which we want to end in a critical status.

Here is an example:

First we get two json documents and a critical status from the script:

console> ./check_http_json.py -H localhost -P 8500 -p /v1/health/service/myservice -q "(0).Node,servera" "(1).Node,serverb" -Q "(0).Status,passing" -E "(0).Status" -d
url:http://localhost:8500//v1/health/service/myservice
json:
[{u'Checks': [{u'CheckID': u'serfHealth',
               u'CreateIndex': 1589745,
               u'ModifyIndex': 1590432,
               u'Name': u'Serf Health Status',
               u'Node': u'servera',
               u'Notes': u'',
               u'Output': u'Agent alive and reachable',
               u'ServiceID': u'',
               u'ServiceName': u'',
               u'Status': u'passing'},
              {u'CheckID': u'service:b474927e-28ba-43d1-b4d8-e94bb4302adc',
               u'CreateIndex': 1591994,
               u'ModifyIndex': 1591995,
               u'Name': u"Service 'myservice' check",
               u'Node': u'servera',
               u'Notes': u'',
               u'Output': u'HTTP GET http://localhost:33000/ping: 200  Output: ',
               u'ServiceID': u'b474927e-28ba-43d1-b4d8-e94bb4302adc',
               u'ServiceName': u'myservice',
               u'Status': u'passing'}],
  u'Node': {u'Address': u'192.168.178.50',
            u'CreateIndex': 1589745,
            u'ModifyIndex': 1591995,
            u'Node': u'servera',
            u'TaggedAddresses': {u'wan': u'192.168.178.50'}},
  u'Service': {u'Address': u'',
               u'CreateIndex': 1591994,
               u'EnableTagOverride': False,
               u'ID': u'b474927e-28ba-43d1-b4d8-e94bb4302adc',
               u'ModifyIndex': 1591995,
               u'Port': 33000,
               u'Service': u'myservice',
               u'Tags': [u'Application',
                         u'develop',
                         u'b474927e-28ba-43d1-b4d8-e94bb4302adc']}},
{u'Checks': [{u'CheckID': u'serfHealth',
               u'CreateIndex': 1589964,
               u'ModifyIndex': 1590486,
               u'Name': u'Serf Health Status',
               u'Node': u'severb',
               u'Notes': u'',
               u'Output': u'Agent alive and reachable',
               u'ServiceID': u'',
               u'ServiceName': u'',
               u'Status': u'passing'},
              {u'CheckID': u'service:2aa34f51-6bdb-4ba7-91e8-2e3e7dcec66c',
               u'CreateIndex': 1591785,
               u'ModifyIndex': 1591788,
               u'Name': u"Service 'myservice' check",
               u'Node': u'severb',
               u'Notes': u'',
               u'Output': u'HTTP GET http://localhost:33000/ping: 200  Output: ',
               u'ServiceID': u'2aa34f51-6bdb-4ba7-91e8-2e3e7dcec66c',
               u'ServiceName': u'myservice',
               u'Status': u'passing'}],
  u'Node': {u'Address': u'192.168.178.50',
            u'CreateIndex': 1589964,
            u'ModifyIndex': 1591893,
            u'Node': u'severb',
            u'TaggedAddresses': {u'wan': u'192.168.178.50'}},
  u'Service': {u'Address': u'',
               u'CreateIndex': 1591785,
               u'EnableTagOverride': False,
               u'ID': u'2aa34f51-6bdb-4ba7-91e8-2e3e7dcec66c',
               u'ModifyIndex': 1591788,
               u'Port': 33000,
               u'Service': u'myservice',
               u'Tags': [u'Application',
                         u'develop',
                         u'2aa34f51-6bdb-4ba7-91e8-2e3e7dcec66c']}}]
rules:Namespace(auth=None, data=None, debug=True, headers=None, host='localhost', key_list=None, key_list_critical=['(0).Status'], key_threshold_critical=None, key_threshold_warning=None, key_value_list=['(0).Node,servera', '(1).Node,severb'], key_value_list_critical=['(0).Status,passing'], metric_list=None, path='/v1/health/service/myservice', port='8500', separator=None, ssl=False, timeout=None)
separator:.
CRITICAL: Status CRITICAL. Value for key (0).Node did not match servera. Value for key (1).Node did not match severb. Value for key (0).Status did not match passing. Key (0).Status did not exist.

Now we shut down one service so the second json document is empty, the script crashed:

console> ./check_http_json.py -H localhost -P 8500 -p /v1/health/service/myservice -q "(0).Node,servera" "(1).Node,severb" -Q "(0).Status,passing" -E "(0).Status" -d
url:http://localhost:8500//v1/health/service/myservice
json:
[{u'Checks': [{u'CheckID': u'serfHealth',
               u'CreateIndex': 1589745,
               u'ModifyIndex': 1590432,
               u'Name': u'Serf Health Status',
               u'Node': u'servera',
               u'Notes': u'',
               u'Output': u'Agent alive and reachable',
               u'ServiceID': u'',
               u'ServiceName': u'',
               u'Status': u'passing'},
              {u'CheckID': u'service:b474927e-28ba-43d1-b4d8-e94bb4302adc',
               u'CreateIndex': 1591994,
               u'ModifyIndex': 1591995,
               u'Name': u"Service 'myservice' check",
               u'Node': u'servera',
               u'Notes': u'',
               u'Output': u'HTTP GET http://localhost:33000/ping: 200  Output: ',
               u'ServiceID': u'b474927e-28ba-43d1-b4d8-e94bb4302adc',
               u'ServiceName': u'myservice',
               u'Status': u'passing'}],
  u'Node': {u'Address': u'192.168.178.50',
            u'CreateIndex': 1589745,
            u'ModifyIndex': 1591995,
            u'Node': u'servera',
            u'TaggedAddresses': {u'wan': u'192.168.178.50'}},
  u'Service': {u'Address': u'',
               u'CreateIndex': 1591994,
               u'EnableTagOverride': False,
               u'ID': u'b474927e-28ba-43d1-b4d8-e94bb4302adc',
               u'ModifyIndex': 1591995,
               u'Port': 33000,
               u'Service': u'myservice',
               u'Tags': [u'Application',
                         u'develop',
                         u'b474927e-28ba-43d1-b4d8-e94bb4302adc']}}]
rules:Namespace(auth=None, data=None, debug=True, headers=None, host='localhost', key_list=None, key_list_critical=['(0).Status'], key_threshold_critical=None, key_threshold_warning=None, key_value_list=['(0).Node,servera', '(1).Node,severb'], key_value_list_critical=['(0).Status,passing'], metric_list=None, path='/v1/health/service/myservice', port='8500', separator=None, ssl=False, timeout=None)
separator:.
Traceback (most recent call last):
  File "./check_http_json.py", line 437, in <module>
    nagios.append_warning(processor.checkWarning())
  File "./check_http_json.py", line 212, in checkWarning
    failure += self.checkEquality(self.rules.key_value_list)
  File "./check_http_json.py", line 163, in checkEquality
    if (self.helper.equals(key, v) == False):
  File "./check_http_json.py", line 99, in equals
    def equals(self, key, value): return self.exists(key) and str(self.get(key)) in value.split(':')
  File "./check_http_json.py", line 104, in exists
    def exists(self, key): return (self.get(key) != (None, 'not_found'))
  File "./check_http_json.py", line 117, in get
    return self.getSubArrayElement(key, data)
  File "./check_http_json.py", line 95, in getSubArrayElement
    return self.get(remainingKey, data[index])
IndexError: list index out of range

Looks like a bug to us.

Any ideas how to fix this?

Critical on HealthCheck Endpoint

Hi,
I have an healthchek endpoint in an application with boolean response, is there a way to have a critical status rather than warning if my healthcheck is false ?

/check_http_json.py  -H orion-ctrl-ofs-1.zsi.agri -P 8080 -p ofs/healthcheck -q "operationTime.healthy,False" "repository.healthy,False"
WARNING: Status check failed, reason: Value for key operationTime.healthy did not match False.

Thanks

Bug when thre is a colon in Key value

Script return : UNKNOWN: Status UNKNOWN.HTTPError[500] when I have brackets in key value.

Sample:

{
  "com.healthCheck" : {
    "healthy" : false,
    "message" : "Exe[mystate/303]: stopped"
  },
  "com.version" : {
    "healthy" : true,
    "message" : "10.23"
  },
  "com.Connection" : {
    "healthy" : true,
    "message" : "PostgreSQL 8.3.20 "
  }
}

Any idea ?

Bug if array element is 0

Hi!
First of all, thank you for that plugin!

I just wanted to start using it, when I stumbled across a possible bug:
I wanted to collect metrics of an integer value in an array and then found that if that value equals "0" the whole json is returned as metrics value.

I think the bug is in the get function:

        if temp_data:
            data = temp_data
        else:
            data = self.data

Since the value (in my case Integer 0) is passed to the get function as "temp_data" by getSubArrayElement, that check of temp_data returns "false".
I assumed that codeline is supposed to check if temp_data is empty and changed it to

        if temp_data != '':
            data = temp_data
        else:
            data = self.data

which seems to have fixed it.

multiple arrays and changing parameter names

Is there way to print out with -m parameter multiple values?

Currently following does not seem to be working:

-m "(0)_gauges_jvm.buffers.direct.capacity(0)_value,(0)_gauges_jvm.buffers.direct.capacity(1)_value" -f _

output:
'(0)_gauges_jvm.buffers.direct.capacity(0)_value'=215415(0)_gauges_jvm.buffers.direct.capacity(1)_value;0;0

EXAMPLE:
[
{ "gauges": { "jvm.buffers.direct.capacity": [{"value": 215415},{"value": 1234}]}}
]

Also it would be great if there was way to change parameter names:
'(0)_gauges_jvm.buffers.direct.capacity(0)_value' to etc "buffer_cappacity_0"

How to parse 0.0 values

HI

with -d option i get

'memory': [{'availableBytes': 5988585472.0,

how to set -c value to get alarm when the value is minor than 59885854

And how can set a -c values when the exit has a string value

'processName': 'ininedgecontrol'},

i need a alert when the ininedgecontro does not exists

Thanks for your help

Operators

Thank you for the great job with this project!

It would be nice to have option to use and operators.
It would produce critical only if both conditions are met.

Something like that:
-c "key1,1:10 & key2,1:5"
-c "key1,1:10" & -c "key2,1:5"

CRITICAL:
{
"key1": 1000,
"key2":6
}

NOT Critical:
{
"key1": 1000,
"key2":4
}

Problem with boolean value

Hello,

I have a health check request that returns the following json :
{ "deadlocks": {"healthy": true}, "hibernate": {"healthy": true} }

I tried to use the nagios http json plugin with the following configuration :
-q deadlocks.healthy,true
But it always return the same message:
WARNING: Status WARNING. Value for key deadlocks.healthy did not match true.

I don't understand why, what is the right configuration so that it consider "true" as matching ?

Key may not contain ,

Hi,
we are trying to use your plugin to monitor our ActiveMQ. Unfortunately the batch checking does not work and we now have to create one check / queue.

During the experiments we found that if one of the keys in your json contains a , the python script will fail in line 202 on the split().
E.g. ActiveMQ returns a status key of this form: "org.apache.activemq:brokerName=static-broker-1-master,destinationName=your-queue-name,destinationType=Queue,type=Broker"

As you can see this contians multiple , that you actually cannot get rid of.

There exists a workaround. If you specify the exact queue name and attribute you are looking for in the url the result will just contain a "value" key. This means no bulk checking, though...

What do you think? Is this worth a fix?

Add New Maintainer

Hey,

first of: great project. We're using it and it's great ๐Ÿ‘
However, given there there are no more updates recently, I'd suggest adding a new maintainer. So that there aren't endless forks and we can ensure new features.

Of course, I'd volunteer myself if you don't mind.

Cheers,
Markus

Adding a parameter to allow perf output on the status line

Hi Drew,

Would you be open to add a parameter so that the perf output also shows on the status information line? That way you don't need to go to the graph to see the value.

I always liked to be able to grasp the values directly from the status information without having to go down to the graph.

Thanks
Olivier

Unknown message handler fails with reference to `critical_message`

Looks like a copy-paste error here. The NagiosHelper.append_unknown() function takes an argument of unknown_message but tries to append critical_message to self.critical_message

One way that this is reproducible by passing a path that would return a 404:

Console 1

$ python -m SimpleHTTPServer
localhost.localdomain - - [19/Dec/2017 14:03:42] code 404, message File not found
localhost.localdomain - - [19/Dec/2017 14:03:42] "GET /management/health HTTP/1.1" 404 -

Console 2

$ ./check_http_json.py -H localhost:8000 -p management/health -q status,UP -f _ -d
Traceback (most recent call last):
  File "./check_http_json.py", line 421, in <module>
    nagios.append_unknown("HTTPError[%s], url:%s" % (str(e.code), url))
  File "./check_http_json.py", line 59, in append_unknown
    self.critical_message += critical_message
NameError: global name 'critical_message' is not defined

Cannot set verify_mode to CERT_NONE when check_hostname is enabled.

I get the following error:

[root@myhost ~]# ./check_http_json.py -H myhost -P 8443 -p rest/api/count?Type=failedTask -s -w count,@10: -c count,@10: -e count -k
Traceback (most recent call last):
  File "./check_http_json.py", line 651, in <module>
    main(sys.argv[1:])
  File "./check_http_json.py", line 553, in main
    context.verify_mode = ssl.CERT_NONE
  File "/usr/lib64/python3.6/ssl.py", line 443, in verify_mode
    super(SSLContext, SSLContext).verify_mode.__set__(self, value)
ValueError: Cannot set verify_mode to CERT_NONE when check_hostname is enabled.

And will provide a fix via a pull request.

Using --key-equals with an empty list returns OK

Trying to monitor the GitLab mirror status of some projects through the API. Since I don't know how many mirrors exist for a particular project, I use the 'data for keys of all items in a list' notation.

This works fine, but the check returns an OK status if the response is an empty list ([]). That would mean that if somebody accidentally removed all mirrors we would not be alerted.

Equality check used: -q "(*).update_status,finished"

translate working curl into correct attributes

I really tried my best:
curl is working perfect but check-http-json.py gives ConnectionResetError: [Errno 104] Connection reset by peer

curl --insecure --cert ~/private.crt --key ~/private.key -d '{}' -H "Content-Type: application/json" -X POST https://localhost:8567/info

check_http_json.py --debug --ssl --host localhost:8567 --insecure --cert ~/private.crt --key ~/private.key --path info --headers '{"content-type": "application/json"}' --key_exists success

I'm sure it's the -d '{}' from curl but I'm not allowed to use --data '{}' with the nagios-plugin here as there will be error
TypeError: POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str.

As far as I understood POST method is only used in connection with --data
otherwise it's always GET method

help is highly appreciated

Broken Makefile and lint test

Makefile uses python should be python3
and I got a lint error on Debian Bullseye and Ubuntu Focal Fossa:
python3 -m pylint check_http_json.py
************* Module check_http_json
check_http_json.py:614:0: E0012: Bad option value 'consider-using-with' (bad-option-value)

Http 403

Hi, i'm trying to use the plugin but i get a 403 using both http and https: UNKNOWN: Status UNKNOWN.HTTPError[403].
The full url given back in the output works fine when used with wget or any browser from the same machine.

Tried adding ** -A '{"content-type": "application/json"}'** but same result.
Any ideas?

Need help.

It's possible to handle that type of json response ?

./check_http_json.py -d -s -H test.service-now.com -p "/api/now/table/ecc_agent?sysparm_query=name=aname&sysparm_fields=status&sysparm_view=" -B "username:Passw0rd" -c "????"
url:https://test.service-now.com//api/now/table/ecc_agent?sysparm_query=name=aname&sysparm_fields=status&sysparm_view=
json:
{u'result': [{u'status': u'Up'}]}
rules:Namespace(auth='username:Passw0rd', data=None, debug=True, headers=None, host='test.service-now.com', key_list=None, key_list_critical=None, key_threshold_critical=['result.status,Up'], key_threshold_warning=None, key_value_list=None, key_value_list_critical=None, metric_list=None, path='/api/now/table/ecc_agent?sysparm_query=name=aname&sysparm_fields=status&sysparm_view=', port=None, separator=None, ssl=True, timeout=None)
separator:.
OK: Status OK.

The response of ServiceNOW is {u'result': [{u'status': u'Up'}]} and I want to setup critical if status is Up for testing.

Thank you!!!

json starting with square bracket

How to access specific JSON field when json is starting with square bracket?

Example:
[
{ "gauges": { "jvm.buffers.direct.capacity": {"value": 215415}}}
]

Key equality check fails if key contains ":"

It seems that colon ":" breaks key equality checking which causes many problems especially with keys containing URL:s.

To reproduce the issue we use testing api https://jsonplaceholder.typicode.com/photos/1

./check_http_json.py -s -d -H jsonplaceholder.typicode.com -p photos/1 -Q url,http://placehold.it/600/92c952

At the moment of writing the api returns:

{
albumId: 1,
id: 1,
title: "accusamus beatae ad facilis cum similique qui sunt",
url: "http://placehold.it/600/92c952",
thumbnailUrl: "http://placehold.it/150/92c952"
}

outputs the following:

url:https://jsonplaceholder.typicode.com/photos/1
json:
{u'albumId': 1,
 u'id': 1,
 u'thumbnailUrl': u'http://placehold.it/150/92c952',
 u'title': u'accusamus beatae ad facilis cum similique qui sunt',
 u'url': u'http://placehold.it/600/92c952'}
rules:Namespace(auth=None, data=None, debug=True, headers=None, host='jsonplaceholder.typicode.com', key_list=None, key_list_critical=None, key_threshold_critical=None, key_threshold_warning=None, key_value_list=None, key_value_list_critical=['url,http://placehold.it/600/92c952'], metric_list=None, path='photos/1', port=None, separator=None, ssl=True, timeout=None)
separator:.
CRITICAL: Status CRITICAL. Value for key url did not match http://placehold.it/600/92c952.

The code on the line 99 which is

def equals(self, key, value): return self.exists(key) and str(self.get(key)) in value.split(':')

seems to be the cause of this issue.

I'm running Python 2.7.5

License for this plugin?

Hi there -- I just came across this plugin, and I'd like to use it -- but can you let me know what license it's released under? (I'm happy to throw out GPLv3 as a suggestion, but that's just me.)

Thanks very much for your time!

Can't seem to handle json attribute names with dots in them

I'm trying to fetch data from dropwizards metrics page, this is a sample of what it looks like:

{
"gauges": {
"jvm.buffers.direct.capacity": {"value": 215415},

I've tried: ./check_http_json.py -H localhost:8081 -p metrics --key_exists gauges.jvm.buffers.direct.capacity.values
but I guess the problem is that the script thinks that jvm this is a nested structure like this:

{"guages": { "jvm": { "buffers": { etc etc

Is it possible to somehow mark that jvm.buffers.direct.capacity is a key or something?

Plugins3

Hey @drewkerrigan:

Would you mind if this plugin was included in nagios-plugins 3 as a plugins-python/contrib kind of thing?

I have some cool ideas in mind to make the next major release pretty awesome, and I'd like to start with this plugin!

What are your thoughts?

OK results do not show Performance Data

When a service is in a warning or critical state the plugin returns the value that generated the alert in the Nagios Web GUI as well as in performance data. However when a service is in a good state the web interface just shows "OK: Status OK." (although Performance Data is populated as expected)

It would be very useful for those of us who use the WebGUI for system status displays if we could get the value that resulted in an "OK" to display, not just when Warning or Critical

Problem checking json output on Elasticsearch server

I'm having an issue where I can't figure out how to the the nodes.ZFI8avwBSZCEF59qI5LQvw.jvm.mem.heap_used_percent element. The problem is the field ZFI8avwBSZCEF59qI5LQvw will be different for each server I hit, and depending how much Elasticsearch cluster scales, I have no way of knowing what it is. How can I make this work?

#./check_http_json.py -H integration-search001 -P 9200 -p "_nodes/integration-search001/stats" -f _ -e "nodes_(0)_jvm.mem.heap_used_percent" -d
url:http://integration-search001:9200/_nodes/integration-search001/stats
json:
{u'_nodes': {u'failed': 0, u'successful': 1, u'total': 1},
 u'cluster_name': u'integration-search',
 u'nodes': {u'ZFI8avwBSZCEF59qI5LQvw': {u'attributes': {u'ml.enabled': u'true'},
                                        u'breakers': {u'fielddata': {u'estimated_size': u'1.5kb',
                                                                     u'estimated_size_in_bytes': 1560,
                                                                     u'limit_size': u'2.3gb',
                                                                     u'limit_size_in_bytes': 2566520832,
                                                                     u'overhead': 1.03,
                                                                     u'tripped': 0},
                                                      u'in_flight_requests': {u'estimated_size': u'0b',
                                                                              u'estimated_size_in_bytes': 0,
                                                                              u'limit_size': u'3.9gb',
                                                                              u'limit_size_in_bytes': 4277534720,
                                                                              u'overhead': 1.0,
                                                                              u'tripped': 0},
                                                      u'parent': {u'estimated_size': u'1.5kb',
                                                                  u'estimated_size_in_bytes': 1560,
                                                                  u'limit_size': u'2.7gb',
                                                                  u'limit_size_in_bytes': 2994274304,
                                                                  u'overhead': 1.0,
                                                                  u'tripped': 0},
                                                      u'request': {u'estimated_size': u'0b',
                                                                   u'estimated_size_in_bytes': 0,
                                                                   u'limit_size': u'2.3gb',
                                                                   u'limit_size_in_bytes': 2566520832,
                                                                   u'overhead': 1.0,
                                                                   u'tripped': 0}},
                                        u'discovery': {u'cluster_state_queue': {u'committed': 0,
                                                                                u'pending': 0,
                                                                                u'total': 0}},
                                        u'fs': {u'data': [{u'available_in_bytes': 94561394688,
                                                           u'free_in_bytes': 99946668032,
                                                           u'mount': u'/var/lib/elasticsearch (/dev/mapper/elastic-elastic)',
                                                           u'path': u'/var/lib/elasticsearch/integration-search001/nodes/0',
                                                           u'spins': u'false',
                                                           u'total_in_bytes': 105551003648,
                                                           u'type': u'ext4'}],
                                                u'io_stats': {u'devices': [{u'device_name': u'dm-0',
                                                                            u'operations': 158156893,
                                                                            u'read_kilobytes': 8456332,
                                                                            u'read_operations': 83477,
                                                                            u'write_kilobytes': 2262981964,
                                                                            u'write_operations': 158073416}],
                                                              u'total': {u'operations': 158156893,
                                                                         u'read_kilobytes': 8456332,
                                                                         u'read_operations': 83477,
                                                                         u'write_kilobytes': 2262981964,
                                                                         u'write_operations': 158073416}},
                                                u'timestamp': 1507212261634,
                                                u'total': {u'available_in_bytes': 94561394688,
                                                           u'free_in_bytes': 99946668032,
                                                           u'total_in_bytes': 105551003648}},
                                        u'host': u'10.10.193.88',
                                        u'http': {u'current_open': 14,
                                                  u'total_opened': 305250},
                                        u'indices': {u'completion': {u'size_in_bytes': 0},
                                                     u'docs': {u'count': 21387902,
                                                               u'deleted': 402641},
                                                     u'fielddata': {u'evictions': 0,
                                                                    u'memory_size_in_bytes': 1560},
                                                     u'flush': {u'total': 205,
                                                                u'total_time_in_millis': 21076},
                                                     u'get': {u'current': 0,
                                                              u'exists_time_in_millis': 0,
                                                              u'exists_total': 0,
                                                              u'missing_time_in_millis': 0,
                                                              u'missing_total': 0,
                                                              u'time_in_millis': 0,
                                                              u'total': 0},
                                                     u'indexing': {u'delete_current': 0,
                                                                   u'delete_time_in_millis': 0,
                                                                   u'delete_total': 0,
                                                                   u'index_current': 0,
                                                                   u'index_failed': 0,
                                                                   u'index_time_in_millis': 22506919,
                                                                   u'index_total': 42364721,
                                                                   u'is_throttled': False,
                                                                   u'noop_update_total': 0,
                                                                   u'throttle_time_in_millis': 0},
                                                     u'merges': {u'current': 0,
                                                                 u'current_docs': 0,
                                                                 u'current_size_in_bytes': 0,
                                                                 u'total': 617509,
                                                                 u'total_auto_throttle_in_bytes': 2272534385,
                                                                 u'total_docs': 9899704139,
                                                                 u'total_size_in_bytes': 2400154791963,
                                                                 u'total_stopped_time_in_millis': 0,
                                                                 u'total_throttled_time_in_millis': 55731,
                                                                 u'total_time_in_millis': 1434961775},
                                                     u'query_cache': {u'cache_count': 2795,
                                                                      u'cache_size': 2715,
                                                                      u'evictions': 80,
                                                                      u'hit_count': 14499,
                                                                      u'memory_size_in_bytes': 19427570,
                                                                      u'miss_count': 82309,
                                                                      u'total_count': 96808},
                                                     u'recovery': {u'current_as_source': 0,
                                                                   u'current_as_target': 0,
                                                                   u'throttle_time_in_millis': 1085},
                                                     u'refresh': {u'listeners': 0,
                                                                  u'total': 6008781,
                                                                  u'total_time_in_millis': 97187070},
                                                     u'request_cache': {u'evictions': 0,
                                                                        u'hit_count': 15099,
                                                                        u'memory_size_in_bytes': 4662964,
                                                                        u'miss_count': 4056},
                                                     u'search': {u'fetch_current': 0,
                                                                 u'fetch_time_in_millis': 1437,
                                                                 u'fetch_total': 84,
                                                                 u'open_contexts': 0,
                                                                 u'query_current': 0,
                                                                 u'query_time_in_millis': 81129,
                                                                 u'query_total': 38204,
                                                                 u'scroll_current': 0,
                                                                 u'scroll_time_in_millis': 0,
                                                                 u'scroll_total': 0,
                                                                 u'suggest_current': 0,
                                                                 u'suggest_time_in_millis': 0,
                                                                 u'suggest_total': 0},
                                                     u'segments': {u'count': 505,
                                                                   u'doc_values_memory_in_bytes': 7935196,
                                                                   u'file_sizes': {},
                                                                   u'fixed_bit_set_memory_in_bytes': 2635568,
                                                                   u'index_writer_memory_in_bytes': 0,
                                                                   u'max_unsafe_auto_id_timestamp': 1507161603687,
                                                                   u'memory_in_bytes': 19966429,
                                                                   u'norms_memory_in_bytes': 87296,
                                                                   u'points_memory_in_bytes': 888639,
                                                                   u'stored_fields_memory_in_bytes': 1928192,
                                                                   u'term_vectors_memory_in_bytes': 0,
                                                                   u'terms_memory_in_bytes': 9127106,
                                                                   u'version_map_memory_in_bytes': 0},
                                                     u'store': {u'size_in_bytes': 5513072482,
                                                                u'throttle_time_in_millis': 0},
                                                     u'translog': {u'operations': 20262,
                                                                   u'size_in_bytes': 18824115},
                                                     u'warmer': {u'current': 0,
                                                                 u'total': 2585213,
                                                                 u'total_time_in_millis': 2277747}},
                                        u'ingest': {u'pipelines': {u'xpack_monitoring_2': {u'count': 0,
                                                                                           u'current': 0,
                                                                                           u'failed': 0,
                                                                                           u'time_in_millis': 0},
                                                                   u'xpack_monitoring_6': {u'count': 0,
                                                                                           u'current': 0,
                                                                                           u'failed': 0,
                                                                                           u'time_in_millis': 0}},
                                                    u'total': {u'count': 0,
                                                               u'current': 0,
                                                               u'failed': 0,
                                                               u'time_in_millis': 0}},
                                        u'ip': u'10.10.193.88:9300',
                                        u'jvm': {u'buffer_pools': {u'direct': {u'count': 53,
                                                                               u'total_capacity_in_bytes': 68183017,
                                                                               u'used_in_bytes': 68183018},
                                                                   u'mapped': {u'count': 1294,
                                                                               u'total_capacity_in_bytes': 5500104160,
                                                                               u'used_in_bytes': 5500104160}},
                                                 u'classes': {u'current_loaded_count': 14327,
                                                              u'total_loaded_count': 14388,
                                                              u'total_unloaded_count': 61},
                                                 u'gc': {u'collectors': {u'old': {u'collection_count': 1584,
                                                                                  u'collection_time_in_millis': 117924},
                                                                         u'young': {u'collection_count': 725521,
                                                                                    u'collection_time_in_millis': 20444535}}},
                                                 u'mem': {u'heap_committed_in_bytes': 4277534720,
                                                          u'heap_max_in_bytes': 4277534720,
                                                          u'heap_used_in_bytes': 2124974840,
                                                          u'heap_used_percent': 49,
                                                          u'non_heap_committed_in_bytes': 170213376,
                                                          u'non_heap_used_in_bytes': 161598824,
                                                          u'pools': {u'old': {u'max_in_bytes': 4120510464,
                                                                              u'peak_max_in_bytes': 4120510464,
                                                                              u'peak_used_in_bytes': 4079527400,
                                                                              u'used_in_bytes': 2115473832},
                                                                     u'survivor': {u'max_in_bytes': 17432576,
                                                                                   u'peak_max_in_bytes': 17432576,
                                                                                   u'peak_used_in_bytes': 17432576,
                                                                                   u'used_in_bytes': 1253136},
                                                                     u'young': {u'max_in_bytes': 139591680,
                                                                                u'peak_max_in_bytes': 139591680,
                                                                                u'peak_used_in_bytes': 139591680,
                                                                                u'used_in_bytes': 8247872}}},
                                                 u'threads': {u'count': 77,
                                                              u'peak_count': 101},
                                                 u'timestamp': 1507212261633,
                                                 u'uptime_in_millis': 2407678598},
                                        u'name': u'integration-search001',
                                        u'os': {u'cpu': {u'load_average': {u'15m': 0.0,
                                                                           u'1m': 0.0,
                                                                           u'5m': 0.0},
                                                         u'percent': 5},
                                                u'mem': {u'free_in_bytes': 398741504,
                                                         u'free_percent': 5,
                                                         u'total_in_bytes': 8373026816,
                                                         u'used_in_bytes': 7974285312,
                                                         u'used_percent': 95},
                                                u'swap': {u'free_in_bytes': 0,
                                                          u'total_in_bytes': 0,
                                                          u'used_in_bytes': 0},
                                                u'timestamp': 1507212261633},
                                        u'process': {u'cpu': {u'percent': 4,
                                                              u'total_in_millis': 531482350},
                                                     u'max_file_descriptors': 65536,
                                                     u'mem': {u'total_virtual_in_bytes': 12712378368},
                                                     u'open_file_descriptors': 357,
                                                     u'timestamp': 1507212261633},
                                        u'roles': [u'master',
                                                   u'data',
                                                   u'ingest'],
                                        u'script': {u'cache_evictions': 0,
                                                    u'compilations': 1},
                                        u'thread_pool': {u'bulk': {u'active': 0,
                                                                   u'completed': 7524444,
                                                                   u'largest': 2,
                                                                   u'queue': 0,
                                                                   u'rejected': 0,
                                                                   u'threads': 2},
                                                         u'fetch_shard_started': {u'active': 0,
                                                                                  u'completed': 23,
                                                                                  u'largest': 4,
                                                                                  u'queue': 0,
                                                                                  u'rejected': 0,
                                                                                  u'threads': 1},
                                                         u'fetch_shard_store': {u'active': 0,
                                                                                u'completed': 23,
                                                                                u'largest': 4,
                                                                                u'queue': 0,
                                                                                u'rejected': 0,
                                                                                u'threads': 1},
                                                         u'flush': {u'active': 0,
                                                                    u'completed': 355,
                                                                    u'largest': 1,
                                                                    u'queue': 0,
                                                                    u'rejected': 0,
                                                                    u'threads': 1},
                                                         u'force_merge': {u'active': 0,
                                                                          u'completed': 0,
                                                                          u'largest': 0,
                                                                          u'queue': 0,
                                                                          u'rejected': 0,
                                                                          u'threads': 0},
                                                         u'generic': {u'active': 0,
                                                                      u'completed': 3130592,
                                                                      u'largest': 7,
                                                                      u'queue': 0,
                                                                      u'rejected': 0,
                                                                      u'threads': 7},
                                                         u'get': {u'active': 0,
                                                                  u'completed': 0,
                                                                  u'largest': 0,
                                                                  u'queue': 0,
                                                                  u'rejected': 0,
                                                                  u'threads': 0},
                                                         u'index': {u'active': 0,
                                                                    u'completed': 0,
                                                                    u'largest': 0,
                                                                    u'queue': 0,
                                                                    u'rejected': 0,
                                                                    u'threads': 0},
                                                         u'listener': {u'active': 0,
                                                                       u'completed': 0,
                                                                       u'largest': 0,
                                                                       u'queue': 0,
                                                                       u'rejected': 0,
                                                                       u'threads': 0},
                                                         u'management': {u'active': 1,
                                                                         u'completed': 11584744,
                                                                         u'largest': 5,
                                                                         u'queue': 0,
                                                                         u'rejected': 0,
                                                                         u'threads': 5},
                                                         u'ml_autodetect': {u'active': 0,
                                                                            u'completed': 0,
                                                                            u'largest': 0,
                                                                            u'queue': 0,
                                                                            u'rejected': 0,
                                                                            u'threads': 0},
                                                         u'ml_datafeed': {u'active': 0,
                                                                          u'completed': 0,
                                                                          u'largest': 0,
                                                                          u'queue': 0,
                                                                          u'rejected': 0,
                                                                          u'threads': 0},
                                                         u'ml_utility': {u'active': 0,
                                                                         u'completed': 28,
                                                                         u'largest': 28,
                                                                         u'queue': 0,
                                                                         u'rejected': 0,
                                                                         u'threads': 28},
                                                         u'refresh': {u'active': 0,
                                                                      u'completed': 21598424,
                                                                      u'largest': 1,
                                                                      u'queue': 0,
                                                                      u'rejected': 0,
                                                                      u'threads': 1},
                                                         u'search': {u'active': 0,
                                                                     u'completed': 995604,
                                                                     u'largest': 4,
                                                                     u'queue': 0,
                                                                     u'rejected': 0,
                                                                     u'threads': 4},
                                                         u'snapshot': {u'active': 0,
                                                                       u'completed': 0,
                                                                       u'largest': 0,
                                                                       u'queue': 0,
                                                                       u'rejected': 0,
                                                                       u'threads': 0},
                                                         u'warmer': {u'active': 0,
                                                                     u'completed': 52166566,
                                                                     u'largest': 1,
                                                                     u'queue': 0,
                                                                     u'rejected': 0,
                                                                     u'threads': 1},
                                                         u'watcher': {u'active': 0,
                                                                      u'completed': 0,
                                                                      u'largest': 0,
                                                                      u'queue': 0,
                                                                      u'rejected': 0,
                                                                      u'threads': 0}},
                                        u'timestamp': 1507212261505,
                                        u'transport': {u'rx_count': 53201865,
                                                       u'rx_size_in_bytes': 216656566638,
                                                       u'server_open': 39,
                                                       u'tx_count': 53201865,
                                                       u'tx_size_in_bytes': 287894015241},
                                        u'transport_address': u'10.10.193.88:9300'}}}
rules:Namespace(auth=None, data=None, debug=True, headers=None, host='integration-search001', key_list=['nodes_(0)_jvm.mem.heap_used_percent'], key_list_critical=None, key_threshold_critical=None, key_threshold_warning=None, key_value_list=None, key_value_list_critical=None, metric_list=None, path='_nodes/integration-search001/stats', port='9200', separator='_', ssl=False, timeout=None)
separator:_
Traceback (most recent call last):
  File "./check_http_json.py", line 437, in <module>
    nagios.append_warning(processor.checkWarning())
  File "./check_http_json.py", line 214, in checkWarning
    failure += self.checkExists(self.rules.key_list)
  File "./check_http_json.py", line 154, in checkExists
    if (self.helper.exists(key) == False):
  File "./check_http_json.py", line 104, in exists
    def exists(self, key): return (self.get(key) != (None, 'not_found'))
  File "./check_http_json.py", line 115, in get
    return self.getSubElement(key, data)
  File "./check_http_json.py", line 78, in getSubElement
    return self.get(remainingKey, data[partialKey])
  File "./check_http_json.py", line 117, in get
    return self.getSubArrayElement(key, data)
  File "./check_http_json.py", line 95, in getSubArrayElement
    return self.get(remainingKey, data[index])
KeyError: 0


Issue when selecting all keys

Hello,

When I am trying to select all keys of an json api using this syntax (*).capacity.value I have this error:

File "./check_http_json.py", line 433, in
nagios.append_metrics(processor.checkMetrics())
File "./check_http_json.py", line 246, in checkMetrics
if self.helper.exists(key):
File "./check_http_json.py", line 104, in exists
def exists(self, key): return (self.get(key) != (None, 'not_found'))
File "./check_http_json.py", line 115, in get
return self.getSubElement(key, data)
File "./check_http_json.py", line 78, in getSubElement
return self.get(remainingKey, data[partialKey])
File "./check_http_json.py", line 117, in get
return self.getSubArrayElement(key, data)
File "./check_http_json.py", line 84, in getSubArrayElement
index = int(key[key.find(self.arrayOpener) + 1:key.find(self.arrayCloser)])
ValueError: invalid literal for int() with base 10: ''
[root@eyes2 plugins]# ./check_http_json.py -H localhost:3010 -p data -m imdata.(
).eqptStorage.attributes.available

If i use an integer like imdata.(0).eqptStorage.attributes.available it works.

How can i select all the keys in a json file?

Thank you.

Traceback

$ ./check_http_json.py -H 184.172.237.226:51234 -m "node_gets"
Traceback (most recent call last):
File "./check_http_json.py", line 421, in
nagios.append_unknown("HTTPError[%s], url:%s" % (str(e.code), url))
File "./check_http_json.py", line 59, in append_unknown
self.critical_message += critical_message
NameError: global name 'critical_message' is not defined

I'll be glad to give you more information about my environment, if needed. Thanks!

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.