Skip to content

Commit 9a731ac

Browse files
author
Alex Moreno
authored
Add alert pausing (#809)
* Add alert pausing * update docs * Add paused to example * Regenerate docs * Remove test * Regenerate docs * Add field in examples an generate docs * Change paused to is_paused
1 parent 96453bf commit 9a731ac

File tree

5 files changed

+14
-1
lines changed

5 files changed

+14
-1
lines changed

docs/resources/rule_group.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ resource "grafana_rule_group" "my_alert_rule" {
4343
"e" = "f"
4444
"g" = "h"
4545
}
46+
is_paused = false
4647
data {
4748
ref_id = "A"
4849
query_type = ""
@@ -136,6 +137,7 @@ Optional:
136137
- `annotations` (Map of String) Key-value pairs of metadata to attach to the alert rule that may add user-defined context, but cannot be used for matching, grouping, or routing. Defaults to `map[]`.
137138
- `exec_err_state` (String) Describes what state to enter when the rule's query is invalid and the rule cannot be executed. Options are OK, Error, and Alerting. Defaults to `Alerting`.
138139
- `for` (String) The amount of time for which the rule must be breached for the rule to be considered to be Firing. Before this time has elapsed, the rule is only considered to be Pending. Defaults to `0`.
140+
- `is_paused` (Boolean) Sets whether the alert should be paused or not. Defaults to `false`.
139141
- `labels` (Map of String) Key-value pairs to attach to the alert rule that can be used in matching, grouping, and routing. Defaults to `map[]`.
140142
- `no_data_state` (String) Describes what state to enter when the rule's query returns No Data. Options are OK, NoData, and Alerting. Defaults to `NoData`.
141143

examples/resources/grafana_rule_group/resource.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ resource "grafana_rule_group" "my_alert_rule" {
2121
"e" = "f"
2222
"g" = "h"
2323
}
24+
is_paused = false
2425
data {
2526
ref_id = "A"
2627
query_type = ""

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.18
55
require (
66
github.com/Masterminds/semver/v3 v3.2.0
77
github.com/grafana/amixr-api-go-client v0.0.6
8-
github.com/grafana/grafana-api-golang-client v0.18.2
8+
github.com/grafana/grafana-api-golang-client v0.18.3
99
github.com/grafana/machine-learning-go-client v0.4.0
1010
github.com/grafana/synthetic-monitoring-agent v0.14.1
1111
github.com/grafana/synthetic-monitoring-api-go-client v0.7.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ github.com/grafana/amixr-api-go-client v0.0.6 h1:dDKSROgxg2NUuNBeF3L/0cfD9nG815O
7979
github.com/grafana/amixr-api-go-client v0.0.6/go.mod h1:N6x26XUrM5zGtK5zL5vNJnAn2JFMxLFPPLTw/6pDkFE=
8080
github.com/grafana/grafana-api-golang-client v0.18.2 h1:WPYT4Cyw0uqBHAyO619HykzNsQ98yHKFmPuJonfiW8c=
8181
github.com/grafana/grafana-api-golang-client v0.18.2/go.mod h1:24W29gPe9yl0/3A9X624TPkAOR8DpHno490cPwnkv8E=
82+
github.com/grafana/grafana-api-golang-client v0.18.3 h1:z0AhbGG6suChLb8t2fADpEO9ckPWnweYPYoCW3WpF6k=
83+
github.com/grafana/grafana-api-golang-client v0.18.3/go.mod h1:24W29gPe9yl0/3A9X624TPkAOR8DpHno490cPwnkv8E=
8284
github.com/grafana/machine-learning-go-client v0.4.0 h1:UAkJPE7xujzFTm0d9ctbX/FsCID8rqejWjnkRPGNM6E=
8385
github.com/grafana/machine-learning-go-client v0.4.0/go.mod h1:QFfZz8NkqVF8++skjkKQXJEZfpCYd8S0yTWJUpsLLTA=
8486
github.com/grafana/synthetic-monitoring-agent v0.14.1 h1:UyTCDTFr2gIJujJrspYR9MHGptdNQrbTM5Td36nDinA=

internal/resources/grafana/resource_alerting_rule_group.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@ This resource requires Grafana 9.1.0 or later.
168168
Type: schema.TypeString,
169169
},
170170
},
171+
"is_paused": {
172+
Type: schema.TypeBool,
173+
Optional: true,
174+
Default: false,
175+
Description: "Sets whether the alert should be paused or not.",
176+
},
171177
},
172178
},
173179
},
@@ -325,6 +331,7 @@ func packAlertRule(r gapi.AlertRule) (interface{}, error) {
325331
"labels": r.Labels,
326332
"annotations": r.Annotations,
327333
"data": data,
334+
"is_paused": r.IsPaused,
328335
}
329336
return json, nil
330337
}
@@ -349,6 +356,7 @@ func unpackAlertRule(raw interface{}, groupName string, folderUID string, orgID
349356
Condition: json["condition"].(string),
350357
Labels: unpackMap(json["labels"]),
351358
Annotations: unpackMap(json["annotations"]),
359+
IsPaused: json["is_paused"].(bool),
352360
}, nil
353361
}
354362

0 commit comments

Comments
 (0)