Page 1 of 1

NCPA - Issues passing arguments to custom plugin on windows

Posted: Mon Mar 30, 2020 12:28 pm
by pavankumar
I have created a custom plugin and copied it to 'plugins' folder under C:\Program Files (x86)\Nagios\NCPA\plugins. It is working as expected when i execute it from cmd prompt.
----------------------------------------------------------------------------------------
C:\Program Files (x86)\Nagios\NCPA\plugins>Log_Test_6.exe -L "C:\\Program Files\\Apache Software Foundation\\Tomcat 9.0\\logs\\localhost_access_log.2020-03-30.txt" -M "C:\\Program Files (x86)\\Nagios\\NCPA\\plugins\\log_stat.txt" -P "200" "400" -w 1 -c 1
Service Status-CRITICAL; Status Message-New matches.; Pattern Matches-2|PatternMatches=2;1;1;;
------------------------------------------------------------------------------------------

It is failing when i try to execute it from NCPA GUI API End point or from /usr/local/nagios/libexec
Below is the error
----------------------------------------------------------------------------------------------
{ "returncode": 3, "stdout": "*****Verbosity Turned On*****\n--------------------------------------------------------------------------------------------------\n-----Argument List-----\nlog path : 'C:\\\\Program Files\\\\Apache Software Foundation\\\\Tomcat 9.0\\\\logs\\\\localhost_access_log.2020-03-30.txt', \nlog meta path : 'C:\\\\Program Files (x86)\\\\Nagios\\\\NCPA\\\\plugins\\\\log_stat.txt', \npattern_list : ['\"200\"', '\"400\"'], \nwarning threshold : 1, \ncritical threshold : 1, \nminimum : None, \nmaximum : None, \n--------------------------------------------------------------------------------------------------\nUNKNOWN - An exception occured, enable verbose, traceback for troubleshooting !\n\nTraceback (most recent call last):\n File \"Log_Test_6.py\", line 176, in \n File \"Log_Test_6.py\", line 47, in get_log_path\n File \"pathlib.py\", line 1365, in is_file\n File \"pathlib.py\", line 1161, in stat\nOSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: \"'C:\\\\Program Files\\\\Apache Software Foundation\\\\Tomcat 9.0\\\\logs\\\\localhost_access_log.2020-03-30.txt'\""
}
---------------------------------------------------------------------------------------------

I am not clear on how check_ncpa.py parses the arguments with spaces and especially windows file paths.
i have passed -L 'C:\\Program Files\\Apache Software Foundation\\Tomcat 9.0\\logs\\localhost_access_log.2020-03-30.txt'
it ended up as -L 'C:\\\\Program Files\\\\Apache Software Foundation\\\\Tomcat 9.0\\\\logs\\\\localhost_access_log.2020-03-30.txt'

I have tried all the possible combinations but it didn't work. I have referred to the below article
https://www.nagios.org/ncpa/help.php#ac ... the-plugin but it didn't help.

Please let me know if this sis a bug else how to solve this or if there is any workaround.

Thanks,

Re: NCPA - Issues passing arguments to custom plugin on wind

Posted: Tue Mar 31, 2020 11:34 am
by benjaminsmith
Hello @pavankumar,

You might be hitting this bug. Can you post the entire check command that you are running from the Nagios XI side for us to review? Thanks.

Additionally, is it possible to test the plugin without spaces in the file path to verify if that is the issue or not.

Re: NCPA - Issues passing arguments to custom plugin on wind

Posted: Wed Apr 01, 2020 2:32 pm
by mbellerue
I do have a work around for this issue, and that is to use symbolic links that point to the directory you want to monitor.

Since spaces in directory and file names are pretty common, I would recommend setting up a directory specifically for these symbolic links. In Windows you can do this in a cmd window.

Code: Select all

mkdir C:\Monitoring
mklink /D C:\Monitoring\ApacheLogs "C:\Program Files\Apache Software Foundation\Tomcat 9.0\logs"
Now whenever you browse to C:\Monitoring\ApacheLogs, you will see the contents of C:\Program Files\Apache Software Foundation\Tomcat 9.0\logs. Here is what the check_ncpa command might look like.

Code: Select all

check_ncpa.py -H <HostIP> -t <SecretToken> -M plugins/Log_Test_6.exe -q 'args=-L C:\\Monitoring\\ApacheLogs\\localhost_access_log.2020-03-30.txt'
Also useful to note that if you have a file that has a space in the name, you can use symbolic links to link directly to a file as well.

Re: NCPA - Issues passing arguments to custom plugin on wind

Posted: Mon Apr 06, 2020 9:39 am
by pavankumar
Thanks all for the inputs.

I have found the issue after a lot of debugging.

1. The python version which came by default is 2.7 and check_ncpa.py runs with only 2.x

2. I have installed Python 3 (Anaconda) and check_ncpa.py is failing with string parsing.

3. I have removed Python 3 and then the below command worked.

./check_ncpa.py -H <hostname> -t '<token>' -M 'plugins/Log_Test_6.exe' -q 'args=-L "C:\Program Files\Apache Software Foundation\Tomcat 9.0\logs\localhost_access_log.2020-04-01.txt",args=-M "C:\Program Files (x86)\Nagios\NCPA\plugins\log_stat.txt",args=-P "HelloWorldExample",args=-w 1,args=-c 1,args=-v'

4. I didn't test if symlinks work but i like that idea.

5. quotes is something very very important in this case. If there are spaces in file path we have to enclose it with double/single quotes and the outer one should be opposite. As you see i have enclosed file path with " quotes and -q argument with ' quote.

6. One more thing. Already Python 2.X is going away and out of support. Is there a plan to upgrade NCPA and plugins coded in python to latest version.

Thanks

Re: NCPA - Issues passing arguments to custom plugin on wind

Posted: Mon Apr 06, 2020 10:10 am
by lmiltchev
3. I have removed Python 3 and then the below command worked.
I am glad your issue has been resolved!
6. One more thing. Already Python 2.X is going away and out of support. Is there a plan to upgrade NCPA and plugins coded in python to latest version.
Yes, NCPA 3 will be using python 3. Unfortunately, I don't have an ETA.

Having said that, according to our developers, you should be able to use python 3 with the latest check_ncpa.py script. Are you using check_ncpa.py ver. 1.2.0 or an older version?
Fixed incompatibility with Python 3.7 and 3.8 (Christian Zettel)
https://github.com/NagiosEnterprises/nc ... HANGES.rst