Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Add existing alerts to terraform #472

Merged
merged 1 commit into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions terraform/alerting/notifications.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
resource "google_monitoring_notification_channel" "email" {
provider = google-beta
project = var.project
display_name = "Email Notification Channel"
type = "email"
labels = {
email_address = var.notification-email
}
}
66 changes: 66 additions & 0 deletions terraform/alerting/probers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
resource "google_monitoring_uptime_check_config" "https" {
for_each = toset([var.server-host, var.apiserver-host, var.adminapi-host])

display_name = each.key
timeout = "3s"
project = var.project
period = "60s"

http_check {
path = "/health"
port = "443"
use_ssl = true
validate_ssl = true
}

monitored_resource {
type = "uptime_url"
labels = {
project_id = var.project
host = each.key
}
}
}

resource "google_monitoring_alert_policy" "probers" {
project = var.project
display_name = "Host Down"
combiner = "OR"
conditions {
display_name = "Host is unreachable"
condition_threshold {
duration = "300s"
threshold_value = 0.2
comparison = "COMPARISON_LT"
filter = "metric.type=\"monitoring.googleapis.com/uptime_check/check_passed\" resource.type=\"uptime_url\""

aggregations {
alignment_period = "60s"
cross_series_reducer = "REDUCE_FRACTION_TRUE"
group_by_fields = [
"resource.label.host",
]
per_series_aligner = "ALIGN_NEXT_OLDER"
}

trigger {
count = 1
}
}
}

documentation {
content = <<-EOT
## $${policy.display_name}

[$${resource.label.host}](https://$${resource.label.host}/health) is being reported unreachable.

See [docs/hosts.md](https://github.com/sethvargo/exposure-notifications-server-infra/blob/main/docs/hosts.md) for information about hosts.
EOT
mime_type = "text/markdown"
}

notification_channels = [
google_monitoring_notification_channel.email.id
]
}
42 changes: 42 additions & 0 deletions terraform/alerting/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
variable "project" {
type = string
}

variable "notification-email" {
type = string
default = "nobody@example.com"
description = "Email address for alerts"
}

variable "server-host" {
type = string
default = ""
description = "Domain web ui is hosted on."
}

variable "apiserver-host" {
type = string
default = ""
description = "Domain apiserver is hosted on."
}

variable "adminapi-host" {
type = string
default = ""
description = "Domain adminapi is hosted on."
}

terraform {
required_version = ">= 0.13"

required_providers {
google = {
source = "hashicorp/google"
version = "~> 3.36"
}
google-beta = {
source = "hashicorp/google-beta"
version = "~> 3.36"
}
}
}