Unable to pass arguments to PS1 script

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
dlukinski
Posts: 1130
Joined: Tue Oct 06, 2015 9:42 am

Unable to pass arguments to PS1 script

Post by dlukinski »

Hello Nagios Support

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$
2. Here is the Service (screenshot)
- 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 

You do not have the required permissions to view the files attached to this post.
User avatar
mbellerue
Posts: 1403
Joined: Fri Jul 12, 2019 11:10 am

Re: Unable to pass arguments to PS1 script

Post by mbellerue »

In the nsclient.ini file, there is an extra semi-colon in the validate_registry_1 command definition.

Existing

Code: Select all

validate_registry_1 = cmd /c echo scripts\\validate_registry_1.ps1; "$ARG1$" "$ARG2$" "$ARG3$"; exit($lastexitcode) | powershell.exe -command -
Should be

Code: Select all

validate_registry_1 = cmd /c echo scripts\\validate_registry_1.ps1 "$ARG1$" "$ARG2$" "$ARG3$"; exit($lastexitcode) | powershell.exe -command -
Give that a shot and let me know how it goes.
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!
Locked