16 Como crear el código Terraform de la Alerta Monitor exportada a JSON - xavisan/Datadog GitHub Wiki
El código en Terraform debería de realizarse mediante comparativa de valores, de la siguiente forma, Tendremos en cuenta los valores especificaros en el correspondiente código,tales como los marcados en amarillo :
{
"id": 115186,
`"name": "CPU Load Kubernetes Cluster",`
`"type": "query alert",`
`"query": "avg(last_5m):avg:kubernetes.cpu.load.10s.avg{*} > 90",`
`"message": "Monitor triggered. Notify: @[email protected]",`
`"tags": [`
`"cpumonitor:kubernetes"`
`],`
`"options": {`
`"notify_audit": false,`
`"locked": false,`
`"silenced": {},`
`"include_tags": true,`
`"thresholds": {`
`"warning": 70,`
`"ok": 0,`
`"critical": 90,`
`"warning_recovery": 65,`
`"critical_recovery": 60`
`},`
`"new_host_delay": 300,`
`"require_full_window": true,`
`"notify_no_data": false,`
`"renotify_interval": 60,`
`"escalation_message": "Exist any problem with the CPU load in the Kubernetes cluster, please review this problem"`
`}`
}
Todos estos valores serán sustituidos en el código Terraform correspondiente a Datadog para Monitor, el ID no será utilizado en la creación de la correspondiente Alarma, al tratarse de una de nueva y no de una existente.
#---------------------------------------------------------
# Monitor and Rules definition for this environment
#---------------------------------------------------------
# create monitor
#------------------------------------------------
resource "datadog_monitor" "cpumonitor" {
name = "CPU Load Kubernetes Cluster"
type = "query alert"
message = "Monitor triggered. Notify: @[email protected]"
escalation_message = "Exist any problem with the CPU load in the Kubernetes cluster, please review this problem"
query = "avg(last_5m):avg:kubernetes.cpu.load.10s.avg{*} > 90"
thresholds = {
`ok = 0`
`warning = 70`
`warning_recovery = 65`
`critical = 90`
`critical_recovery = 60`
}
notify_no_data = false
renotify_interval = 60
notify_audit = false
timeout_h = 0
include_tags = true
# ignore any changes in silenced value; using silenced is deprecated in favor of downtimes
# lifecycle {
# ignore_changes = [silenced]
# }
tags = ["cpumonitor:kubernetes"]
}
De esta forma tendríamos el correspondiente código para Monitoring. El tipo de alerta, queda especificado en el valor que se especifica en Type: en nuestro caso “query.alert”.