# Check available size on datastores on VMWare ESX # # Revision History # 2014-03-10 Willion van Es - Netdata [w.vanes@netdata.nl] 1.0 code initial created # 2014-03-10 Robin Smit - Netdata [ r.smit@netdata.nl / info@robinsmit.nl ] # To execute from within NSClient++ # #[NRPE Handlers] #check_exchange_dag_indexstate_health=cmd /c echo C:\Scripts\NagiosMonitoring_ExchangeContentIndexStateHealth.ps1 | PowerShell.exe -Command - # # On the check_nrpe command include the -t 20, since it takes some time to load # the vSphere cmdlet's. if ( (Get-PSSnapin -Name VMware.VimAutomation.Core -ErrorAction:SilentlyContinue) -eq $null) { add-pssnapin VMware.VimAutomation.Core } $connect = connect-viserver ip.ad.dr.es -user administrator -password ******* -WarningAction SilentlyContinue $NagiosStatus = "0" $NagiosDescription = "" $datastorecheck = "SYN-SATA-1" $datastores = get-datastore $datastorecheck | select-object Name,FreespaceGB | Sort Name ForEach ($datastore in $datastores) { $datastorename = $datastore | select-object -ExpandProperty Name $datastoresize = $datastore | Select-Object -ExpandProperty FreespaceGB $comment = "GB available" if ($NagiosDescription -ne "") { # Format the output for Nagios $NagiosDescription = "" } if ($datastoresize -lt 50) { if ($datastoresize -lt 30) { #minder als 30GB vrij $NagiosDescription = $NagiosDescription + $datastorename + " = " + $datastoresize + $comment # Set the status to Critical. $NagiosStatus = "2" #echo $datastorename $datastoresize " lt 30" } else { $NagiosDescription = $NagiosDescription + $datastorename + " = " + $datastoresize + $comment # Set the status to Warning. $NagiosStatus = "1" #echo $datastorename $datastoresize " lt 50" } } if ($datastoresize -gt 50) { #meer als 50GB vrij $NagiosDescription = $NagiosDescription + $datastorename + " = " + $datastoresize + $comment # Set the status to failed. $NagiosStatus = "0" #echo $datastorename $datastoresize " bg 50" } if ($NagiosStatus -eq "2") { Write-Host "CRITICAL:" $NagiosDescription #$NagiosStatus = "0" #$NagiosDescription = "" } if ($NagiosStatus -eq "1") { Write-Host "Warning:" $NagiosDescription #$NagiosStatus = "0" #$NagiosDescription = "" } if ($NagiosStatus -eq "0") { Write-Host "OK:" Datastore $datastorename has enough space available } exit $NagiosStatus } #end foreach