Page 1 of 1

Handling complex arguments No2

Posted: Tue Apr 21, 2015 2:03 pm
by stecino
I am pretty bad with string manipulations, so here is another one, I was able to get this far:


underlying is using jq to parse the json. So I am passing URL, jq filter and the thresholds it needs to match for each field

./parse_json_generic.sh 'http://blah.com:9020/healthcheck' \'.\"Mongo' 'Health\".\"healthy\"\',\'.\"Two-Way-Communication-Service\".\"healthy\"\',\'.\"RabbitMQ\".\"healthy\"\',\'.\"threadDeadlockHealthCheck\".\"healthy\"\' 'false false false false'
These is the filter '."Mongo Health"."healthy"','."Two-Way-Communication-Service"."healthy"','."RabbitMQ"."healthy"','."threadDeadlockHealthCheck"."healthy"'

'."Mongo_Health"."healthy"'=true is CRITICAL '."Two-Way-Communication-Service"."healthy"'=true is CRITICAL '."RabbitMQ"."healthy"'=true is CRITICAL '."threadDeadlockHealthCheck"."healthy"'=true is CRITICAL

But when I am trying to put this into Nagios is where I am running into issues. Here is what I have.

define command{
command_name check_parse_json_threshold
command_line $USER1$/parse_json_generic.sh $ARG1$ $ARG2$ $ARG3$
}

define service{
use app-services
service_description Two-Way Communication
host_name BLAH
check_command check_parse_json_threshold!"http://$HOSTADDRESS$:9020/healthcheck"!\'.\"Mongo' 'Health\".\"healthy\"\',\'.\"Two-Way-Communication-Service\".\"healthy\"\',\'.\"RabbitMQ\".\"healthy\"\',\'.\"threadDeadlockHealthCheck\".\"healthy\"\'!"false false false false"
notifications_enabled 0
}

I need help with the second argument as so that \'.\"Mongo' 'Health\".\"healthy\"\',\'.\"Two-Way-Communication-Service\".\"healthy\"\',\'.\"RabbitMQ\".\"healthy\"\',\'.\"threadDeadlockHealthCheck\".\"healthy\"\' is handled as one string
Double quotes around it don't help

Thanks in advance

Re: Handling complex arguments No2

Posted: Tue Apr 21, 2015 2:09 pm
by jdalrymple
This is what I get when I do what we discussed before:

Code: Select all

\'.\"Mongo' 'Health\".\"healthy\"\',\'.\"Two-Way-Communication-Service\".\"healthy\"\',\'.\"RabbitMQ\".\"healthy\"\',\'
becomes

Code: Select all

\\\'.\\\"Mongo\' \'Health\\\".\\\"healthy\\\"\\\',\\\'.\\\"Two-Way-Communication-Service\\\".\\\"healthy\\\"\\\',\\\'.\\\"RabbitMQ\\\".\\\"healthy\\\"\\\',\\\'
escaping:

Code: Select all

\ ' "

Re: Handling complex arguments No2

Posted: Tue Apr 21, 2015 5:56 pm
by stecino
jdalrymple wrote:This is what I get when I do what we discussed before:

Code: Select all

\'.\"Mongo' 'Health\".\"healthy\"\',\'.\"Two-Way-Communication-Service\".\"healthy\"\',\'.\"RabbitMQ\".\"healthy\"\',\'
becomes

Code: Select all

\\\'.\\\"Mongo\' \'Health\\\".\\\"healthy\\\"\\\',\\\'.\\\"Two-Way-Communication-Service\\\".\\\"healthy\\\"\\\',\\\'.\\\"RabbitMQ\\\".\\\"healthy\\\"\\\',\\\'
escaping:

Code: Select all

\ ' "

It didn't work that space for the Mongo Health is throwing things off

So when I remove that one and just use this \\\'.\\\"Two-Way-Communication-Service\\\".\\\"healthy\\\"\\\',\\\'.\\\"RabbitMQ\\\".\\\"healthy\\\"\\\',\\\'.\\\"threadDeadlockHealthCheck\\\".\\\"healthy\\\"\\\' I get things parsed correctly.
I have asked the devs to modify the code to give single worded field names, so I won't run into this issue.

But it would be nice to figure out how to handle multiple words

Re: Handling complex arguments No2

Posted: Wed Apr 22, 2015 1:30 pm
by jdalrymple
%20?

That would be my only potential thought. Otherwise generally speaking Nagios ARGs handle whitespace without issue.