check_by_ssh works on cmd line, fails in gui

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
ddewilde
Posts: 3
Joined: Fri Aug 15, 2014 7:35 am

check_by_ssh works on cmd line, fails in gui

Post by ddewilde »

Using NagiosXI 2014 CentOS VMware image.
Attempting to use a complex command line fails after using the gui to configure the command.
The error on use is:
(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

The same command works fine from the command line.
Example:
./check_by_ssh -H myHost -l myUser -C "freespace=\`df -k /home/mydisk | tail -n1 | sed -r 's/\\ +/\\ /g' | cut -d \\ -f5 | sed -r 's/%//g' \`; if [ \$freespace -lt 90 ]; then echo \"OK Free space: \$freespace%\"; exit 0; elif [ \$freespace -lt 95 ]; then echo \"Warning Free space: \$freespace%\"; exit 1 else echo \"Crititcal Free space: \$freespace%\"; exit 2; fi"

output:
OK Free space: 80%

The one-liner approach is required as I may not modify the target system.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: check_by_ssh works on cmd line, fails in gui

Post by tmcdonald »

How are you testing the command? Are you configuring it and letting it run? Or are you using the Test Check Command in the CCM? The Test Check Command button has some issues both with escaping and with running certain checks.
Former Nagios employee
ddewilde
Posts: 3
Joined: Fri Aug 15, 2014 7:35 am

Re: check_by_ssh works on cmd line, fails in gui

Post by ddewilde »

I noticed the test command has problems with even basic check_by_ssh command requests so I was using the actual service command execution to test.

I worked around this problem by placing the complex command line in a wrapper command and then used the gui to call the simple interface. I imported my new wrapper command and used it successfully from a service within XI.

The result is a new plugin called check_disk_by_ssh which then calls check_by_ssh with the complex command.
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: check_by_ssh works on cmd line, fails in gui

Post by sreinhardt »

Nice job! Thanks for letting us know its working.
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
Locked