drewkerrigan/nagios-http-json

Bug when thre is a colon in Key value

fitou13 opened this issue · 12 comments

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 ?

Hi, can you show the command you're running. I could not recreate that yet.

Ok so it's not the Bracket, but the colon.

Due to this:

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

Unittest to recreate

   def test_equality_colon(self):
       # This should not fail
       self.check_data(RulesHelper().dash_q(['metric,foo:bar']),
                       '{"metric": "foo:bar"}', OK_CODE)

@drewkerrigan One solution would be to add a new CLI paramter to set a custom separator for the -q option. What do you think? 🤔

K0nne commented

Other checks like nwc health use a similar approach.

@K0nne I'm not sure I know what you mean?

K0nne commented

I mean special options for options.

yeah I thinks that's the only solution here

Yeah I think for the short term a custom separator via cli option will be fine. For the medium-long term I think we may want to actually switch to something like json path for the majority of this functionality

@drewkerrigan Been thinking about a jsonpath solution, I see an issue with having a library for that, since the script loses its independence. You know what I mean?

I'll write some code for a custom separator and we'll see if that works

@martialblog agree re: script independence. If we go the json path route we would likely want to rip out some open source functionality and put it directly in the script. That would need to be a major version change though, since the interface would definitely be broken for existing users.

Fixed in v2.0 Branch https://github.com/drewkerrigan/nagios-http-json/tree/python3

Release will follow soon