<# .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! Acknowledged Alarms > Total: 4 | Acknowledged: 3 | Unacknowledged: 1 WARNING! Acknowledged Alarms: Total: 4 | Acknowledged: 4 | Unacknowledged: 0 OK! Acknowledged Alarms: Total: 0 | Acknowledged: 0 | Unacknowledged: 0 .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 .EXAMPLE .\check_vmware_triggeredalarms.ps1 -Server VCENTER .EXAMPLE .\check_vmware_triggeredalarms.ps1 -Server VCENTER -CredentialFilePath .\nagios.monitor.xml #> param ( [String] $Server, [String] $CredentialFilePath, [String] $User, [String] $Password ) <# 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 } $rootFolder = Get-Folder -Server $vc "Datacenters" #$rootFolder.ExtensionData.TriggeredAlarmState|FL $countTotalAlarms = $rootFolder.ExtensionData.TriggeredAlarmState |measure $countAcknowledgedAlarms = $rootFolder.ExtensionData.TriggeredAlarmState|Where-Object {$_.Acknowledged -eq $true} |measure $countUnacknowledgedAlarms = $rootFolder.ExtensionData.TriggeredAlarmState|Where-Object {$_.Acknowledged -ne $true} |measure $RT = 3 #UNKNOWN if ( $countUnacknowledgedAlarms.Count -gt 0 ) { #RT CRITICAL Write-Host "CRITICAL! vCenter Alarms > Total: $($countTotalAlarms.Count) # Acknowledged: $($countAcknowledgedAlarms.Count) # Unacknowledged: $($countUnacknowledgedAlarms.Count) " $rt = 2 } if ($countTotalAlarms.Count -gt 0 -and $countUnacknowledgedAlarms.Count -eq 0) { #RT WARNING Write-Host "WARNING! vCenter Alarms > Total: $($countTotalAlarms.Count) # Acknowledged: $($countAcknowledgedAlarms.Count) # Unacknowledged: $($countUnacknowledgedAlarms.Count) " $rt = 1 } if ($countTotalAlarms.Count -eq 0 ) { #RT OK Write-Host "OK! vCenter Alarms > Total: $($countTotalAlarms.Count) # Acknowledged: $($countAcknowledgedAlarms.Count) # Unacknowledged: $($countUnacknowledgedAlarms.Count) " $rt = 0 } #Write-Verbose -Verbose $countTotalAlarms.Count Disconnect-VIServer $Server -Confirm:$false exit $rt