having trouble using strings on return

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
gmills
Posts: 114
Joined: Wed Jun 12, 2019 2:08 pm

having trouble using strings on return

Post by gmills »

Is there anything special Nagios configuration needs to support the command returning and accepting Strings?

I'm new, trying something new, and of course, struggling....

on command line, I can do ..

Code: Select all

./check_jmx4perl --user passthru --password B@dC0mpany --url http://localhost:9090/jolokia --mbean org.apache.activemq:type=Broker,brokerName=amq,service=Health --attribute CurrentStatus --string --critical '!Good'
OK - [org.apache.activemq:type=Broker,brokerName=amq,service=Health,CurrentStatus] : 'Good' as expected

for Nagios monitorng server
Command.cfg

Code: Select all

define command{
        command_name    check_local_container_broker_health
        command_line    $USER1$/check_jmx4perl --user $ARG1$ --password $ARG2$ --url $ARG3$ --mbean $ARG4$ --attribute $ARG5$ $ARG6$
        }
Local Service def

Code: Select all

define service{
        use                             local-service
        host_name                       localhost
        service_description             Container PassThru Broker Health
        check_command                   check_local_container_broker_health!passthru!B@dC0mpany!http://localhost:9090/jolokia!org.apache.activemq:type=Broker,brokerName=amq,service=Health!CurrentStatus!--string --critical '!Good'
        }
** Handling check result for service 'Container Delta MRO Broker Health' on host 'localhost' from 'Core Worker 15854'...
[1562947372.677475] [016.1] [pid=15850] HOST: localhost, SERVICE: Container Delta MRO Broker Health, CHECK TYPE: Active, OPTIONS: 0, SCHEDULED: Yes, RESCHEDULE: Yes, EXITED OK: Yes, RETURN CODE: 1, OUTPUT: (No output on stdout) stderr: /bin/sh: -c: line 0: unexpected EOF while looking for matching `''
/bin/sh: -c: line 1: syntax error: unexpected end of file

However, nagios doesn't seem to understand or recognize Strings - I know it is either how I'm using it OR there is an option in need of enabling, if so, does this require recompiling ???

thank you again !!! I'm getting there :)
gmills
Posts: 114
Joined: Wed Jun 12, 2019 2:08 pm

Re: having trouble using strings on return

Post by gmills »

I don't know if this is it, but it is working now, and a little confused.

I added another ARG to the command,

Code: Select all

define command{
        command_name    check_local_container_broker_health
        command_line    $USER1$/check_jmx4perl --user $ARG1$ --password $ARG2$ --url $ARG3$ --mbean $ARG4$ --attribute $ARG5$ $ARG6$ $ARG7$
        }
Yeilds:
[1562949146.077285] [016.0] [pid=12926] ** Handling check result for service 'Container Delta FADEC Broker Health' on host 'localhost' from 'Core Worker 12932'...
[1562949146.077306] [016.1] [pid=12926] HOST: localhost, SERVICE: Container Delta FADEC Broker Health, CHECK TYPE: Active, OPTIONS: 0, SCHEDULED: Yes, RESCHEDULE: Yes, EXITED OK: Yes, RETURN CODE: 0, OUTPUT: OK - [org.apache.activemq:type=Broker,brokerName=amq,service=Health,CurrentStatus] : 'Good' as expected

[1562949146.077336] [001.0] [pid=12926] get_service_check_return_code()
[1562949146.077370] [016.2] [pid=12926] Parsing check output...
[1562949146.077387] [016.2] [pid=12926] Short Output: OK - [org.apache.activemq:type=Broker,brokerName=amq,service=Health,CurrentStatus] : 'Good' as expected
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: having trouble using strings on return

Post by scottwilkerson »

The problem is that nagios used ! as an argument delimiter in the check_command field

you ended the command with

Code: Select all

 --critical '!Good'
Which actually will split that into another $ARGn$
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
gmills
Posts: 114
Joined: Wed Jun 12, 2019 2:08 pm

Re: having trouble using strings on return

Post by gmills »

thank you

please excuse me, I'm an idiot sometimes :) this is probably another simple thing I'm just not getting, ...

how do I get around this? I did try adding another ARGn but this didn't work.
This command works on the Local Nagios Monitoring Server, but it like you mention, the NRPE server uses the ! char as a field delimiter.

I'm following the documentation as close as I can or know. but I do not know how to get around this. escaping \ doesn't work, I need the command to observe the ! in the String ARG as a NOT and not a delimiter.

I am observing from here that describes Strings but nothing talks about how this is to be interpreted on the NRPE side.

https://nagios-plugins.org/doc/guidelin ... HOLDFORMAT
https://metacpan.org/pod/release/ROLAND ... ng-checks

String checks
In addition to standard numerical checks, direct string comparison can be used. This mode is switched on either explicitely via --string (configuration: String) or by default implicitely if a heuristics determines that a value is non-numeric. Numeric checking can be enforced with the option --numeric (configuration: Numeric).

For string checks, --critical and --warning are not treated as numerical values but as string types. They are compared literally against the value retrieved and yield the corresponding Nagios status if matched. If the threshold is given with a leading !, the condition is negated. E.g. a --critical '!Running' returns CRITICAL if the value not equals to Running. Alternatively you can also use a regular expression by using qr/.../ as threshold value (substitute ... with the pattern to used for comparison). Boolean values are returned as true or false strings from the agent, so you can check for them as well with this kind of string comparison.

Does this apply to what i'm trying to do
# ILLEGAL OBJECT NAME CHARACTERS
# This option allows you to specify illegal characters that cannot
# be used in host names, service descriptions, or names of other
# object types.

illegal_object_name_chars=`~!$%^&*|'"<>?,()=



