From aff00cd7c76c7c899ccc29b42ebaa4aaedf96200 Mon Sep 17 00:00:00 2001 From: Quentin Manfroi Date: Fri, 13 Dec 2019 10:19:36 +0100 Subject: [PATCH 1/4] MON-544 allow to define empty message for warning and nodata --- common/alerting-message/inputs.tf | 4 +++- common/alerting-message/main.tf | 5 ++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/common/alerting-message/inputs.tf b/common/alerting-message/inputs.tf index 3ebe0cf..d113f84 100644 --- a/common/alerting-message/inputs.tf +++ b/common/alerting-message/inputs.tf @@ -6,12 +6,13 @@ variable "message_alert" { variable "message_warning" { description = "Define a broadcast channel for warning alerts" type = string + default = "false" } variable "message_nodata" { description = "Define a broadcast channel for nodata alerts" type = string - default = "" + default = "false" } variable "prepend_text" { @@ -26,3 +27,4 @@ variable "append_text" { default = "" } + diff --git a/common/alerting-message/main.tf b/common/alerting-message/main.tf index 88d4840..8c5c02c 100644 --- a/common/alerting-message/main.tf +++ b/common/alerting-message/main.tf @@ -10,11 +10,10 @@ EOF vars = { message_alert = var.message_alert - message_warning = var.message_warning - message_nodata = coalesce(var.message_nodata, var.message_alert) + message_warning = var.message_warning == "false" ? var.message_alert : var.message_warning + message_nodata = var.message_nodata == "false" ? var.message_alert : var.message_nodata message_recovery = join(" ", compact(distinct(list(var.message_alert, var.message_warning, var.message_nodata)))) prepend_text = var.prepend_text append_text = var.append_text } } - From 34df9e0c76865b7ae47e9ac586e1b3ef2f570286 Mon Sep 17 00:00:00 2001 From: Quentin Manfroi Date: Fri, 13 Dec 2019 14:55:50 +0100 Subject: [PATCH 2/4] MON-544 improve readme ot understand alerting message output behavior --- common/alerting-message/README.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/common/alerting-message/README.md b/common/alerting-message/README.md index 96d42f3..be89cfb 100644 --- a/common/alerting-message/README.md +++ b/common/alerting-message/README.md @@ -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 | | message_alert | Define a broadcast channel for critical alerts | string | - | yes | | 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 | ## Outputs @@ -41,3 +41,18 @@ Creates a DataDog monitor alert message with the following inputs : ## 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) + +## 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 From 25892d8302efd2077cc401855feba4e236e9866d Mon Sep 17 00:00:00 2001 From: Quentin Manfroi Date: Fri, 13 Dec 2019 15:07:14 +0100 Subject: [PATCH 3/4] Apply suggestion to common/alerting-message/main.tf --- common/alerting-message/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/alerting-message/main.tf b/common/alerting-message/main.tf index 8c5c02c..37438c4 100644 --- a/common/alerting-message/main.tf +++ b/common/alerting-message/main.tf @@ -11,7 +11,7 @@ EOF vars = { message_alert = var.message_alert message_warning = var.message_warning == "false" ? var.message_alert : var.message_warning - message_nodata = var.message_nodata == "false" ? var.message_alert : var.message_nodata + 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)))) prepend_text = var.prepend_text append_text = var.append_text From 4930d090a97264c69f71d337fb224e0c4fe41d79 Mon Sep 17 00:00:00 2001 From: Quentin Manfroi Date: Fri, 13 Dec 2019 15:08:43 +0100 Subject: [PATCH 4/4] MON-544 improve using null instead of false string --- common/alerting-message/inputs.tf | 4 ++-- common/alerting-message/main.tf | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/common/alerting-message/inputs.tf b/common/alerting-message/inputs.tf index d113f84..60c1305 100644 --- a/common/alerting-message/inputs.tf +++ b/common/alerting-message/inputs.tf @@ -6,13 +6,13 @@ variable "message_alert" { variable "message_warning" { description = "Define a broadcast channel for warning alerts" type = string - default = "false" + default = null } variable "message_nodata" { description = "Define a broadcast channel for nodata alerts" type = string - default = "false" + default = null } variable "prepend_text" { diff --git a/common/alerting-message/main.tf b/common/alerting-message/main.tf index 37438c4..a05c986 100644 --- a/common/alerting-message/main.tf +++ b/common/alerting-message/main.tf @@ -10,7 +10,7 @@ EOF vars = { message_alert = var.message_alert - message_warning = var.message_warning == "false" ? var.message_alert : var.message_warning + message_warning = var.message_warning == null ? var.message_alert : var.message_warning 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)))) prepend_text = var.prepend_text