|
| 1 | +--- |
| 2 | +subcategory: "Inventory" |
| 3 | +page_title: "VMware vSphere: vsphere_alarm" |
| 4 | +sidebar_current: "docs-vsphere-resource-inventory-alarm" |
| 5 | +description: |- |
| 6 | + Provides a VMware vSphere alarm resource. This can be used deployed on all kinds of vSphere inventory objects. |
| 7 | +--- |
| 8 | + |
| 9 | +# vsphere_alarm |
| 10 | + |
| 11 | +Provides a VMware vSphere alarm resource. This can be used deployed on all kinds of vSphere inventory objects. |
| 12 | + |
| 13 | +## Example Usages |
| 14 | + |
| 15 | +**Create warning alarm with an email action on a datacenter when on a host is disconnected:** |
| 16 | + |
| 17 | +```hcl |
| 18 | +resource "vsphere_alarm" "host_disconnected_warning" { |
| 19 | + name = "Host disconnected" |
| 20 | + description = "Triggers a warning when a host is disconnected" |
| 21 | + entity_type = "Datacenter" |
| 22 | + entity_id = data.vsphere_datacenter.datacenter.id |
| 23 | +
|
| 24 | + state_expression { |
| 25 | + operator = "isEqual" |
| 26 | + state_path = "runtime.connectionState" |
| 27 | + object_type = "HostSystem" |
| 28 | + yellow = "disconnected" |
| 29 | + } |
| 30 | +
|
| 31 | + email_action { |
| 32 | + to = "foo@example.com" |
| 33 | + subject = "Host disconnected" |
| 34 | + start_state = "green" |
| 35 | + final_state = "yellow" |
| 36 | + } |
| 37 | +} |
| 38 | +``` |
| 39 | + |
| 40 | +**Create critical alarm when a host CPU usage is above 95% for 5min:** |
| 41 | + |
| 42 | +```hcl |
| 43 | +resource "vsphere_alarm" "host_disconnected_warning" { |
| 44 | + name = "Host CPU usage" |
| 45 | + description = "Triggers a critical when a host CPU usage is too high" |
| 46 | + entity_type = "Datacenter" |
| 47 | + entity_id = data.vsphere_datacenter.datacenter.id |
| 48 | +
|
| 49 | + metric_expression { |
| 50 | + metric_counter_id = 2 # hosted counter ID for CPU usage |
| 51 | + operator = "isAbove" |
| 52 | + object_type = "HostSystem" |
| 53 | + red = 9500 |
| 54 | + red_interval = 300 |
| 55 | + } |
| 56 | +} |
| 57 | +``` |
| 58 | + |
| 59 | +**Create alarm to set a host in maintenance when a lacp down event occurs, and remove the maintenance when the lacp is up again:** |
| 60 | + |
| 61 | +```hcl |
| 62 | +resource "vsphere_alarm" "lacp_down_on_host" { |
| 63 | + name = "LACP down on host" |
| 64 | + description = "Set the host is maintenance if lacp goes down" |
| 65 | + entity_type = "Datacenter" |
| 66 | + entity_id = data.vsphere_datacenter.datacenter.id |
| 67 | +
|
| 68 | + # alert |
| 69 | + event_expression { |
| 70 | + event_type_id = "esx.problem.net.lacp.lag.transition.down" |
| 71 | + object_type = "HostSystem" |
| 72 | + status = "red" |
| 73 | + } |
| 74 | +
|
| 75 | + # recovery |
| 76 | + event_expression { |
| 77 | + event_type_id = "esx.problem.net.lacp.lag.transition.up" |
| 78 | + object_type = "HostSystem" |
| 79 | + status = "green" |
| 80 | + } |
| 81 | +
|
| 82 | + # enter maintenance mode if alert is triggered |
| 83 | + advanced_action { |
| 84 | + start_state = "green" |
| 85 | + final_state = "red" |
| 86 | + name = "EnterMaintenanceMode_Task" |
| 87 | + } |
| 88 | +
|
| 89 | + # remove maintenance mode on alert² recovery |
| 90 | + advanced_action { |
| 91 | + start_state = "red" |
| 92 | + final_state = "green" |
| 93 | + name = "ExitMaintenanceMode_Task" |
| 94 | + } |
| 95 | +} |
| 96 | +``` |
| 97 | + |
| 98 | +## Argument Reference |
| 99 | + |
| 100 | +The following arguments are supported: |
| 101 | + |
| 102 | +* `name` - (Required) The name of the alarm. This name needs to be unique |
| 103 | + within the vCenter. Forces a new resource if changed. |
| 104 | +* `description` - (Optional) The alarm description. |
| 105 | +* `enabled` - (Optional) Whether or not the alarm is enabled. |
| 106 | +* `entity_id` - (Required) The [managed object reference ID][docs-about-morefs] of the entity the alarm will be created in. |
| 107 | +* `entity_type` - (Required) The type of the entity the alarm will be created in. |
| 108 | +* `expression_operator` - (Optional) The logical link between expressions. |
| 109 | +* `event_expression` - (Optional) Alarm trigger expressions based on events. |
| 110 | +* `metric_expression` - (Optional) Alarm trigger expressions based on metric values. |
| 111 | +* `state_expression` - (Optional) Alarm trigger expressions based on object state changes. |
| 112 | +* `advanced_action` - (Optional) Advanced alarm action to trigger depending on the alarm state, such as entering maintenance mode. |
| 113 | +* `email_action` - (Optional) Email alarm action to trigger depending on the alarm state. |
| 114 | +* `snmp_action` - (Optional) Snmp alarm action to trigger depending on the alarm state. |
| 115 | + |
| 116 | +## Attribute Reference |
| 117 | + |
| 118 | +* `id` - The ID of the alarm. |
| 119 | + |
| 120 | +## Importing |
| 121 | + |
| 122 | +Importing vSphere alarm is not managed. |
0 commit comments