# ILLEGAL MACRO OUTPUT CHARACTERS
# This option allows you to specify illegal characters that are
# stripped from macros before being used in notifications, event
# handlers, etc. This DOES NOT affect macros used in service or
# host check commands.
# The following macros are stripped of the characters you specify:
# $HOSTOUTPUT$
# $LONGHOSTOUTPUT$
# $HOSTPERFDATA$
# $HOSTACKAUTHOR$
# $HOSTACKCOMMENT$
# $SERVICEOUTPUT$
# $LONGSERVICEOUTPUT$
# $SERVICEPERFDATA$
# $SERVICEACKAUTHOR$
# $SERVICEACKCOMMENT$

illegal_macro_output_chars=`~$&|'"<>



# REGULAR EXPRESSION MATCHING
# This option controls whether or not regular expression matching
# takes place in the object config files. Regular expression
# matching is used to match host, hostgroup, service, and service
# group names/descriptions in some fields of various object types.
# Values: 1 = enable regexp matching, 0 = disable regexp matching

use_regexp_matching=0
User avatar
lmiltchev
Former Nagios Staff
Posts: 13587
Joined: Mon May 23, 2011 12:15 pm

Re: having trouble using strings on return

Post by lmiltchev »

Have you tried placing '!Good' in the resource.cfg file? You can create a user macro ($USERx$), which can be passed to your command. This could solve the issue with the "!", being a delimiter.
Be sure to check out our Knowledgebase for helpful articles and solutions!
gmills
Posts: 114
Joined: Wed Jun 12, 2019 2:08 pm

Re: having trouble using strings on return

Post by gmills »

did I do this correctly?

because I'm stil getting the same result.

[1562969268] Host 3.239.245.209 is asking for command 'check_remote_container_broker_health' to be run...
[1562969268] Running command: /usr/local/nagios/libexec/check_jmx4perl --user deltafadec --password B@dM0nk3y --url http://localhost:9093/jolokia --mbean org.apache.activemq:type=Broker,brokerName=amq,service=Health --attribute CurrentStatus --string --critical Good
[1562969268] Command completed with return code 2 and output: CRITICAL - [org.apache.activemq:type=Broker,brokerName=amq,service=Health,CurrentStatus] : 'Good' matches threshold 'Good'
[1562969268] Return Code: 2, Output: CRITICAL - [org.apache.activemq:type=Broker,brokerName=amq,service=Health,CurrentStatus] : 'Good' matches threshold 'Good'
[1562969268] Connection from 3.239.245.209 closed.


what I did

Code: Select all

define service{
        use                             generic-service
        host_name                       alphprdfuse1i
        service_description             Container Delta FADEC Broker Health
        check_command                   check_nrpe!check_remote_container_broker_health!-a '--user deltafadec --password B@dM0nk3y --url http://localhost:9093/jolokia --mbean org.apache.activemq:type=Broker,brokerName=amq,service=Health --attribute CurrentStatus --string --critical [b]$USER3$[/b]'
        }
resource.cfg
$USER3$='!Good'

the nagios daemons have been recycled both nagios and nrpe
gmills
Posts: 114
Joined: Wed Jun 12, 2019 2:08 pm

Re: having trouble using strings on return

Post by gmills »

Hello, happy Monday :)

I am wondering - the problem I am having is that passing arguments to NRPE and evaluating as String.
The String evaluation has a Logical NOT operator in it. I guess this is the problem. So, the actual question should be, how do we get String operations on NRPE to work, using operators like NOT AND OR Greator, Lessthan, etc... without effecting the normal processing of fields.

Code: Select all

check_command                   check_nrpe!check_remote_container_broker_health!-a '--user iprcmtx --password G00gl3M3 --url http://localhost:9091/jolokia --mbean org.apache.activemq:type=Broker,brokerName=amq,service=Health --attribute CurrentStatus --string --critical '!Good''
so, this is passing all the args, it gets the --string --critical '!Good' that needs to be evaluated as IF NOT EQUAL to GOOD, where it is getting evaluated as splitting the argument '!Good' as separate fields. ??? thank you.
User avatar
lmiltchev
Former Nagios Staff
Posts: 13587
Joined: Mon May 23, 2011 12:15 pm

Re: having trouble using strings on return

Post by lmiltchev »

Can you click on the "Container Delta FADEC Broker Health" service in the GUI, then click on the "Re-schedule the next check of this service" link under the "Service Commands" section, and show a screenshot of the page?
Be sure to check out our Knowledgebase for helpful articles and solutions!
gmills
Posts: 114
Joined: Wed Jun 12, 2019 2:08 pm

Re: having trouble using strings on return

Post by gmills »

I'm sorry, I don't know how to paste or post an image, can you kindly explain how to do this? thank you
I can't just cut and paste an image. thank you
Attachments
Nagios UI Shot
Nagios UI Shot
Last edited by gmills on Mon Jul 15, 2019 1:35 pm, edited 1 time in total.
User avatar
lmiltchev
Former Nagios Staff
Posts: 13587
Joined: Mon May 23, 2011 12:15 pm

Re: having trouble using strings on return

Post by lmiltchev »

Take the screenshot with whatever program is available on your system, and save the file. Then you go to: Upload attachment > Browse... > <your screenshot> > Add the file > Place inline
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked