четверг, 17 июля 2014 г.

Как в vCenter включить отправку email оповещений для всех преднастроенных алармов (vmware enable all alarm definitions to receive email)

Если нужно сделать простой мониторинг инфраструктуры виртуализации штатными средствами VMware vCenter Server, то необходимо настроить email оповещения для преднастроенных событий (definitions).

Сделать это можно вручную, но vSphere 5.5 таких преднастроенных событий 66. Поэтому логично включить оповещения с помощью скрипта.


Подходящий скрипт я нашел на сайте fixingitpro.com для версии 5.1 и 5.0.
Поскольку в разных версиях vSphere, компания VMware  меняет названия некоторых преднастроенных событий (definitions), то скрипт вызывал ошибки при выполнении так, что пришлось его переделать под vSphere 5.5. Результат представлен ниже(я упростил скрипт в плане повторяемости событий, теперь все события сопровождаются отправкой только одного письма).
$user="administrator"
$pass="Passw0rd"
$vCenterServer="192.168.33.156"


$MailtoAddresses= "email1@email.com","email2@email.com"


#----Connect to the vCenter Server

Connect-VIServer -Server $vCenterServer -Protocol https -User $user -Password $pass -WarningAction SilentlyContinue | Out-Null

$sessionManager = Get-View -Id $global:DefaultVIServer.ExtensionData.Content.SessionManager
$sessionManager.SetLocale("en-US")

#----These Alarms will send a single email message and not repeat ----
$Alarms="License inventory monitoring",`
"Datastore usage on disk",`
"Virtual machine memory usage",`
"Virtual machine Consolidation Needed status",`
"vSphere Distributed Switch teaming matched status",`
"Virtual machine CPU usage",`
"vSphere Distributed Switch MTU supported status",`
"vSphere Distributed Switch MTU matched status",`
"vSphere Distributed Switch VLAN trunked status",`
"SRM Consistency Group Violation",`
"The host license edition is not compatible with the vCenter Server license edition",`
"Pre-4.1 host connected to SIOC-enabled datastore",`
"License capacity monitoring",`
"vSphere HA virtual machine monitoring error",`
"vSphere HA virtual machine monitoring action",`
"vSphere HA virtual machine failover failed",`
"Host service console swap rates",`
"vSphere HA host status",`
"Cannot find vSphere HA master agent",`
"vSphere HA failover in progress",`
"Insufficient vSphere HA failover resources",`
"Datastore cluster is out of space",`
"Datastore is in multiple datacenters",`
"Storage DRS is not supported on a host",`
"Storage DRS recommendation",`
"Datastore capability alarm",`
"Thin-provisioned volume capacity threshold exceeded",`
"Host memory usage",`
"Health status monitoring",`
"License user threshold monitoring",`
"Host Baseboard Management Controller status",`
"Host IPMI System Event Log status",`
"Unmanaged workload detected on SIOC-enabled datastore",`
"VMKernel NIC not configured correctly",`
"Network uplink redundancy degraded",`
"Network uplink redundancy lost",`
"Network connectivity lost",`
"Virtual machine Fault Tolerance state changed",`
"Host CPU usage",`
"Health status changed alarm",`
"License error",`
"Exit standby error",`
"Migration error",`
"Cannot connect to storage",`
"Host connection failure",`
"Virtual machine error",`
"Host error",`
"Host storage status",`
"Status of other host hardware objects",`
"Virtual Machine Fault Tolerance vLockStep interval Status Changed",`
"Host battery status",`
"Host hardware system board status",`
"Host hardware power status",`
"Host hardware temperature status",`
"Host hardware voltage",`
"Host hardware fan status",`
"Host memory status",`
"Host processor status",`
"No compatible host for Secondary VM",`
"Expired Virtual SAN license",`
"Host SSD capacity exceeds the licensed limit for Virtual SAN",`
"Host vendor provider registration",`
"Host virtual flash resource usage",`
"Host virtual flash resource status",`
"Datastore compliance alarm",`
"VM storage compliance alarm",`
"Timed out starting Secondary VM",`
"Host connection and power state"


#---Set Alarm Action for Low Priority Alarms---
Foreach ($Alarm in $Alarms) {
    Get-AlarmDefinition -Name "$Alarm" | Get-AlarmAction -ActionType SendEmail| Remove-AlarmAction -Confirm:$false
    Get-AlarmDefinition -Name "$Alarm" | New-AlarmAction -Email -To @($MailtoAddresses)
    Get-AlarmDefinition -Name "$Alarm" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Green" -EndStatus "Yellow"
    #Get-AlarmDefinition -Name "$Alarm" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Yellow" -EndStatus "Red"  # This ActionTrigger is enabled by default.
    Get-AlarmDefinition -Name "$Alarm" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Red" -EndStatus "Yellow"
    Get-AlarmDefinition -Name "$Alarm" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Yellow" -EndStatus "Green"
}


#---Disconnect from vCenter Server----
Disconnect-VIServer -Server $vCenterServer -Force:$true -Confirm:$false

Комментариев нет:

Отправить комментарий