FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects
Commit bded7e4d authored by Robin Goodall's avatar Robin Goodall :speech_balloon:
Browse files

Merge branch 'basic-alerting' into 'master'

Basic alerting

See merge request !7
parents 70f97732 829e1286
No related branches found
No related tags found
1 merge request!7Basic alerting
Pipeline #37642 passed
......@@ -140,3 +140,13 @@ resource "google_cloud_run_domain_mapping" "webapp" {
route_name = google_cloud_run_service.webapp.name
}
}
module "uptime_monitoring" {
source = "./modules/monitoring"
project = var.project
email_address = var.alerting_email_address
monitored_domain = var.dns_name
uptime_timeout = var.alerting_uptime_timeout
uptime_period = var.alerting_uptime_period
enabled = var.alerting_enabled
}
# Basic email uptime alerting
This provides basic uptime alerting via email for failing http polling. See
[variables.tf](variables.tf) for how to configure this module.
Note that the project must be in a Stackdriver monitoring workspace and this
must be configured manually. At the time of writing there is no terraform
support for this. This module will error when applying if this is not so.
locals {
# this is a hack to allow disabling everying. In tf 0.13 (in beta at the
# time of writing) count can be applied to the module inclusion phase so this
# won't be needed.
count = var.email_address == "" ? 0 : 1
}
resource "google_monitoring_uptime_check_config" "https" {
count = local.count
display_name = "https-uptime-check"
timeout = var.uptime_timeout
period = var.uptime_period
project = var.project
http_check {
path = var.polling_path
port = "443"
use_ssl = true
validate_ssl = true
}
monitored_resource {
type = "uptime_url"
labels = {
project_id = var.project
host = var.monitored_domain
}
}
# workaround - see https://github.com/terraform-providers/terraform-provider-google/issues/3133
lifecycle {
create_before_destroy = true
}
}
resource "google_monitoring_notification_channel" "notification_email" {
count = local.count
project = var.project
display_name = "Notifications Email"
type = "email"
labels = {
email_address = var.email_address
}
}
resource "google_monitoring_alert_policy" "uptime_alert" {
enabled = var.enabled
count = local.count
project = var.project
display_name = "HTTP uptime alert"
notification_channels = [google_monitoring_notification_channel.notification_email[count.index].id]
combiner = "OR"
conditions {
display_name = "http check failing for ${var.monitored_domain}${var.polling_path}"
condition_threshold {
filter = <<-EOT
metric.type="monitoring.googleapis.com/uptime_check/check_passed" AND
metric.label.check_id="${google_monitoring_uptime_check_config.https[count.index].uptime_check_id}" AND
resource.type="uptime_url"
EOT
duration = "60s"
comparison = "COMPARISON_GT"
threshold_value = "1"
trigger { count = "1" }
}
}
}
variable "email_address" {
default = ""
type = string
description = "Email address for alerts"
}
variable "monitored_domain" {
type = string
description = "domain component of url to be monitored"
}
variable "polling_path" {
type = string
default = "/"
description = "path component of url to be monitored"
}
variable "project" {
type = string
description = "project for all resources"
}
variable "uptime_timeout" {
type = string
default = "30s"
description = "timeout for http polling"
}
variable "uptime_period" {
type = string
default = "300s"
description = "Frequency of uptime checks"
}
variable "enabled" {
type = bool
default = true
description = "Whether the alerting policy is enabled"
}
......@@ -90,3 +90,29 @@ variable "service_account_display_name" {
If non-empty, override the default display name of the webapp service account.
EOI
}
variable "alerting_email_address" {
default = ""
type = string
description = <<EOT
Email address for basic uptime alerts. If empty (the default) no alerting will be configured. Otherwise note that the project must be in a Stackdriver monitoring workspace and this must be configured manually (no terraform support).
EOT
}
variable "alerting_uptime_timeout" {
default = "30s"
type = string
description = "timeout for http polling"
}
variable "alerting_uptime_period" {
type = string
default = "300s"
description = "Frequency of uptime checks"
}
variable "alerting_enabled" {
type = bool
default = true
description = "Whether alerting policy is enabled"
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment