Windows NRPE - 无效返回码:-196608 Nagios Core
Posted
技术标签:
【中文标题】Windows NRPE - 无效返回码:-196608 Nagios Core【英文标题】:Windows NRPE - invalid return code: -196608 Nagios Core 【发布时间】:2019-09-30 13:57:45 【问题描述】:我有这个用于监控 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】:问题已解决,必须在退出代码周围添加引号,例如:
$NagiosStatus -eq "2"
【讨论】:
以上是关于Windows NRPE - 无效返回码:-196608 Nagios Core的主要内容,如果未能解决你的问题,请参考以下文章
ValueError: int() 以 10 为底的无效文字:'196.41'
来自Icinga的带有Windows Server 2012的NRPE的NSClient ++命令