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,
NCPA - Issues passing arguments to custom plugin on windows
-
pavankumar
- Posts: 14
- Joined: Wed Aug 28, 2019 11:03 am
-
benjaminsmith
- Posts: 5324
- Joined: Wed Aug 22, 2018 4:39 pm
- Location: saint paul
Re: NCPA - Issues passing arguments to custom plugin on wind
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.
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.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: NCPA - Issues passing arguments to custom plugin on wind
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.
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.
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.
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"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'As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Be sure to check out our Knowledgebase for helpful articles and solutions!
-
pavankumar
- Posts: 14
- Joined: Wed Aug 28, 2019 11:03 am
Re: NCPA - Issues passing arguments to custom plugin on wind
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
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
I am glad your issue has been resolved!3. I have removed Python 3 and then the below command worked.
Yes, NCPA 3 will be using python 3. Unfortunately, I don't have an ETA.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.
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?
https://github.com/NagiosEnterprises/nc ... HANGES.rstFixed incompatibility with Python 3.7 and 3.8 (Christian Zettel)
Be sure to check out our Knowledgebase for helpful articles and solutions!