<# .SYNOPSIS This script will connect to vSphere through PowerCLI and using PowerShell, it will return information about the alerts: Will Return Something Like This! CRITICAL! Datastore AX4-1 > CapacityGB: 1003GB > FreeSpaceGB: 205GB WARNING! Datastore AX4-1 > CapacityGB: 1003GB > FreeSpaceGB: 205GB OK! Datastore AX4-1 > CapacityGB: 1003GB > FreeSpaceGB: 205GB .NOTES Author : Pedro Simões .LINK http://blog.mirandasimoes.eu .PARAMETER Server Server Full Address or Machine Name .PARAMETER CredentialFilePath Path For Credential File Generated by Function New-VICredentialStoreItem a Password file can be Generated By » New-VICredentialStoreItem -Host $VIServer -User $user -Password $password -File $CredentialFilePath .PARAMETER Name Datastore Name .PARAMETER W Return Warning in GB .PARAMETER C Return Critical in GB .EXAMPLE .\check_vmware_triggeredalarms.ps1 -Server VCENTER -Name DataStore-Name -W 50 -C 10 .EXAMPLE .\check_vmware_triggeredalarms.ps1 -Server VCENTER -CredentialFilePath .\nagios.monitor.xml -Name DataStore-Name -W 50 -C 10 .EXAMPLE .\check_vmware_triggeredalarms.ps1 -Server VCENTER -User monitor.user -Password MyPassword -Name DataStore-Name -W 50 -C 10 #> param ( [String] $Server, [String] $CredentialFilePath, [String] $User, [String] $Password, [String] $Name, [String] $W, [String] $C ) <# if ( !(Get-Module -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue) ) { if (Test-Path -Path 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\VMware, Inc.\VMware vSphere PowerCLI' ) { $Regkey = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\VMware, Inc.\VMware vSphere PowerCLI' } else { $Regkey = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\VMware, Inc.\VMware vSphere PowerCLI' } . (join-path -path (Get-ItemProperty $Regkey).InstallPath -childpath 'Scripts\Initialize-PowerCLIEnvironment.ps1') } if ( !(Get-Module -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue) ) { Write-Host "VMware modules not loaded/unable to load" Exit 99 } Get-Module -Name VMware* -ListAvailable | Import-Module #> Import-Module VMware.VimAutomation.Core if ($CredentialFilePath) { $CredentialFilePath = $CredentialFilePath -replace "`n","" -replace "\""","" # Fix for NCPA $cred = Get-VICredentialStoreItem -Host $Server -File $CredentialFilePath -ErrorAction stop $vc = Connect-VIServer -Server $Server -User $cred.User -Password $cred.Password -ErrorAction stop }elseif ( $User -ne $null -and $Password -ne $null ) { $vc = Connect-VIServer -Server $Server -User $User -Password $Password -ErrorAction stop } else { $vc = Connect-VIServer $Server } if (!$vc) { Write-Output "Failure connecting to the vCenter $Server." exit 3 } $DS = Get-Datastore -Name $Name $RT = 3 #UNKNOWN if ( $DS.FreeSpaceGB -lt $C ) { #RT CRITICAL Write-Host "CRITICAL! Datastore $Name > CapacityGB: $([math]::Round($DS.CapacityGB))GB > FreeSpaceGB:$([math]::Round($DS.FreeSpaceGB))GB " $rt = 2 } if ($DS.FreeSpaceGB -gt $C -and $DS.FreeSpaceGB -lt $W) { #RT WARNING Write-Host "WARNING! Datastore $Name > CapacityGB: $([math]::Round($DS.CapacityGB))GB > FreeSpaceGB: $([math]::Round($DS.FreeSpaceGB))GB " $rt = 1 } if ($DS.FreeSpaceGB -gt $C -and $DS.FreeSpaceGB -gt $W ) { #RT OK Write-Host "OK! Datastore $Name > CapacityGB: $([math]::Round($DS.CapacityGB))GB > FreeSpaceGB: $([math]::Round($DS.FreeSpaceGB))GB " $rt = 0 } #Write-Verbose -Verbose $countTotalAlarms.Count Disconnect-VIServer $Server -Confirm:$false exit $rt