Page 1 of 1

NCPA - Passing Directory Path ARG with Spaces

Posted: Wed Nov 14, 2018 10:33 am
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

Re: NCPA - Passing Directory Path ARG with Spaces

Posted: Wed Nov 14, 2018 2:40 pm
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.

Re: NCPA - Passing Directory Path ARG with Spaces

Posted: Thu Nov 15, 2018 3:25 pm
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
}

Re: NCPA - Passing Directory Path ARG with Spaces

Posted: Fri Nov 16, 2018 11:44 am
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
}

Re: NCPA - Passing Directory Path ARG with Spaces

Posted: Mon Nov 26, 2018 9:11 am
by FrontlineIT
Made the changes and the check is now working like a charm. Thank you very much!!