Merge branch 'MON-544_allow_empty_message' into 'master'

MON-544 allow to define empty message for warning and nodata

Closes MON-544

See merge request claranet/pt-monitoring/projects/datadog/terraform/monitors!148
This commit is contained in:
Quentin Manfroi 2019-12-13 15:20:56 +01:00
commit 736a2e5b3d
3 changed files with 21 additions and 5 deletions

View File

@ -29,7 +29,7 @@ Creates a DataDog monitor alert message with the following inputs :
| append_text | Optional free text string to append to alert | string | `` | no | | append_text | Optional free text string to append to alert | string | `` | no |
| message_alert | Define a broadcast channel for critical alerts | string | - | yes | | message_alert | Define a broadcast channel for critical alerts | string | - | yes |
| message_nodata | Define a broadcast channel for nodata alerts | string | `` | no | | message_nodata | Define a broadcast channel for nodata alerts | string | `` | no |
| message_warning | Define a broadcast channel for warning alerts | string | - | yes | | message_warning | Define a broadcast channel for warning alerts | string | - | no |
| prepend_text | Optional free text string to prepend to alert | string | `` | no | | prepend_text | Optional free text string to prepend to alert | string | `` | no |
## Outputs ## Outputs
@ -41,3 +41,18 @@ Creates a DataDog monitor alert message with the following inputs :
## Related documentation ## Related documentation
Datadog notifications official documentation: [https://docs.datadoghq.com/monitors/notifications/?tab=is_alertis_warning](https://docs.datadoghq.com/monitors/notifications/?tab=is_alertis_warning) Datadog notifications official documentation: [https://docs.datadoghq.com/monitors/notifications/?tab=is_alertis_warning](https://docs.datadoghq.com/monitors/notifications/?tab=is_alertis_warning)
## Notes
This module aims to generate a valid message to split notification into different destinations based on its type (alert, warning, no data).
If this way matchs your need so you should be able to use its output alone directly for your monitors.
You can even use `append_text` and `prepend_text` variables to add context or documentation to monitors.
Else you can still use its output with one or multiple destinations to use it in your own messsage (i.e. with `{{#is_match}}` splitting mechanism).
Here is some tips to understand the behavior of this module and espacially its resulted output:
* Only `message_alert` is mandatory
* If `message_warning` or `message_nodata` are not defined it will use `message_alert` by default
* You can "disable" one notification type by set its variable to empty (i.e. `message_warning = ""`)
* feel free to use this module multiple times with different combinations to suit your needs

View File

@ -6,12 +6,13 @@ variable "message_alert" {
variable "message_warning" { variable "message_warning" {
description = "Define a broadcast channel for warning alerts" description = "Define a broadcast channel for warning alerts"
type = string type = string
default = null
} }
variable "message_nodata" { variable "message_nodata" {
description = "Define a broadcast channel for nodata alerts" description = "Define a broadcast channel for nodata alerts"
type = string type = string
default = "" default = null
} }
variable "prepend_text" { variable "prepend_text" {
@ -26,3 +27,4 @@ variable "append_text" {
default = "" default = ""
} }

View File

@ -10,11 +10,10 @@ EOF
vars = { vars = {
message_alert = var.message_alert message_alert = var.message_alert
message_warning = var.message_warning message_warning = var.message_warning == null ? var.message_alert : var.message_warning
message_nodata = coalesce(var.message_nodata, var.message_alert) message_nodata = var.message_nodata == null ? var.message_alert : var.message_nodata
message_recovery = join(" ", compact(distinct(list(var.message_alert, var.message_warning, var.message_nodata)))) message_recovery = join(" ", compact(distinct(list(var.message_alert, var.message_warning, var.message_nodata))))
prepend_text = var.prepend_text prepend_text = var.prepend_text
append_text = var.append_text append_text = var.append_text
} }
} }