# Imports NetworkLoadBalancingClusters module. # # This script will execute checks against NLB Cluster Nodes via powershell and nsclient++ # The script will return WARNING on a node in a Converging State. # The script will return CRITICAL if a node is in a Stopped State # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # # # Revision History # 2015-09-16 Barry Mulholland [basra.mulholland@gmail.com] 1.0 # * Initial script created # # To execute from within NSClient++ # #[NRPE Handlers] #check_nlb_status=cmd /c echo Scripts\check_nlbstatus.ps1; exit($lastexitcode) | PowerShell.exe -Command - # # On the check_nrpe command include the -t 20, since it takes some time to load the cmdlet's. # Check if NLB Module is loaded and load it if it's not if (-not (Get-Module NetworkLoadBalancingClusters)) { #Write-Host "`n`tImporting NetworkLoadBalancingClusters Module.." -ForegroundColor Yellow Import-Module NetworkLoadBalancingClusters } $outMessage = "" $status = 0 # test array #$test = @( ("SERVER1", "Converged(default)"), ("SERVER2", "Converging") ) # Check NLB Node Status foreach ($node in Get-NLBClusterNode) { # test code #foreach ($node in $test) { $nodename = $node.Name.ToString() $state = $node.State.ToString() # test variables #$nodename = $node[0] #$state = $node[1] if ($state -like "Stopped*") { if ($outmessage -ne "") { $outMessage = $outMessage + ", " } $outMessage = $outMessage + "$nodename - $state" $status = 2 } ElseIf ($state -like "Converging*") { if ($outmessage -ne "") { $outMessage = $outMessage + ", " } $outMessage = $outMessage + "$nodename - $state" if ($status -ne 2) { $status = 1 } } Elseif ($state -like "Converged*") { if ($outmessage -ne "") { $outMessage = $outMessage + ", " } $outMessage = $outMessage + "$nodename - $state" } } if ($Status -eq 2) { Write-Host "CRITICAL: " $outMessage } elseif ($Status -eq 1) { Write-Host "WARNING: " $outMessage } else { Write-Host "OK: " $outMessage } exit $status