Skip to content

Commit 601bd3d

Browse files
committed
add
1 parent 5120ae2 commit 601bd3d

File tree

3 files changed

+226
-28
lines changed

3 files changed

+226
-28
lines changed

tencentcloud/services/cls/resource_tc_cls_alarm.go

Lines changed: 84 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,40 @@ func ResourceTencentCloudClsAlarm() *schema.Resource {
9999
},
100100

101101
"condition": {
102-
Required: true,
103-
Type: schema.TypeString,
104-
Description: "triggering conditions.",
102+
Optional: true,
103+
Type: schema.TypeString,
104+
ConflictsWith: []string{"multi_conditions"},
105+
Description: "Trigger condition.",
105106
},
106107

107108
"alarm_level": {
108-
Optional: true,
109-
Computed: true,
110-
Type: schema.TypeInt,
111-
Description: "Alarm level. 0: Warning; 1: Info; 2: Critical. Default is 0.",
109+
Optional: true,
110+
Computed: true,
111+
Type: schema.TypeInt,
112+
ConflictsWith: []string{"multi_conditions"},
113+
Description: "Alarm level. 0: Warning; 1: Info; 2: Critical. Default is 0.",
114+
},
115+
116+
"multi_conditions": {
117+
Optional: true,
118+
Type: schema.TypeList,
119+
ConflictsWith: []string{"condition", "alarm_level"},
120+
Description: "Multiple triggering conditions.",
121+
Elem: &schema.Resource{
122+
Schema: map[string]*schema.Schema{
123+
"condition": {
124+
Type: schema.TypeString,
125+
Optional: true,
126+
Description: "Trigger condition.",
127+
},
128+
"alarm_level": {
129+
Type: schema.TypeInt,
130+
Optional: true,
131+
Computed: true,
132+
Description: "Alarm level. 0: Warning; 1: Info; 2: Critical. Default is 0.",
133+
},
134+
},
135+
},
112136
},
113137

114138
"trigger_count": {
@@ -296,6 +320,23 @@ func resourceTencentCloudClsAlarmCreate(d *schema.ResourceData, meta interface{}
296320
request.AlarmLevel = helper.IntUint64(v.(int))
297321
}
298322

323+
if v, ok := d.GetOk("multi_conditions"); ok {
324+
for _, item := range v.([]interface{}) {
325+
dMap := item.(map[string]interface{})
326+
multiCondition := cls.MultiCondition{}
327+
if v, ok := dMap["condition"]; ok {
328+
multiCondition.Condition = helper.String(v.(string))
329+
multiCondition.AlarmLevel = helper.IntUint64(0)
330+
}
331+
332+
if v, ok := dMap["alarm_level"]; ok {
333+
multiCondition.AlarmLevel = helper.IntUint64(v.(int))
334+
}
335+
336+
request.MultiConditions = append(request.MultiConditions, &multiCondition)
337+
}
338+
}
339+
299340
if v, ok := d.GetOkExists("trigger_count"); ok {
300341
request.TriggerCount = helper.IntInt64(v.(int))
301342
}
@@ -494,6 +535,24 @@ func resourceTencentCloudClsAlarmRead(d *schema.ResourceData, meta interface{})
494535
_ = d.Set("alarm_level", alarm.AlarmLevel)
495536
}
496537

