NCPA - Issues passing arguments to custom plugin on windows
Posted: Mon Mar 30, 2020 12:28 pm
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,
----------------------------------------------------------------------------------------
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,