Escaping special characters

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
User avatar
snapon_admin
Posts: 952
Joined: Mon Jun 10, 2013 10:39 am
Location: Kenosha, WI
Contact:

Escaping special characters

Post by snapon_admin »

I'm trying to monitor a specific process that has special characters in its name, specifically [] (service is called '-D[Standalone]') and I'm having a hard time with it. I've tried adding \ to escape the brackets but that doesn't seem to work. Thoughts?

Edit, I've also got another process with an even more ridiculous name that was just requested for monitoring that I can't get to work: -XX:+UseParallelGC -XX:+AggressiveOpts. Any ideas on how best to monitor that?
mp4783
Posts: 116
Joined: Wed May 14, 2014 11:11 am

Re: Escaping special characters

Post by mp4783 »

I would need more details on what you're doing, but let me assume some things and offer this. If your check is ultimately being run as a shell command, then you have to be very careful with meta characters that the shell will interpret. I've run into this many times. You may need enclose parts of it in double quotation marks or you may need to add a second '\' to escape the characters properly.

When a check passes from the GUI all the way through to actual execution, there are places where escape characters and quotation marks can be removed or interpreted. For example, if your check ran as shell command, that in turn called another shell command, each time a shell gets the command, it parses those characters.

What you need to do is find out exactly what Nagios XI is executing and then got to the command shell of the system and try running it. If it doesn't work, then you'll need to modify it. For example, I have an event handler that needs to pass arguments to a shell script. These arguments need to passed all the way to the command shell with quotation marks preserved. So in the Nagios XI GUI, I might have the following:

$USER1$/eventhandlers/myEventHandler.sh -H myhost.domain.com -S \"Search for this string\"

This when passed through the Nagios command execution logic would translate into a command that could be successfully run on the command line:

/usr/local/nagios/eventhandlers/myEventHandler.sh -H myhost.domain.com -S "Search for this string"

This then preserves the entire -S argument as a single string.
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Escaping special characters

Post by abrist »

Well, is this on a windows system or linux?
What agent/plugin are you using to check this?
Can you post a sample command that you are working with?
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
User avatar
snapon_admin
Posts: 952
Joined: Mon Jun 10, 2013 10:39 am
Location: Kenosha, WI
Contact:

Re: Escaping special characters

Post by snapon_admin »

It's for a unix system, but you can close this up. I told them to pick a string out of the process that is unique for those servers and just eliminated checking the special characters completely. Seemed easier that way.
cmerchant
Posts: 546
Joined: Wed Sep 24, 2014 11:19 am

Re: Escaping special characters

Post by cmerchant »

I like that approach, modify the user's behavior. We'll go ahead and lock 'er up. Thanks.
Locked