drewkerrigan/nagios-http-json

Key equality check fails if key contains ":"

lauritus opened this issue · 1 comments

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

Hi, I just tested this and the issue here is the separator, which is . by default

CLI option: [-f SEPARATOR]

See also:

        def test_separator(self):
            rules = RulesHelper()
            rules.separator = '_'
            self.check_data(
                rules.dash_q(
                    ['(0)_gauges_jvm.buffers.direct.capacity(1)_value,1234']),
                '''[{ "gauges": { "jvm.buffers.direct.capacity": [
                {"value": 215415},{"value": 1234}]}}]''',
                OK_CODE)
            self.check_data(
                rules.dash_q(
                    ['(*)_gauges_jvm.buffers.direct.capacity(1)_value,1234']),
                '''[{ "gauges": { "jvm.buffers.direct.capacity": [
                {"value": 215415},{"value": 1234}]}},
                { "gauges": { "jvm.buffers.direct.capacity": [
                {"value": 215415},{"value": 1235}]}}]''',
                WARNING_CODE)