NCPA - Passing Directory Path ARG with Spaces

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
FrontlineIT
Posts: 94
Joined: Tue Jul 26, 2016 8:46 am

NCPA - Passing Directory Path ARG with Spaces

Post by FrontlineIT »

Hello,

I'm having trouble passing an ARG (file path with a space) using NCPA. I'm able to get this check working when a file path contains no spaces but no luck when a space is involved. I'm using NCPA v2.1.6 and Configuration Wizard v2.0.2. Could I get assistance on the correct syntax I should be using? Below is an example with the Run Check Command output:

-t '************' -P 5693 -M 'plugins/check_file_count.ps1' -a 'E:\Frontline\Report Agent\ReportOutput 3000'

C:\Program Files (x86)\Nagios\NCPA\plugins\check_file_count.ps1 : Cannot
process argument transformation on parameter 'c'. Cannot convert value
"Agent\ReportOutput" to type "System.Int32". Error: "Input string was not in a
correct format."
+ CategoryInfo : InvalidData: (:) [check_file_count.ps1], ParentC
ontainsErrorRecordException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,check_file_
count.ps1
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: NCPA - Passing Directory Path ARG with Spaces

Post by benjaminsmith »

Hello @FrontlineIT

It looks like there's a formatting issue with the space in the file path between the arguments your passing to the plugin via NCPA. Please try the following options:

Code: Select all

"'E:\Frontline\Report Agent\ReportOutput' 3000"
"E:\\Frontline\\Report\ Agent\\ReportOutput 3000"
'E:\Frontline\Report%20Agent\ReportOutput 3000'
If you're note able to resolve the issue, please post the ncpa.cfg file along with the code for this powershell script for us to review. Thank you.
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!
FrontlineIT
Posts: 94
Joined: Tue Jul 26, 2016 8:46 am

Re: NCPA - Passing Directory Path ARG with Spaces

Post by FrontlineIT »

Thanks. Unfortunately, I'm still having issues with getting this working even after trying the different methods. I have no issues when running in powershell and passing the arguments manually. Here's the error message I'm getting after running the run check command

-t '**********' -P 5693 -M 'plugins/check_file_count.ps1' -a 'E:\Frontline\Report Agent\ReportOutput 3000'

C:\Program Files (x86)\Nagios\NCPA\plugins\check_file_count.ps1 : Cannot
process argument transformation on parameter 'files'. Cannot convert value
"Agent\ReportOutput" to type "System.Int32". Error: "Input string was not in a
correct format."
+ CategoryInfo : InvalidData: (:) [check_file_count.ps1], ParentC
ontainsErrorRecordException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,check_file_
count.ps1

I attached the NCPA.cfg and below is the powershell script:

param(
[Parameter(Mandatory=$true)][string]$filepath,
[Parameter(Mandatory=$true)][int]$files
)

$ok = 0
$warning = 1
$critical = 2

$file_count = [System.IO.Directory]::GetFiles("$filepath").Count
if ($file_count -ge $files){
write-host "Critical - $file_count files exists"
exit $critical
}
else{
write-host "OK - $file_count files exists"
exit $ok
}
You do not have the required permissions to view the files attached to this post.
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: NCPA - Passing Directory Path ARG with Spaces

Post by ssax »

Please try this:

Code: Select all

/usr/local/nagios/libexec/check_ncpa.py -H X.X.X.X -t 'yourtoken' -M 'plugins/check_file_count.ps1' -a "'E:\Frontline\Report Agent\ReportOutput' 3000"
I updated your script as well since the apostrophes need to be removed for the GetFiles function:

Code: Select all

param(
[Parameter(Mandatory=$true)][string]$filepath,
[Parameter(Mandatory=$true)][int]$files
)

$ok = 0
$warning = 1
$critical = 2
$filepath2 = $filepath -replace "'",""
$file_count = [System.IO.Directory]::GetFiles($filepath2).Count
if ($file_count -ge $files){
write-host "Critical - $file_count files exists"
exit $critical
}
else{
write-host "OK - $file_count files exists"
exit $ok
}
FrontlineIT
Posts: 94
Joined: Tue Jul 26, 2016 8:46 am

Re: NCPA - Passing Directory Path ARG with Spaces

Post by FrontlineIT »

Made the changes and the check is now working like a charm. Thank you very much!!
Locked