I'm trying to have NCPA execute a PowerShell script on a server while providing it with arguments. I have done so before and have 3 different scripts that behave as expected. This one doesn't.
To keep this short, I'm trying to use Get-Counter
to get a performance counter and provide the path as an argument.
The script currently looks like this:
$count = $args[0]
$warn = 1500
$crit = 2000
$Data = Get-Counter -Counter $count
$Raw = $Data.CounterSamples.CookedValue
Write-Host "$Raw | 'Counter'=$Raw;$warn;$crit;0;3000"
if ($Raw -gt $crit) {
exit 2
} elseif ($Raw -gt $warn) {
exit 1
} else {
exit 0
}
This gets called from the Nagios server via:
/usr/local/nagios/libexec/check_ncpa.py -H 192.168.**.** -t 'randomkeystringstuff' -P 5693 -M plugins/counter.ps1 -a "'\Processor Information(_Total)\% Processor Time'"
Filling the count variable directly in the script works. I can then also execute that through Nagios without errors. But using the argument returns
Get-Counter : Internal performance counter API call failed. Error: c0000bc4.
Which is the identical error when you provide a non existing path.
Since I've got the argument method working in three other scripts perfectly, I'm assuming some kind of string or type mismatch or such.