From 35edf309303847a61d654fd13b9e04bc8a224f1e Mon Sep 17 00:00:00 2001 From: Quentin Manfroi Date: Fri, 10 Aug 2018 16:57:09 +0200 Subject: [PATCH] MON-273 add filter tags module --- common/alerting-message/README.md | 19 +++++-------- common/filter-tags/README.md | 45 +++++++++++++++++++++++++++++++ common/filter-tags/inputs.tf | 20 ++++++++++++++ common/filter-tags/locals.tf | 4 +++ common/filter-tags/output.tf | 10 +++++++ 5 files changed, 85 insertions(+), 13 deletions(-) create mode 100644 common/filter-tags/README.md create mode 100644 common/filter-tags/inputs.tf create mode 100644 common/filter-tags/locals.tf create mode 100644 common/filter-tags/output.tf diff --git a/common/alerting-message/README.md b/common/alerting-message/README.md index 2a5d870..49ac413 100644 --- a/common/alerting-message/README.md +++ b/common/alerting-message/README.md @@ -1,8 +1,6 @@ -Alerting Message Datadog Generator -================================== +# ALERTING MESSAGE Datadog Generator -How to use this module ----------------------- +## How to use this module ``` module "datadog-message-alerting" { @@ -14,8 +12,7 @@ module "datadog-message-alerting" { } ``` -Purpose -------- +## Purpose Creates a DataDog monitor alert message with the following inputs : @@ -25,8 +22,7 @@ Creates a DataDog monitor alert message with the following inputs : * Prepend text free string * Append text free string -Inputs ------- +## Inputs | Name | Description | Type | Default | Required | |------|-------------|:----:|:-----:|:-----:| @@ -36,14 +32,11 @@ Inputs | message_warning | Define a broadcast channel for warning alerts | string | - | yes | | prepend_text | Optional free text string to prepend to alert | string | `` | no | -Outputs -------- +## Outputs | Name | Description | |------|-------------| | alerting-message | The generated message string | -Related documentation ---------------------- +## Related documentation -DataDog documentation: [https://docs.datadoghq.com/integrations/azure_app_services](https://docs.datadoghq.com/integrations/azure_app_services) diff --git a/common/filter-tags/README.md b/common/filter-tags/README.md new file mode 100644 index 0000000..80ce730 --- /dev/null +++ b/common/filter-tags/README.md @@ -0,0 +1,45 @@ +# FILTER TAGS Datadog Generator + +## How to use this module + +This module usage should be transparent because it should be used inside each monitors set directly. +Here is a simple example but it is advisable to see how are created other existing monitors sets: + +``` +module "filter-tags" { + source = "../../common/filter-tags" + + environment = "${var.environment}" + resource = "my_resource" + filter_tags_use_defaults = "${var.filter_tags_use_defaults}" + filter_tags_custom = "${var.filter_tags_custom}" +} +``` + +## Purpose + +Creates all kinds of filters tags patterns depending of the monitor type and directly usable in a monitors set : + +* A filter tags pattern for service check +* A filter tags pattern for query alert + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|:----:|:-----:|:-----:| +| environment | Architecture Environment | string | - | yes | +| filter_tags_custom | Tags used for custom filtering when filter_tags_use_defaults is false | string | `*` | no | +| filter_tags_use_defaults | Use default filter tags convention | string | `true` | no | +| resource | The dedicated tag for the resource | string | - | yes | + +## Outputs + +| Name | Description | +|------|-------------| +| query_alert | The full filtering pattern including parentheses for service check monitor type | +| service_check | The full filtering pattern including braces for query alert monitor type | + +## Related documentation + +Datadog API type of monitor: [https://docs.datadoghq.com/api/?lang=python#create-a-monitor](https://docs.datadoghq.com/api/?lang=python#create-a-monitor) + diff --git a/common/filter-tags/inputs.tf b/common/filter-tags/inputs.tf new file mode 100644 index 0000000..5c4da92 --- /dev/null +++ b/common/filter-tags/inputs.tf @@ -0,0 +1,20 @@ +variable "environment" { + description = "Architecture Environment" + type = "string" +} + +variable "resource" { + description = "The dedicated tag for the resource" + type = "string" +} + +variable "filter_tags_use_defaults" { + description = "Use default filter tags convention" + default = "true" +} + +variable "filter_tags_custom" { + description = "Tags used for custom filtering when filter_tags_use_defaults is false" + default = "*" +} + diff --git a/common/filter-tags/locals.tf b/common/filter-tags/locals.tf new file mode 100644 index 0000000..2d3834f --- /dev/null +++ b/common/filter-tags/locals.tf @@ -0,0 +1,4 @@ +locals { + filters = "${var.filter_tags_use_defaults == "true" ? format("dd_monitoring:enabled,dd_%s:enabled,env:%s", var.resource, var.environment) : "${var.filter_tags_custom}"}" +} + diff --git a/common/filter-tags/output.tf b/common/filter-tags/output.tf new file mode 100644 index 0000000..e71c0b9 --- /dev/null +++ b/common/filter-tags/output.tf @@ -0,0 +1,10 @@ +output "query_alert" { + description = "The full filtering pattern including parentheses for service check monitor type" + value = "{${local.filters}}" +} + +output "service_check" { + description = "The full filtering pattern including braces for query alert monitor type" + value = "(\"${replace(local.filters, ",", "\",\"")}\")" +} +