drewkerrigan/nagios-http-json

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

bprins opened this issue · 4 comments

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"

Yeah, I can see how this is an issue.

I managed to recreate the issue with a test, and see what I can do.

    def test_empty_key_value_array(self):
        rules = RulesHelper()

        # This should work
        data = '[{"update_status": "finished"},{"update_status": "finished"}]'
        self.check_data(rules.dash_q(['(*).update_status,finished']), data, OK_CODE)

        # This should throw a warning
        data = '[]'
        self.check_data(rules.dash_q(['(*).update_status,finished']), data, WARNING_CODE)

@bprins You can check out this Branch https://github.com/drewkerrigan/nagios-http-json/tree/key-equals-empty

Let me know if this works as expected.

Cheers, Markus

Hi Markus, did a test with the issue branch and it seems to work great.

Check output for an empty list is now: CRITICAL: Status CRITICAL. Empty JSON data.

Thanks for the quick follow-up.

Kind regards, Bobby

Cool 🧊 It'll be included in the next release