beginner
beginner

Reputation: 53

Windows NRPE - invalid return code: -196608 Nagios Core

I have this Powershell script for monitoring AD sync status:

Param(
        [Parameter(Mandatory=$false,Position=0)] 
        [ValidateNotNullOrEmpty()]
        [int]$Warning=1,
        [Parameter(Mandatory=$false,Position=1)] 
        [ValidateNotNullOrEmpty()]
        [int]$Critical=5
)
# Variables
$SyncErrors=0
$NagiosStatus = 0
$NagiosOutput = ""
$Syncs = 0

# Get AD Replication Status for this DC
$SyncResults = Get-WmiObject -Namespace root\MicrosoftActiveDirectory -Class MSAD_ReplNeighbor -ComputerName $env:COMPUTERNAME |
    select SourceDsaCN, NamingContextDN, LastSyncResult, NumConsecutiveSyncFailures, @{N="LastSyncAttempt"; E={$_.ConvertToDateTime($_.TimeOfLastSyncAttempt)}}, @{N="LastSyncSuccess"; E={$_.ConvertToDateTime($_.TimeOfLastSyncSuccess)}} 

# Process result
foreach ($SyncResult in $SyncResults)
{
    if ($SyncResult.LastSyncResult -gt 0){
        $NagiosOutput += "$($SyncResult.NumConsecutiveSyncFailures) failed sync with DC $($SyncResult.SourceDsaCN) on $($SyncResult.NamingContextDN) at $($SyncResult.LastSyncAttempt), last success sync at $($SyncResult.LastSyncSuccess)."
        $SyncErrors++
        if ($SyncErrors -eq $Warning){
            $NagiosStatus = 1
        }
        elseif ($SyncErrors -eq $Critical) {
            $NagiosStatus = 2
        }           
    }
    else{
        $Syncs++
    }
}
# Nagios Output
$NagiosOutput += " | Syncs=$($Syncs);;;; SyncErrors=$($SyncErrors);$Warning;$Critical;;"
if ($NagiosStatus -eq 2) {
    Write-Host "CRITICAL: Replication error: $($NagiosOutput)"
    $host.SetShouldExit(2)

} 
elseif ($NagiosStatus -eq 1) {
    Write-Host "WARNING: Replication error: $($NagiosOutput)"
    $host.SetShouldExit(1)
    exit 1
} 
else{
    Write-Host "OK: replication is up and running.$($NagiosOutput)"
    $host.SetShouldExit(0)
    exit 0
}

nslient.ini:

[/settings/external scripts/scripts]

check_ad_replication = cmd /c echo \scripts\check_ad_replication.ps1; exit($lastexitcode) | powershell.exe - Command -

Script is located in script folder,

./check_nrpe -H 1.2.3.5

I (0.5.2.35 2018-01-28) seem to be doing fine...

From Nagios server getting

 ./check_nrpe -H 1.2.3.5 -c check_ad_replication -t 30

The command (check_ad_replication) returned an invalid return code: -196608

Tried to set exit 1 - 3 for exit codes but no changes, from Powershell command runs just fine. Does anyone knows what should be set for error codes

Upvotes: 0

Views: 1625

Answers (1)

beginner
beginner

Reputation: 53

Issue solved, had to add quotes around exit codes, example:

$NagiosStatus -eq "2"

Upvotes: 1

Related Questions