I am trying to run a powershell script via NSClient using check_nrpe but it is giving unexpected output. The powershell script is fetching a performance counter from list of servers and based on it the result is send to Nagios.
Below is the software version I am using:
Nagios 3.5.1
Nagios-plugins 2.0.3
NRPE Version - 2.15
NSClient - 0.4.1.90
NSClient.ini:
[/settings/external scripts/wrapped scripts]
alias_check_scripts = powershell\\check_scripts.ps1
[/settings/external scripts/scripts]
alias_check_scripts = cmd /c echo \\scripts\\powershell\\check_scripts.ps1 ; exit($lastexitcode) | powershell.exe -command -
***********************check_scripts.ps1***********************************
Code: Select all
$returnStateOK =0
$returnStateWarning =1
$returnStateCritical =2
$returnStateUnknown =3
$servers = "ABCWPMBX1-ABC","GHIWPMBX3-DEF","DEFWPMBX2-ABC","KLMWPMBX4-DEF","PQRWVJAR2-DEF"
$ErrorActionPreference = 'Stop'
foreach ( $s in $servers )
{
try
{
$c = Get-Counter -ComputerName $s -ListSet MSExchangeIS -ea stop|select-object -ExpandProperty CounterSetName
}
catch
{
continue
}
}
if($c -Match "MSExchangeIS" )
{
$errorString = "MSExchangeIS counter is enabled for " + $s
Write-Host "Critical:"$errorString""
break
exit $returnStateCritical
}
$errorString = "MSExchangeIS counter is disabled"
Write-Host "OK:"$errorString""
exit $returnStateOK
Powershell
PS C:\Program Files\NSClient++\scripts\powershell> .\check_scripts.ps1
Critical: MSExchangeIS counter is enabled for PQRWVJAR2-DEF
CMD
C:\>cmd /c echo C:\"Program Files"\NSClient++\scripts\powershell\check_scripts.ps1 ; exit($lastexitcode) | powershell.exe -command -
Critical: MSExchangeIS counter is enabled for SCHWVJAR52-USB.collaboration.lcl
check_nrpe
[nagios@abc ~]$ /usr/lib64/nagios/plugins/check_nrpe -H x.x.x.x -c alias_check_scripts
OK: MSExchangeIS counter is disabled
Please advise where I am going wrong.