Last active
May 30, 2018 16:50
-
-
Save Dapacruz/6845ef615f72a68aab4d7f3c78d527ba to your computer and use it in GitHub Desktop.
Set Up VMware vCenter Email Alerts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$smtp_sender = 'vcenter@domain.com' | |
$smtp_recipients = 'support@domain.com' | |
$smtp_server = 'smtp.domain.com' | |
$smtp_user = '' | |
$smtp_password = '' | |
$smtp_port = '25' | |
$vcenter = $global:defaultviservers.Name | |
$alarms = @( | |
@{ | |
alarm_definition = 'Datastore usage on disk' | |
subject = 'Datastore Usage on Disk Alert' | |
transitions = @( | |
@{ | |
start_state = 'green' | |
final_state = 'yellow' | |
}, | |
@{ | |
start_state = 'yellow' | |
final_state = 'red' | |
} | |
) | |
}, | |
@{ | |
alarm_definition = 'Host CPU usage' | |
subject = 'Host CPU Usage Alert' | |
transitions = @( | |
@{ | |
start_state = 'green' | |
final_state = 'yellow' | |
}, | |
@{ | |
start_state = 'yellow' | |
final_state = 'red' | |
} | |
) | |
}, | |
@{ | |
alarm_definition = 'Host connection and power state' | |
subject = 'Host Connection and Power State Alert' | |
transitions = @( | |
@{ | |
start_state = 'green' | |
final_state = 'yellow' | |
}, | |
@{ | |
start_state = 'yellow' | |
final_state = 'red' | |
} | |
) | |
},@{ | |
alarm_definition = 'Host memory usage' | |
subject = 'Host Memory Usage Alert' | |
transitions = @( | |
@{ | |
start_state = 'green' | |
final_state = 'yellow' | |
}, | |
@{ | |
start_state = 'yellow' | |
final_state = 'red' | |
} | |
) | |
} | |
) | |
# Configure SMTP | |
Get-AdvancedSetting -Entity $vcenter -Name mail.smtp.server | Set-AdvancedSetting -Value $smtp_server -Confirm:$false | Out-Null | |
Get-AdvancedSetting -Entity $vcenter -Name mail.smtp.port | Set-AdvancedSetting -Value $smtp_port -Confirm:$false | Out-Null | |
Get-AdvancedSetting -Entity $vcenter -Name mail.sender | Set-AdvancedSetting -Value $smtp_sender -Confirm:$false | Out-Null | |
if ($smtp_user -and $smtp_password) { | |
Get-AdvancedSetting -Entity $vcenter -Name mail.smtp.username | Set-AdvancedSetting -Entity $vcenter -Value $smtp_user -Confirm:$false | Out-Null | |
Get-AdvancedSetting -Entity $vcenter -Name mail.smtp.password | Set-AdvancedSetting -Entity $vcenter -Value $smtp_password -Confirm:$false | Out-Null | |
} | |
Get-AdvancedSetting -Entity $vcenter -Name mail.smtp.server, mail.smtp.port, mail.sender, mail.smtp.username, mail.smtp.password | |
# Configure alarm actions | |
foreach ($a in $alarms) { | |
# Remove existing alarm actions | |
Get-AlarmAction -AlarmDefinition $a.alarm_definition | Remove-AlarmAction -Confirm:$false | |
# Add send email alarm action | |
$action = New-AlarmAction -AlarmDefinition $a.alarm_definition -Email -To $smtp_recipients -Subject $a.subject | |
# Define transitions | |
foreach ($trans in $a.transitions) { | |
# Skip default transition | |
if ($trans.start_state -eq 'yellow' -and $trans.final_state -eq 'red') { | |
continue | |
} | |
New-AlarmActionTrigger -AlarmAction $action -StartStatus $trans.start_state -EndStatus $trans.final_state | Out-Null | |
} | |
Write-Host "$($a.alarm_definition) action triggers:" | |
Get-AlarmActionTrigger -AlarmAction $action | Out-String | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment