Issue with check command

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
imrob
Posts: 9
Joined: Mon May 06, 2013 4:46 pm

Issue with check command

Post by imrob »

Hi,

I've run into an issue while evaluating Nagios XI

System: Centos 6.4
Platform: Xenserver 5.6sp2 vm
Nagios XI Version: 2012R1.8

Since I've used nagios OSS for a while so I'm doing the configuration of our test box via the core config manager.

I have the following check command that works fine via cli:

[root@nagiosxitest services]# /usr/local/nagios/libexec/check_nt -H 10.1.5.147 -s "" -p 1248 -v COUNTER -l "\LogicalDisk(C:)\% Free Space","Disk Free Space %.2f %%" -w 90 -c 95
Disk Free Space 38.70 % | 'Disk Free Space %.2f %%'=38.704600%;90.000000;95.000000;

10.1.5.147 has the nsclient++ as shown in the windows server auto discover wizard. The return values look correct from the cli command above.

However, when I define the following in the gui, it fails:
===================================
Config name: win_diskc
Description: Disk C: Free Space Pct
Check command: check_xi_service_nsclient
Active[X]
Command view: $USER1$/check_nt -H $HOSTADDRESS$ -s "$ARG1$" -p 1248 -v $ARG2$ $ARG3$ $ARG4$
$ARG1$ [ ]
$ARG2$ [ COUNTER ]
$ARG3$ [ -l "\LogicalDisk(C:)\% Free Space","Disk Free Space %.2f %%" -w 90 -c 95 ]
===================================

Running "Test check command" shows the following:
===================================
COMMAND: /usr/local/nagios/libexec/check_nt -H 10.1.5.147 -s "" -p 1248 -v COUNTER -l "\\LogicalDisk\(C:\)\\% Free Space","Disk Free Space %.2f %%" -w 90 -c 95
OUTPUT: Disk Free Space 0.00 % | 'Disk Free Space %.2f %%'=0.000000%;90.000000;95.000000;
===================================

I believe that the "LogicalDisk(C:)" is being (incorrectly?) escaped as LogicalDisk\(C:\) and this is what is causing it to fail.

Please advise if I am wrong and what I'm doing wrong.

If I'm correct, is there a work-around or bugfix for this issue?

Thanks,

Robert
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: Issue with check command

Post by slansing »

The test may fail since it may be required to escape the backslashes that are being used in the ARG3 value. See this wiki page for an example of escaping a special character:

http://support.nagios.com/wiki/index.ph ... ck_Command

What the test was doing was escaping those characters once, but the command line read the slashes that were added as literal, so what you need to do is add double slashes where that test did, in the ARG3 value. For example:

Code: Select all

-l "\\LogicalDisk\\(C:\\)\\% Free Space","Disk Free Space %.2f %%" -w 90 -c 95
And then verify after the config has been saved and applied, via the schedule an immediate check function on the service details page of the service itself. If the double slashes do not work where they were not present before, try switching them to singles like so:

Code: Select all

-l "\\LogicalDisk\(C:\)\\% Free Space","Disk Free Space %.2f %%" -w 90 -c 95
imrob
Posts: 9
Joined: Mon May 06, 2013 4:46 pm

Re: Issue with check command

Post by imrob »

slansing wrote:The test may fail since it may be required to escape the backslashes that are being used in the ARG3 value. See this wiki page for an example of escaping a special character:

http://support.nagios.com/wiki/index.ph ... ck_Command

What the test was doing was escaping those characters once, but the command line read the slashes that were added as literal, so what you need to do is add double slashes where that test did, in the ARG3 value. For example:

Code: Select all

-l "\\LogicalDisk\\(C:\\)\\% Free Space","Disk Free Space %.2f %%" -w 90 -c 95
And then verify after the config has been saved and applied, via the schedule an immediate check function on the service details page of the service itself. If the double slashes do not work where they were not present before, try switching them to singles like so:

Code: Select all

-l "\\LogicalDisk\(C:\)\\% Free Space","Disk Free Space %.2f %%" -w 90 -c 95
I understand the reasoning behind this, and I'll give it a shot, thanks.

