Windows NRPE-无效的返回码:-196608 Nagios Core

时间:2019-09-30 13:57:45

标签: powershell nagios nrpe

我具有用于监视AD同步状态的Powershell脚本:

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 -

脚本位于脚本文件夹中,

./check_nrpe -H 1.2.3.5

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

从Nagios服务器获取

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

命令(check_ad_replication)返回了无效的返回码:-196608

  

试图为退出代码设置1-3出口,但没有更改,从Powershell命令运行就可以了。有谁知道应该为错误代码设置什么

1 个答案:

答案 0 :(得分:1)

问题已解决,必须在退出代码周围添加引号,例如:

$NagiosStatus -eq "2"