538+
if alarm.MultiConditions != nil {
539+
tmpList := make([]map[string]interface{}, 0)
540+
for _, item := range alarm.MultiConditions {
541+
dMap := make(map[string]interface{})
542+
if item.Condition != nil {
543+
dMap["condition"] = *item.Condition
544+
}
545+
546+
if item.AlarmLevel != nil {
547+
dMap["alarm_level"] = *item.AlarmLevel
548+
}
549+
550+
tmpList = append(tmpList, dMap)
551+
}
552+
553+
_ = d.Set("multi_conditions", tmpList)
554+
}
555+
497556
if alarm.TriggerCount != nil {
498557
_ = d.Set("trigger_count", alarm.TriggerCount)
499558
}
@@ -597,7 +656,7 @@ func resourceTencentCloudClsAlarmUpdate(d *schema.ResourceData, meta interface{}
597656
request.AlarmId = &alarmId
598657
mutableArgs := []string{
599658
"name", "alarm_targets", "monitor_time", "condition", "alarm_level",
600-
"trigger_count", "alarm_period", "alarm_notice_ids",
659+
"multi_conditions", "trigger_count", "alarm_period", "alarm_notice_ids",
601660
"status", "message_template", "call_back", "analysis",
602661
}
603662

@@ -671,6 +730,23 @@ func resourceTencentCloudClsAlarmUpdate(d *schema.ResourceData, meta interface{}
671730
request.AlarmLevel = helper.IntUint64(v.(int))
672731
}
673732

733+
if v, ok := d.GetOk("multi_conditions"); ok {
734+
for _, item := range v.([]interface{}) {
735+
dMap := item.(map[string]interface{})
736+
multiCondition := cls.MultiCondition{}
737+
if v, ok := dMap["condition"]; ok {
738+
multiCondition.Condition = helper.String(v.(string))
739+
multiCondition.AlarmLevel = helper.IntUint64(0)
740+
}
741+
742+
if v, ok := dMap["alarm_level"]; ok {
743+
multiCondition.AlarmLevel = helper.IntUint64(v.(int))
744+
}
745+
746+
request.MultiConditions = append(request.MultiConditions, &multiCondition)
747+
}
748+
}
749+
674750
if v, ok := d.GetOkExists("trigger_count"); ok {
675751
request.TriggerCount = helper.IntInt64(v.(int))
676752
}

tencentcloud/services/cls/resource_tc_cls_alarm.md

Lines changed: 68 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,73 @@ Provides a resource to create a cls alarm
22

33
Example Usage
44

5+
Use single condition
6+
57
```hcl
68
resource "tencentcloud_cls_alarm" "example" {
7-
name = "tf-example"
9+
name = "tf-example"
810
alarm_notice_ids = [
9-
"notice-0850756b-245d-4bc7-bb27-2a58fffc780b",
11+
"notice-c2af43ee-1a4b-4c4a-ae3e-f81481280101",
1012
]
1113
alarm_period = 15
12-
condition = "test"
13-
alarm_level = 0
14+
condition = "$1.source='10.0.0.1'"
15+
alarm_level = 1
1416
message_template = "{{.Label}}"
1517
status = true
16-
tags = {
17-
"createdBy" = "terraform"
18-
}
19-
trigger_count = 1
18+
trigger_count = 1
2019
2120
alarm_targets {
21+
logset_id = "e74efb8e-f647-48b2-a725-43f11b122081"
22+
topic_id = "59cf3ec0-1612-4157-be3f-341b2e7a53cb"
23+
query = "status:>500 | select count(*) as errorCounts"
24+
start_time_offset = -15
2225
end_time_offset = 0
23-
logset_id = "33aaf0ae-6163-411b-a415-9f27450f68db"
2426
number = 1
27+
syntax_rule = 1
28+
}
29+
30+
analysis {
31+
content = "__FILENAME__"
32+
name = "terraform"
33+
type = "field"
34+
35+
config_info {
36+
key = "QueryIndex"
37+
value = "1"
38+
}
39+
}
40+
41+
monitor_time {
42+
time = 1
43+
type = "Period"
44+
}
45+
46+
tags = {
47+
createdBy = "terraform"
48+
}
49+
}
50+
```
51+
52+
Use multi conditions
53+
54+
```hcl
55+
resource "tencentcloud_cls_alarm" "example" {
56+
name = "tf-example"
57+
alarm_notice_ids = [
58+
"notice-c2af43ee-1a4b-4c4a-ae3e-f81481280101",
59+
]
60+
alarm_period = 15
61+
message_template = "{{.Label}}"
62+
status = true
63+
trigger_count = 1
64+
65+
alarm_targets {
66+
logset_id = "e74efb8e-f647-48b2-a725-43f11b122081"
67+
topic_id = "59cf3ec0-1612-4157-be3f-341b2e7a53cb"
2568
query = "status:>500 | select count(*) as errorCounts"
2669
start_time_offset = -15
27-
topic_id = "88735a07-bea4-4985-8763-e9deb6da4fad"
70+
end_time_offset = 0
71+
number = 1
2872
syntax_rule = 1
2973
}
3074
@@ -39,10 +83,24 @@ resource "tencentcloud_cls_alarm" "example" {
3983
}
4084
}
4185
86+
multi_conditions {
87+
condition = "[$1.__QUERYCOUNT__]> 0"
88+
alarm_level = 1
89+
}
90+
91+
multi_conditions {
92+
condition = "$1.source='10.0.0.1'"
93+
alarm_level = 2
94+
}
95+
4296
monitor_time {
4397
time = 1
4498
type = "Period"
4599
}
100+
101+
tags = {
102+
createdBy = "terraform"
103+
}
46104
}
47105
```
48106

website/docs/r/cls_alarm.html.markdown

Lines changed: 74 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,73 @@ Provides a resource to create a cls alarm
1313

1414
## Example Usage
1515

16+
### Use single condition
17+
1618
```hcl
1719
resource "tencentcloud_cls_alarm" "example" {
1820
name = "tf-example"
1921
alarm_notice_ids = [
20-
"notice-0850756b-245d-4bc7-bb27-2a58fffc780b",
22+
"notice-c2af43ee-1a4b-4c4a-ae3e-f81481280101",
2123
]
2224
alarm_period = 15
23-
condition = "test"
24-
alarm_level = 0
25+
condition = "$1.source='10.0.0.1'"
26+
alarm_level = 1
2527
message_template = "{{.Label}}"
2628
status = true
27-
tags = {
28-
"createdBy" = "terraform"
29-
}
30-
trigger_count = 1
29+
trigger_count = 1
3130
3231
alarm_targets {
32+
logset_id = "e74efb8e-f647-48b2-a725-43f11b122081"
33+
topic_id = "59cf3ec0-1612-4157-be3f-341b2e7a53cb"
34+
query = "status:>500 | select count(*) as errorCounts"
35+
start_time_offset = -15
3336
end_time_offset = 0
34-
logset_id = "33aaf0ae-6163-411b-a415-9f27450f68db"
3537
number = 1
38+
syntax_rule = 1
39+
}
40+
41+
analysis {
42+
content = "__FILENAME__"
43+
name = "terraform"
44+
type = "field"
45+
46+
config_info {
47+
key = "QueryIndex"
48+
value = "1"
49+
}
50+
}
51+
52+
monitor_time {
53+
time = 1
54+
type = "Period"
55+
}
56+
57+
tags = {
58+
createdBy = "terraform"
59+
}
60+
}
61+
```
62+
63+
### Use multi conditions
64+
65+
```hcl
66+
resource "tencentcloud_cls_alarm" "example" {
67+
name = "tf-example"
68+
alarm_notice_ids = [
69+
"notice-c2af43ee-1a4b-4c4a-ae3e-f81481280101",
70+
]
71+
alarm_period = 15
72+
message_template = "{{.Label}}"
73+
status = true
74+
trigger_count = 1
75+
76+
alarm_targets {
77+
logset_id = "e74efb8e-f647-48b2-a725-43f11b122081"
78+
topic_id = "59cf3ec0-1612-4157-be3f-341b2e7a53cb"
3679
query = "status:>500 | select count(*) as errorCounts"
3780
start_time_offset = -15
38-
topic_id = "88735a07-bea4-4985-8763-e9deb6da4fad"
81+
end_time_offset = 0
82+
number = 1
3983
syntax_rule = 1
4084
}
4185
@@ -50,10 +94,24 @@ resource "tencentcloud_cls_alarm" "example" {
5094
}
5195
}
5296
97+
multi_conditions {
98+
condition = "[$1.__QUERYCOUNT__]> 0"
99+
alarm_level = 1
100+
}
101+
102+
multi_conditions {
103+
condition = "$1.source='10.0.0.1'"
104+
alarm_level = 2
105+
}
106+
53107
monitor_time {
54108
time = 1
55109
type = "Period"
56110
}
111+
112+
tags = {
113+
createdBy = "terraform"
114+
}
57115
}
58116
```
59117

@@ -64,14 +122,15 @@ The following arguments are supported:
64122
* `alarm_notice_ids` - (Required, Set: [`String`]) list of alarm notice id.
65123
* `alarm_period` - (Required, Int) alarm repeat cycle.
66124
* `alarm_targets` - (Required, List) list of alarm target.
67-
* `condition` - (Required, String) triggering conditions.
68125
* `monitor_time` - (Required, List) monitor task execution time.
69126
* `name` - (Required, String) log alarm name.
70127
* `trigger_count` - (Required, Int) continuous cycle.
71128
* `alarm_level` - (Optional, Int) Alarm level. 0: Warning; 1: Info; 2: Critical. Default is 0.
72129
* `analysis` - (Optional, List) multidimensional analysis.
73130
* `call_back` - (Optional, List) user define callback.
131+
* `condition` - (Optional, String) Trigger condition.
74132
* `message_template` - (Optional, String) user define alarm notice.
133+
* `multi_conditions` - (Optional, List) Multiple triggering conditions.
75134
* `status` - (Optional, Bool) whether to enable the alarm policy.
76135
* `tags` - (Optional, Map) Tag description list.
77136

@@ -107,6 +166,11 @@ The `monitor_time` object supports the following:
107166
* `time` - (Required, Int) time period or point in time.
108167
* `type` - (Required, String) Period for periodic execution, Fixed for regular execution.
109168

169+
The `multi_conditions` object supports the following:
170+
171+
* `alarm_level` - (Optional, Int) Alarm level. 0: Warning; 1: Info; 2: Critical. Default is 0.
172+
* `condition` - (Optional, String) Trigger condition.
173+
110174
## Attributes Reference
111175

112176
In addition to all arguments above, the following attributes are exported:

0 commit comments

Comments
 (0)