github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/website/source/docs/providers/circonus/r/rule_set.html.markdown (about) 1 --- 2 layout: "circonus" 3 page_title: "Circonus: circonus_rule_set" 4 sidebar_current: "docs-circonus-resource-circonus_rule_set" 5 description: |- 6 Manages a Circonus rule set. 7 --- 8 9 # circonus\_rule_set 10 11 The ``circonus_rule_set`` resource creates and manages a 12 [Circonus Rule Set](https://login.circonus.com/resources/api/calls/rule_set). 13 14 ## Usage 15 16 ```hcl 17 variable "myapp-tags" { 18 type = "list" 19 default = [ "app:myapp", "owner:myteam" ] 20 } 21 22 resource "circonus_rule_set" "myapp-cert-ttl-alert" { 23 check = "${circonus_check.myapp-https.checks[0]}" 24 metric_name = "cert_end_in" 25 link = "https://wiki.example.org/playbook/how-to-renew-cert" 26 27 if { 28 value { 29 min_value = "${2 * 24 * 3600}" 30 } 31 32 then { 33 notify = [ "${circonus_contact_group.myapp-owners.id}" ] 34 severity = 1 35 } 36 } 37 38 if { 39 value { 40 min_value = "${7 * 24 * 3600}" 41 } 42 43 then { 44 notify = [ "${circonus_contact_group.myapp-owners.id}" ] 45 severity = 2 46 } 47 } 48 49 if { 50 value { 51 min_value = "${21 * 24 * 3600}" 52 } 53 54 then { 55 notify = [ "${circonus_contact_group.myapp-owners.id}" ] 56 severity = 3 57 } 58 } 59 60 if { 61 value { 62 absent = "24h" 63 } 64 65 then { 66 notify = [ "${circonus_contact_group.myapp-owners.id}" ] 67 severity = 1 68 } 69 } 70 71 tags = [ "${var.myapp-tags}" ] 72 } 73 74 resource "circonus_rule_set" "myapp-healthy-alert" { 75 check = "${circonus_check.myapp-https.checks[0]}" 76 metric_name = "duration" 77 link = "https://wiki.example.org/playbook/debug-down-app" 78 79 if { 80 value { 81 # SEV1 if it takes more than 9.5s for us to complete an HTTP request 82 max_value = "${9.5 * 1000}" 83 } 84 85 then { 86 notify = [ "${circonus_contact_group.myapp-owners.id}" ] 87 severity = 1 88 } 89 } 90 91 if { 92 value { 93 # SEV2 if it takes more than 5s for us to complete an HTTP request 94 max_value = "${5 * 1000}" 95 } 96 97 then { 98 notify = [ "${circonus_contact_group.myapp-owners.id}" ] 99 severity = 2 100 } 101 } 102 103 if { 104 value { 105 # SEV3 if the average response time is more than 500ms using a moving 106 # average over the last 10min. Any transient problems should have 107 # resolved themselves by now. Something's wrong, need to page someone. 108 over { 109 last = "10m" 110 using = "average" 111 } 112 max_value = "500" 113 } 114 115 then { 116 notify = [ "${circonus_contact_group.myapp-owners.id}" ] 117 severity = 3 118 } 119 } 120 121 if { 122 value { 123 # SEV4 if it takes more than 500ms for us to complete an HTTP request. We 124 # want to record that things were slow, but not wake anyone up if it 125 # momentarily pops above 500ms. 126 min_value = "500" 127 } 128 129 then { 130 notify = [ "${circonus_contact_group.myapp-owners.id}" ] 131 severity = 3 132 } 133 } 134 135 if { 136 value { 137 # If for whatever reason we're not recording any values for the last 138 # 24hrs, fire off a SEV1. 139 absent = "24h" 140 } 141 142 then { 143 notify = [ "${circonus_contact_group.myapp-owners.id}" ] 144 severity = 1 145 } 146 } 147 148 tags = [ "${var.myapp-tags}" ] 149 } 150 151 resource "circonus_contact_group" "myapp-owners" { 152 name = "My App Owners" 153 tags = [ "${var.myapp-tags}" ] 154 } 155 156 resource "circonus_check" "myapp-https" { 157 name = "My App's HTTPS Check" 158 159 notes = <<-EOF 160 A check to create metric streams for Time to First Byte, HTTP transaction 161 duration, and the TTL of a TLS cert. 162 EOF 163 164 collector { 165 id = "/broker/1" 166 } 167 168 http { 169 code = "^200$" 170 headers = { 171 X-Request-Type = "health-check", 172 } 173 url = "https://www.example.com/myapp/healthz" 174 } 175 176 metric { 177 name = "${circonus_metric.myapp-cert-ttl.name}" 178 tags = "${circonus_metric.myapp-cert-ttl.tags}" 179 type = "${circonus_metric.myapp-cert-ttl.type}" 180 unit = "${circonus_metric.myapp-cert-ttl.unit}" 181 } 182 183 metric { 184 name = "${circonus_metric.myapp-duration.name}" 185 tags = "${circonus_metric.myapp-duration.tags}" 186 type = "${circonus_metric.myapp-duration.type}" 187 unit = "${circonus_metric.myapp-duration.unit}" 188 } 189 190 period = 60 191 tags = ["source:circonus", "author:terraform"] 192 timeout = 10 193 } 194 195 resource "circonus_metric" "myapp-cert-ttl" { 196 name = "cert_end_in" 197 type = "numeric" 198 unit = "seconds" 199 tags = [ "${var.myapp-tags}", "resource:tls" ] 200 } 201 202 resource "circonus_metric" "myapp-duration" { 203 name = "duration" 204 type = "numeric" 205 unit = "miliseconds" 206 tags = [ "${var.myapp-tags}" ] 207 } 208 ``` 209 210 ## Argument Reference 211 212 * `check` - (Required) The Circonus ID that this Rule Set will use to search for 213 a metric stream to alert on. 214 215 * `if` - (Required) One or more ordered predicate clauses that describe when 216 Circonus should generate a notification. See below for details on the 217 structure of an `if` configuration clause. 218 219 * `link` - (Optional) A link to external documentation (or anything else you 220 feel is important) when a notification is sent. This value will show up in 221 email alerts and the Circonus UI. 222 223 * `metric_type` - (Optional) The type of metric this rule set will operate on. 224 Valid values are `numeric` (the default) and `text`. 225 226 * `notes` - (Optional) Notes about this rule set. 227 228 * `parent` - (Optional) A Circonus Metric ID that, if specified and active with 229 a severity 1 alert, will silence this rule set until all of the severity 1 230 alerts on the parent clear. This value must match the format 231 `${check_id}_${metric_name}`. 232 233 * `metric_name` - (Required) The name of the metric stream within a given check 234 that this rule set is active on. 235 236 * `tags` - (Optional) A list of tags assigned to this rule set. 237 238 ## `if` Configuration 239 240 The `if` configuration block is an 241 [ordered list of rules](https://login.circonus.com/user/docs/Alerting/Rules/Configure) that 242 are evaluated in order, first to last. The first `if` condition to evaluate 243 true shortcircuits all other `if` blocks in this rule set. An `if` block is also 244 referred to as a "rule." It is advised that all high-severity rules are ordered 245 before low-severity rules otherwise low-severity rules will mask notifications 246 that should be delivered with a high-severity. 247 248 `if` blocks are made up of two configuration blocks: `value` and `then`. The 249 `value` configuration block specifies the criteria underwhich the metric streams 250 are evaluated. The `then` configuration block, optional, specifies what action 251 to take. 252 253 ### `value` Configuration 254 255 A `value` block can have only one of several "predicate" attributes specified 256 because they conflict with each other. The list of mutually exclusive 257 predicates is dependent on the `metric_type`. To evaluate multiple predicates, 258 create multiple `if` configuration blocks in the proper order. 259 260 #### `numeric` Predicates 261 262 Metric types of type `numeric` support the following predicates. Only one of 263 the following predicates may be specified at a time. 264 265 * `absent` - (Optional) If a metric has not been observed in this duration the 266 rule will fire. When present, this duration is evaluated in terms of seconds. 267 268 * `changed` - (Optional) A boolean indicating this rule should fire when the 269 value changes (e.g. `n != n<sub>1</sub>`). 270 271 * `min_value` - (Optional) When the value is less than this value, this rule will 272 fire (e.g. `n < ${min_value}`). 273 274 * `max_value` - (Optional) When the value is greater than this value, this rule 275 will fire (e.g. `n > ${max_value}`). 276 277 Additionally, a `numeric` check can also evaluate data based on a windowing 278 function versus the last measured value in the metric stream. In order to have 279 a rule evaluate on derived value from a window, include a nested `over` 280 attribute inside of the `value` configuration block. An `over` attribute needs 281 two attributes: 282 283 * `last` - (Optional) A duration for the sliding window. Default `300s`. 284 285 * `using` - (Optional) The window function to use over the `last` interval. 286 Valid window functions include: `average` (the default), `stddev`, `derive`, 287 `derive_stddev`, `counter`, `counter_stddev`, `derive_2`, `derive_2_stddev`, 288 `counter_2`, and `counter_2_stddev`. 289 290 #### `text` Predicates 291 292 Metric types of type `text` support the following predicates: 293 294 * `absent` - (Optional) If a metric has not been observed in this duration the 295 rule will fire. When present, this duration is evaluated in terms of seconds. 296 297 * `changed` - (Optional) A boolean indicating this rule should fire when the 298 last value in the metric stream changed from it's previous value (e.g. `n != 299 n-1`). 300 301 * `contains` - (Optional) When the last value in the metric stream the value is 302 less than this value, this rule will fire (e.g. `strstr(n, ${contains}) != 303 NULL`). 304 305 * `match` - (Optional) When the last value in the metric stream value exactly 306 matches this configured value, this rule will fire (e.g. `strcmp(n, ${match}) 307 == 0`). 308 309 * `not_contain` - (Optional) When the last value in the metric stream does not 310 match this configured value, this rule will fire (e.g. `strstr(n, ${contains}) 311 == NULL`). 312 313 * `not_match` - (Optional) When the last value in the metric stream does not match 314 this configured value, this rule will fire (e.g. `strstr(n, ${not_match}) == 315 NULL`). 316 317 ### `then` Configuration 318 319 A `then` block can have the following attributes: 320 321 * `after` - (Optional) Only execute this notification after waiting for this 322 number of minutes. Defaults to immediately, or `0m`. 323 * `notify` - (Optional) A list of contact group IDs to notify when this rule is 324 sends off a notification. 325 * `severity` - (Optional) The severity level of the notification. This can be 326 set to any value between `1` and `5`. Defaults to `1`. 327 328 ## Import Example 329 330 `circonus_rule_set` supports importing resources. Supposing the following 331 Terraform (and that the referenced [`circonus_metric`](metric.html) 332 and [`circonus_check`](check.html) have already been imported): 333 334 ```hcl 335 resource "circonus_rule_set" "icmp-latency-alert" { 336 check = "${circonus_check.api_latency.checks[0]}" 337 metric_name = "maximum" 338 339 if { 340 value { 341 absent = "600s" 342 } 343 344 then { 345 notify = [ "${circonus_contact_group.test-trigger.id}" ] 346 severity = 1 347 } 348 } 349 350 if { 351 value { 352 over { 353 last = "120s" 354 using = "average" 355 } 356 357 max_value = 0.5 # units are in miliseconds 358 } 359 360 then { 361 notify = [ "${circonus_contact_group.test-trigger.id}" ] 362 severity = 2 363 } 364 } 365 } 366 ``` 367 368 It is possible to import a `circonus_rule_set` resource with the following command: 369 370 ``` 371 $ terraform import circonus_rule_set.usage ID 372 ``` 373 374 Where `ID` is the `_cid` or Circonus ID of the Rule Set 375 (e.g. `/rule_set/201285_maximum`) and `circonus_rule_set.icmp-latency-alert` is 376 the name of the resource whose state will be populated as a result of the 377 command.