VMware: Change Alarm-Actions with PowerCLI
I’m working on a project for a company that is running a big cloud datacenter, the organization is 24/7 and some of my colleagues need to monitor the environment week by week (standby shifts). Once a week we need to change some alarm actions to send the Alarm notifications to a different email address.. because it’s a lot of work to do this by hand I tried to script this.
You must change the email address value in the script.. and automatically change the rest of the definitions.
$MailToRandom1 = "[email protected]"
Here’s my script:
#====================================================================# # SCRIPT: Change_Alarm_Datacenter.ps1 # # FUNCTION: Modify multiple Alarm definitions in vCenter # # CREATED: 10/06/2011 # # VERSION: v.1.1 # #====================================================================# # CHANGELOG: # # # # v.1.1 # # - Deleted email body # # - Added Alarm definition # # - Added changelog # # # # v.1.0 # # - First Release # # # #====================================================================# # Note: You only have to change the "MailToRandom1" value in "Custom # # Definitions" to change the alarm action # #====================================================================# # Connect vCenter server; #--------------------------------------------------------------------# $vCenterServer = "vcenter-server" $user = "username" $pass = "password" if ( $DefaultVIServers.Length -lt 1 ) { Connect-VIServer -Server $vCenterServer -Protocol https -User $user -Password $pass -WarningAction SilentlyContinue | Out-Null } #--------------------------------------------------------------------# # Custom Definitions; #--------------------------------------------------------------------# $actType = "SendEmailAction" $MailToRandom1 = "[email protected]" $MailToDefault1 = "[email protected]" $MailToDefault2 = "[email protected]" $actAlarm1 = "Machine suspended" $actAlarm2 = "Datastore usage" $actAlarm3 = "Snapshot alarm" $actSubject = "Get-AlarmDefinition" #--------------------------------------------------------------------# # Delete Alarm Trigger; #--------------------------------------------------------------------# Get-AlarmDefinition -Name "$actAlarm1" , "$actAlarm2" , "$actAlarm3" | Get-AlarmAction | Remove-AlarmAction -Confirm:$false #--------------------------------------------------------------------# # Create Alarm Trigger; #--------------------------------------------------------------------# Get-AlarmDefinition -Name "$actAlarm1" , "$actAlarm2" , "$actAlarm3" | New-AlarmAction -Email -To "$MailToRandom1" , "$MailToDefault1" , "$MailToDefault2" Get-AlarmDefinition -Name "$actAlarm1" , "$actAlarm2" , "$actAlarm3" | Get-AlarmAction | New-AlarmActionTrigger -StartStatus "Green" -EndStatus "Yellow" #--------------------------------------------------------------------# # Disconnect vCenter server; #--------------------------------------------------------------------# Disconnect-VIServer -Server $vCenterServer -Force:$true -Confirm:$false #--------------------------------------------------------------------#
Recent Comments