Merge branch 'MON-557-sqlserver-monitors' into 'master'

MON-557: SQL Server monitors

Closes MON-557

See merge request claranet/pt-monitoring/projects/datadog/terraform/monitors!162
This commit is contained in:
Quentin Manfroi 2020-01-23 16:11:18 +01:00
commit 76e87e76ff
6 changed files with 175 additions and 0 deletions

View File

@ -200,6 +200,7 @@ module "datadog-monitors-system-generic" {
- [mysql](https://github.com/claranet/terraform-datadog-monitors/tree/master/database/mysql/) - [mysql](https://github.com/claranet/terraform-datadog-monitors/tree/master/database/mysql/)
- [postgresql](https://github.com/claranet/terraform-datadog-monitors/tree/master/database/postgresql/) - [postgresql](https://github.com/claranet/terraform-datadog-monitors/tree/master/database/postgresql/)
- [redis](https://github.com/claranet/terraform-datadog-monitors/tree/master/database/redis/) - [redis](https://github.com/claranet/terraform-datadog-monitors/tree/master/database/redis/)
- [sqlserver](https://github.com/claranet/terraform-datadog-monitors/tree/master/database/sqlserver/)
- [middleware](https://github.com/claranet/terraform-datadog-monitors/tree/master/middleware/) - [middleware](https://github.com/claranet/terraform-datadog-monitors/tree/master/middleware/)
- [apache](https://github.com/claranet/terraform-datadog-monitors/tree/master/middleware/apache/) - [apache](https://github.com/claranet/terraform-datadog-monitors/tree/master/middleware/apache/)
- [kong](https://github.com/claranet/terraform-datadog-monitors/tree/master/middleware/kong/) - [kong](https://github.com/claranet/terraform-datadog-monitors/tree/master/middleware/kong/)

View File

@ -0,0 +1,49 @@
# DATABASE SQLSERVER DataDog monitors
## How to use this module
```hcl
module "datadog-monitors-database-sqlserver" {
source = "claranet/monitors/datadog//database/sqlserver"
version = "{revision}"
environment = var.environment
message = module.datadog-message-alerting.alerting-message
}
```
## Purpose
Creates DataDog monitors with the following checks:
- SQL Server server does not respond
## Inputs
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:-----:|
| environment | Environment | `string` | n/a | yes |
| evaluation\_delay | Delay in seconds for the metric evaluation | `number` | `15` | no |
| filter\_tags\_custom | Tags used for custom filtering when filter\_tags\_use\_defaults is false | `string` | `"*"` | no |
| filter\_tags\_custom\_excluded | Tags excluded for custom filtering when filter\_tags\_use\_defaults is false | `string` | `""` | no |
| filter\_tags\_use\_defaults | Use default filter tags convention | `string` | `"true"` | no |
| message | Message sent when an alert is triggered | `any` | n/a | yes |
| new\_host\_delay | Delay in seconds for the metric evaluation | `number` | `300` | no |
| notify\_no\_data | Will raise no data alert if set to true | `bool` | `true` | no |
| prefix\_slug | Prefix string to prepend between brackets on every monitors names | `string` | `""` | no |
| sqlserver\_availability\_enabled | Flag to enable SQL Server availability monitor | `string` | `"true"` | no |
| sqlserver\_availability\_extra\_tags | Extra tags for SQL Server availability monitor | `list(string)` | `[]` | no |
| sqlserver\_availability\_message | Custom message for SQL Server availability monitor | `string` | `""` | no |
| sqlserver\_availability\_no\_data\_timeframe | SQL Server availability monitor no data timeframe | `string` | `10` | no |
| sqlserver\_availability\_threshold\_warning | SQL Server availability monitor (warning threshold) | `string` | `3` | no |
## Outputs
| Name | Description |
|------|-------------|
| sqlserver\_availability\_id | id for monitor sqlserver\_availability |
## Related documentation
DataDog documentation: [https://docs.datadoghq.com/integrations/sqlserver/](https://docs.datadoghq.com/integrations/sqlserver/)

View File

@ -0,0 +1,79 @@
variable "environment" {
description = "Environment"
type = string
}
variable "evaluation_delay" {
description = "Delay in seconds for the metric evaluation"
default = 15
}
variable "new_host_delay" {
description = "Delay in seconds for the metric evaluation"
default = 300
}
variable "prefix_slug" {
description = "Prefix string to prepend between brackets on every monitors names"
default = ""
}
variable "notify_no_data" {
description = "Will raise no data alert if set to true"
default = true
}
variable "message" {
description = "Message sent when an alert is triggered"
}
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 = "*"
}
variable "filter_tags_custom_excluded" {
description = "Tags excluded for custom filtering when filter_tags_use_defaults is false"
default = ""
}
# SQL Server specific
#################################
### SQL Server availability ###
#################################
variable "sqlserver_availability_enabled" {
description = "Flag to enable SQL Server availability monitor"
type = string
default = "true"
}
variable "sqlserver_availability_extra_tags" {
description = "Extra tags for SQL Server availability monitor"
type = list(string)
default = []
}
variable "sqlserver_availability_message" {
description = "Custom message for SQL Server availability monitor"
type = string
default = ""
}
variable "sqlserver_availability_threshold_warning" {
description = "SQL Server availability monitor (warning threshold)"
type = string
default = 3
}
variable "sqlserver_availability_no_data_timeframe" {
description = "SQL Server availability monitor no data timeframe"
type = string
default = 10
}

View File

@ -0,0 +1,10 @@
module "filter-tags" {
source = "../../common/filter-tags"
environment = var.environment
resource = "sqlserver"
filter_tags_use_defaults = var.filter_tags_use_defaults
filter_tags_custom = var.filter_tags_custom
filter_tags_custom_excluded = var.filter_tags_custom_excluded
}

View File

@ -0,0 +1,31 @@
resource "datadog_monitor" "sqlserver_availability" {
count = var.sqlserver_availability_enabled == "true" ? 1 : 0
name = "${var.prefix_slug == "" ? "" : "[${var.prefix_slug}]"}[${var.environment}] SQL Server server does not respond"
message = coalesce(var.sqlserver_availability_message, var.message)
type = "service check"
query = <<EOQ
"sqlserver.can_connect"${module.filter-tags.service_check}.by("db","server").last(6).count_by_status()
EOQ
thresholds = {
warning = var.sqlserver_availability_threshold_warning
critical = 5
}
no_data_timeframe = var.sqlserver_availability_no_data_timeframe
new_host_delay = var.new_host_delay
notify_no_data = var.notify_no_data
renotify_interval = 0
notify_audit = false
timeout_h = 0
include_tags = true
locked = false
require_full_window = true
tags = concat(["env:${var.environment}", "type:database", "provider:sqlserver", "resource:sqlserver", "team:claranet", "created-by:terraform"], var.sqlserver_availability_extra_tags)
lifecycle {
ignore_changes = [silenced]
}
}

View File

@ -0,0 +1,5 @@
output "sqlserver_availability_id" {
description = "id for monitor sqlserver_availability"
value = datadog_monitor.sqlserver_availability.*.id
}