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

Commit

Permalink
Add existing alerts (#472)
Browse files Browse the repository at this point in the history
  • Loading branch information
icco authored Sep 3, 2020
1 parent c74bdbe commit a5e7401
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
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"
}
}
}

0 comments on commit a5e7401

Please sign in to comment.