We are unable to pass agrument or arguments to powershell script: just does not work
I there a best practice or the right way to pass what PS1 expects to be entered in XI (nrpe / nsclient used)
0. Error screen attached (similar any way we tried - PS does not recognize the arguments)
1. Here is the Command (we've tried a single $ARG1$ too for all 3 values, no luck)
Code: Select all
$USER1$/check_nrpe -H $HOSTADDRESS$ -t 60 -c validate_registry_1 -a $ARG1$ $ARG2$ $ARG3$
- tried with -a / and without, as a single or multiple arguments, with value prefixes and without. No luck here either
3. INI file attached
4. PS script is this one:
Code: Select all
# Check Status
#
# To execute from within NSClient++
#
# [NRPE Handlers]
# validate_registry_1 = cmd /c echo scripts\\validate_regitry_1.ps1 -LicensingMode 4 -WarnMode 2 -CritMode 5; exit($lastexitcode) | powershell.exe -command -
#
# On the check_nrpe command include the -t 60, since it can take longer than the standard 10 seconds to run.
#
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)]
[int]$LicensingMode,
[Parameter(Mandatory=$true)]
[int]$WarnMode,
[Parameter(Mandatory=$true)]
[int]$CritMode
)
# Initialise variables
$NagiosStatus = "0" # 0 = OK, 1 = WARNING, 2 = CRITICAL, 3 = UNKNOWN
$NagiosDescription = ""
$NagiosPerfData = "| 0;" + $WarnMode + ";" + $CritMode
$LicensingMode = "0"
$WarnMode = "2"
$CritMode = "5"
# Script Functions
function Test-RegistryEntry ([string] $key, [string] $name)
{
Get-ItemProperty -Path "$key" -Name "$name" -ErrorAction SilentlyContinue | Out-Null;
return $?;
}
function Read-RegistryEntry ([string] $key, [string] $name)
{
if ( Test-RegistryEntry $key $name )
{
return (Get-ItemProperty -Path $key -Name $name).$name;
}
else
{
return '';
}
}
$key = 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\RCM\Licensing Core'
$name = 'LicensingMode'
$LicensingMode = ( Read-RegistryEntry $key $name )
#$LicensingMode = (Get-ItemProperty -Path $key -Name $name).$name
switch ( $LicensingMode ) {
5 {
$NagiosStatus = "2"
$NagiosDescription = "RDS Licensing Mode (" + $LicensingMode + ") is + " + $LicensingMode + " at fault "
$NagiosPerfData = "| " + $LicensingMode
}
2 {
$NagiosStatus = "1"
$NagiosDescription = "RDS Licensing Mode (" + $LicensingMode + ") is " + $LicensingMode + " per Device "
$NagiosPerfData = "| " + $LicensingMode
}
4 {
$NagiosStatus = "0"
$NagiosDescription = $NagiosDescription + "RDS LicensingMode is per User"
$NagiosPerfData = "| " + $LicensingMode
}
default {
$NagiosStatus = "3"
$NagiosDescription = $NagiosDescription + "RDS LicensingMode is UNKNOWN"
$NagiosPerfData = "| " + $LicensingMode
}
}
# Output, what level should we tell our caller?
switch ( $NagiosStatus ) {
3 {Write-Host "UNKNOWN:" $NagiosDescription" "$NagiosPerfData}
2 {Write-Host "CRITICAL:" $NagiosDescription" "$NagiosPerfData}
1 {Write-Host "WARNING:" $NagiosDescription" "$NagiosPerfData}
default { Write-Host "OK: RDS License Mode is per User" $NagiosPerfData }
}
exit $NagiosStatus