Skip to content

Commit 9d3d599

Browse files
authored
feat: add support for alarms (#2600)
Adds support for vSphere alarms resource and data source. Ref: #1312
1 parent d05a589 commit 9d3d599

File tree

9 files changed

+2044
-0
lines changed

9 files changed

+2044
-0
lines changed

docs/data-sources/alarm.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
subcategory: "Inventory"
3+
page_title: "VMware vSphere: vsphere_alarm"
4+
sidebar_current: "docs-vsphere-data-source-alarm"
5+
description: |-
6+
Provides a vSphere alarm data source. Returns attributes of a
7+
vSphere alarm.
8+
---
9+
10+
# vsphere_compute_cluster_host_group
11+
12+
The `vsphere_alarm` data source can be used to retrieve the property of a given alarm.
13+
14+
## Example Usage
15+
16+
```hcl
17+
data "vsphere_datacenter" "datacenter" {
18+
name = "dc-01"
19+
}
20+
21+
data "vsphere_alarm" "alarm" {
22+
entity_type = "Datacenter"
23+
entity_id = data.vsphere_datacenter.dc.id
24+
name = "example"
25+
}
26+
```
27+
28+
## Argument Reference
29+
30+
The following arguments are supported:
31+
32+
* `name` - (Required) The name of the host group.
33+
* `entity_id` - (Required) The [managed object reference ID][docs-about-morefs] of the entity the alarm will be created in.
34+
* `entity_type` - (Required) The type of the entity the alarm will be created in.
35+
36+
## Attribute Reference
37+
* `id`: The [managed object reference ID][docs-about-morefs] of the alarm.
38+
* `enabled` - Whether or not the alarm is enabled.
39+
* `expression_operator` - The logical link between expressions.
40+
* `event_expression` - The event expressions of the alarm.
41+
* `metric_expression` - The metric expressions of the alarm.
42+
* `state_expression` - The state expressions of the alarm.
43+
* `advanced_action` - The advanced actions of the alarm.
44+
* `email_action` - The email alarm actions of the alarm.
45+
* `snmp_action` - The snmp alarm actions of the alarm.
46+
47+
[docs-about-morefs]: /docs/providers/vsphere/index.html#use-of-managed-object-references-by-the-vsphere-provider

docs/resources/alarm.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
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

Comments
 (0)