Any way this may be fixed to make it a bit easier for Windows Admins who don't know the internals of linux shell escape character?
imrob
Posts: 9
Joined: Mon May 06, 2013 4:46 pm

Re: Issue with check command

Post by imrob »

I copied and pasted your example and it did not solve the issue:

$ARG3$ [ -l "\\LogicalDisk\\(C:\\)\\% Free Space","Disk Free Space %.2f %%" -w 90 -c 95 ]

Output of test command:

Code: Select all

COMMAND: /usr/local/nagios/libexec/check_nt -H 10.1.5.147 -s "" -p 1248 -v COUNTER -l "\\\\LogicalDisk\\\\\(C:\\\\\)\\\\% Free Space","Disk Free Space %.2f %%" -w 90 -c 95 
OUTPUT: Disk Free Space 0.00 % | 'Disk Free Space %.2f %%'=0.000000%;90.000000;95.000000;
Edit: I forgot to meniton that I tried single slashes first, as I believe that is what works on the CLI.
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: Issue with check command

Post by slansing »

Did you try these by forcing the check command through "Home > Service Details > "Service's name" > Schedule an immediate check button

I do not believe that you would be able to test this through the "Test" function in the CCM due to having to escape the slashes. Currently the only way to test changes like this would be through the schedule check button in the service's details page itself, not the CCM..apologies if I was unclear.
imrob
Posts: 9
Joined: Mon May 06, 2013 4:46 pm

Re: Issue with check command

Post by imrob »

No I did not.

This does kind of show that the "test check command" in services is broken then...no? I'll try actually setting up the check and assiging it to a host to see if it actually returns any data.

Edit:

Code: Select all

-l "\LogicalDisk(C:)\% Free Space","Disk Free Space %.2f %%" -w 90 -c 95
Returned 0

Code: Select all

-l "\\LogicalDisk\\(C:\\)\\% Free Space","Disk Free Space %.2f %%" -w 90 -c 95
Returned 0

Code: Select all

-l "\\LogicalDisk(C:)\\% Free Space","Disk Free Space %.2f %%" -w 90 -c 95
Returned the correct number.

So I guess it comes down to removing the "escaping" of the ()'s that the test check tries to do. Does this sound correct? Is this something that will be fixed so non-linux/non-shell people will have the test command work as expected?
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Issue with check command

Post by abrist »

The test check adds the escaping right before the check as it is a one-shot test. The XI interface will also add escaping, but does so behind the scenes.
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.
imrob
Posts: 9
Joined: Mon May 06, 2013 4:46 pm

Re: Issue with check command

Post by imrob »

Why then would the test NOT work but when actually setting it up that way as a service, work?
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Issue with check command

Post by abrist »

Sometimes the test check command does not work for checks if those checks cannot be run as user "apache". There are also some extra precautions taken with the test check command as there are security concerns with allowing any plugin to be run from the web ui as a one shot.
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.
imrob
Posts: 9
Joined: Mon May 06, 2013 4:46 pm

Re: Issue with check command

Post by imrob »

abrist wrote:Sometimes the test check command does not work for checks if those checks cannot be run as user "apache". There are also some extra precautions taken with the test check command as there are security concerns with allowing any plugin to be run from the web ui as a one shot.
Running it as user apache seems to be OK:

Code: Select all

bash-4.1$ whoami
apache
bash-4.1$ /usr/local/nagios/libexec/check_nt -H 10.1.5.147 -s "" -p 1248 -v COUNTER -l "\\LogicalDisk(C:)\\% Free Space","Disk Free Space %.2f %%" -w 90 -c 95
Disk Free Space 38.68 % | 'Disk Free Space %.2f %%'=38.680800%;90.000000;95.000000;
That makes sense. Is there some security issue that requires escaping ()'s as that seems to be the issue.....

I wonder if there is another way to escape the ()'s, securely, while still making sure the check works -- OR notifying the end user that checks with ()'s may not work...
Locked