SHARE
TWEET

PowerCLI Script to automatically setup vCenter Alarm Email

a guest Apr 25th, 2016 240 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $user="administrator"
  2. $pass="a-bloody-password"
  3. $vCenterServer="192.168.111.111"
  4.  
  5.  
  6. $MailtoAddresses= "email1@gmail.com","email2@gmail.com"
  7.  
  8.  
  9. #----Connect to the vCenter Server
  10.  
  11. Connect-VIServer -Server $vCenterServer -Protocol https -User $user -Password $pass -WarningAction SilentlyContinue | Out-Null
  12.  
  13. $sessionManager = Get-View -Id $global:DefaultVIServer.ExtensionData.Content.SessionManager
  14. $sessionManager.SetLocale(“en-US”)
  15.  
  16. #----These Alarms will send a single email message and not repeat ----
  17. $LowPriorityAlarms="Timed out starting Secondary VM",`
  18. "No compatible host for Secondary VM",`
  19. "Virtual Machine Fault Tolerance vLockStep interval Status Changed",`
  20. "Migration error",`
  21. "Exit standby error",`
  22. "License error",`
  23. "Virtual machine Fault Tolerance state changed",`
  24. "VMKernel NIC not configured correctly",`
  25. "Unmanaged workload detected on SIOC-enabled datastore",`
  26. "Host IPMI System Event Log status",`
  27. "Host Baseboard Management Controller status",`
  28. "License user threshold monitoring",`
  29. "Datastore capability alarm",`
  30. "Storage DRS recommendation",`
  31. "Storage DRS is not supported on a host",`
  32. "Datastore is in multiple datacenters",`
  33. "Insufficient vSphere HA failover resources",`
  34. "License capacity monitoring",`
  35. "Virtual machine cpu usage",`
  36. "Virtual machine memory usage",`
  37. "License inventory monitoring"
  38.  
  39. #----These Alarms will repeat every 24 hours----
  40. $MediumPriorityAlarms=`
  41. "Virtual machine error",`
  42. "Health status changed alarm",`
  43. "Host cpu usage",`
  44. "Host memory usage",`
  45. "Cannot find vSphere HA master agent",`
  46. "vSphere HA host status",`
  47. "Host service console swap rates",`
  48. "vSphere HA virtual machine monitoring action",`
  49. "vSphere HA virtual machine monitoring error"
  50.  
  51.  
  52. #----These Alarms will repeat every 2 hours----
  53. $HighPriorityAlarms=`
  54. "Host connection and power state",`
  55. "Host processor status",`
  56. "Host memory status",`
  57. "Host hardware fan status",`
  58. "Host hardware voltage",`
  59. "Host hardware temperature status",`
  60. "Host hardware power status",`
  61. "Host hardware system board status",`
  62. "Host battery status",`
  63. "Status of other host hardware objects",`
  64. "Host storage status",`
  65. "Host error",`
  66. "Host connection failure",`
  67. "Cannot connect to storage",`
  68. "Network connectivity lost",`
  69. "Network uplink redundancy lost",`
  70. "Network uplink redundancy degraded",`
  71. "Thin-provisioned volume capacity threshold exceeded",`
  72. "Datastore cluster is out of space",`
  73. "vSphere HA failover in progress",`
  74. "vSphere HA virtual machine failover failed",`
  75. "Datastore usage on disk"
  76.  
  77. #---Set Alarm Action for Low Priority Alarms---
  78. Foreach ($LowPriorityAlarm in $LowPriorityAlarms) {
  79.     Get-AlarmDefinition -Name "$LowPriorityAlarm" | Get-AlarmAction -ActionType SendEmail| Remove-AlarmAction -Confirm:$false
  80.     Get-AlarmDefinition -Name "$LowPriorityAlarm" | New-AlarmAction -Email -To @($MailtoAddresses)
  81.     Get-AlarmDefinition -Name "$LowPriorityAlarm" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Green" -EndStatus "Yellow"
  82.     #Get-AlarmDefinition -Name "$LowPriorityAlarm" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Yellow" -EndStatus "Red"  # This ActionTrigger is enabled by default.
  83.     Get-AlarmDefinition -Name "$LowPriorityAlarm" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Red" -EndStatus "Yellow"
  84.     Get-AlarmDefinition -Name "$LowPriorityAlarm" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Yellow" -EndStatus "Green"
  85. }
  86.  
  87. #---Set Alarm Action for Medium Priority Alarms---
  88. Foreach ($MediumPriorityAlarm in $MediumPriorityAlarms) {
  89.     Get-AlarmDefinition -Name "$MediumPriorityAlarm" | Get-AlarmAction -ActionType SendEmail| Remove-AlarmAction -Confirm:$false
  90.     Set-AlarmDefinition "$MediumPriorityAlarm" -ActionRepeatMinutes (60 * 24) # 24 Hours
  91.     Get-AlarmDefinition -Name "$MediumPriorityAlarm" | New-AlarmAction -Email -To @($MailtoAddresses)
  92.     Get-AlarmDefinition -Name "$MediumPriorityAlarm" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Green" -EndStatus "Yellow"
  93.     Get-AlarmDefinition -Name "$MediumPriorityAlarm" | Get-AlarmAction -ActionType SendEmail | Get-AlarmActionTrigger | Select -First 1 | Remove-AlarmActionTrigger -Confirm:$false
  94.     Get-AlarmDefinition -Name "$MediumPriorityAlarm" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Yellow" -EndStatus "Red" -Repeat
  95.     Get-AlarmDefinition -Name "$MediumPriorityAlarm" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Red" -EndStatus "Yellow"
  96.     Get-AlarmDefinition -Name "$MediumPriorityAlarm" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Yellow" -EndStatus "Green"
  97. }
  98.  
  99. #---Set Alarm Action for High Priority Alarms---
  100. Foreach ($HighPriorityAlarm in $HighPriorityAlarms) {
  101.     Get-AlarmDefinition -Name "$HighPriorityAlarm" | Get-AlarmAction -ActionType SendEmail| Remove-AlarmAction -Confirm:$false
  102.     Set-AlarmDefinition "$HighPriorityAlarm" -ActionRepeatMinutes (60 * 2) # 2 hours
  103.     Get-AlarmDefinition -Name "$HighPriorityAlarm" | New-AlarmAction -Email -To @($MailtoAddresses)
  104.     Get-AlarmDefinition -Name "$HighPriorityAlarm" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Green" -EndStatus "Yellow"
  105.     Get-AlarmDefinition -Name "$HighPriorityAlarm" | Get-AlarmAction -ActionType SendEmail | Get-AlarmActionTrigger | Select -First 1 | Remove-AlarmActionTrigger -Confirm:$false
  106.     Get-AlarmDefinition -Name "$HighPriorityAlarm" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Yellow" -EndStatus "Red" -Repeat
  107.     Get-AlarmDefinition -Name "$HighPriorityAlarm" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Red" -EndStatus "Yellow"
  108.     Get-AlarmDefinition -Name "$HighPriorityAlarm" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Yellow" -EndStatus "Green"
  109. }
  110.  
  111. #---Disconnect from vCenter Server----
  112. Disconnect-VIServer -Server $vCenterServer -Force:$true -Confirm:$false
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top