Hi everyone,
We downloaded a script for Nagios that allows us to monitor Hyper-V replication between hosts. The script is written in Powershell and is triggered by the NSClient. This works perfectly. Now we want to use that script as a base for writing our own PowerShell checks for Nagios.
$server=get-vmreplication $returnStateOK = 0 $returnStateCritical = 2 $errormassage = "Replication works fine!" foreach($r in $server) { if($r.Health -cnotlike "Normal") { $f=1 $errormassage = "Replication-Error - " +$r.Name + "state: " + $r.Health } } if($f -eq 1) { Write-Host $errormassage exit $returnStateCritical } else { Write-Host $errormassage exit $returnStateOK }
Import-Module "C:\Program Files\NSClient++\scripts\ADFSDiagnostics.psm1" $returnStateOK = 0 $returnStateWarning = 1 $returnStateCritical = 2 $returnStateUnknown = 3 if($server=Test-AdfsServerHealth | where {$_.Result -eq "Fail"}) { $report = "warning" } else { $report="ok" } if($report -eq "warning") { $errormessage = "ADFS Health state: Warning," +$Errordetail Write-Host $errormessage exit $returnStateCritical } elseif($report -eq "ok") { $Okmessage = "ADFS Health state: OK, no problems have been found." Write-Host $Okmessage exit $returnStateOK } else { exit $returnStateUnknown }
Above is the script that we created by copy pasting anything that looked right. It results in displaying the "warning" part, I just want to use the output from
Test-AdfsServerHealth | where {$_.Result -eq "Fail"}
to display the name and/or Detail of the found problem. If we execute the above command without the rest of the script we get this result:
Does anyone know how I can capture the displayed Name and Detail and output that for my Nagios check? I tried $r.Name only because it was written in the other script aswell. Sorry for the stupid questions ;-)
Kind regards,
Dennis