From 793568095e9c072aacea2a40e1e793f832344ef0 Mon Sep 17 00:00:00 2001 From: Matthew Baggett Date: Tue, 9 Jul 2024 11:58:20 +0200 Subject: [PATCH] Telegrammy bits - Requires a patch to vigil itself. --- .gitignore | 1 + modules/vigil/configuration.tf | 29 ++++++++++++++++------------- modules/vigil/inputs.tf | 16 ++++++++++++++-- modules/vigil/vigil.toml.tpl | 8 ++++---- vigil.tf | 18 ++++++++++++++++-- 5 files changed, 51 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 3f374e1..a196130 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /terraform.tfstate* /.terraform.tfstate* /.github/cache +/terraform.tfvars \ No newline at end of file diff --git a/modules/vigil/configuration.tf b/modules/vigil/configuration.tf index 92e915c..6c44497 100644 --- a/modules/vigil/configuration.tf +++ b/modules/vigil/configuration.tf @@ -7,19 +7,22 @@ locals { }) ] vigil_toml = templatefile("${path.module}/vigil.toml.tpl", { - manager_token = random_password.token["manager"].result - reporter_token = random_password.token["worker"].result - page_title = var.page_title - page_url = var.page_url - company_name = var.company_name - icon_color = var.icon_color - icon_url = var.icon_url - logo_color = var.logo_color - logo_url = var.logo_url - website_url = var.website_url - support_url = var.support_url - custom_html = var.custom_html - services = local.services_toml + manager_token = random_password.token["manager"].result + reporter_token = random_password.token["worker"].result + page_title = var.page_title + page_url = var.page_url + company_name = var.company_name + icon_color = var.icon_color + icon_url = var.icon_url + logo_color = var.logo_color + logo_url = var.logo_url + website_url = var.website_url + support_url = var.support_url + custom_html = var.custom_html + services = local.services_toml + startup_notification = var.notify_on_startup + telegram_bot_token = var.notify_telegram.token + telegram_chat_id = var.notify_telegram.channel }) vigil_toml_checksum = md5(local.vigil_toml) } diff --git a/modules/vigil/inputs.tf b/modules/vigil/inputs.tf index fe421f0..e5b68d7 100644 --- a/modules/vigil/inputs.tf +++ b/modules/vigil/inputs.tf @@ -16,7 +16,20 @@ variable "docker_networks" { description = "Docker networks to connect the vigil service to" default = null } - +variable "notify_on_startup" { + type = bool + description = "Whether to send a startup notifications" + default = false +} +variable "notify_telegram" { + type = object({ + token = string + channel = string + topic = optional(string, null) + }) + description = "Telegram configuration" + default = null +} variable "monitored_services" { type = map(list(object({ id = string @@ -26,7 +39,6 @@ variable "monitored_services" { http_status_healthy_below = optional(number, 400) http_status_healthy_above = optional(number, 200) }))) - } variable "page_title" { type = string diff --git a/modules/vigil/vigil.toml.tpl b/modules/vigil/vigil.toml.tpl index 38a2f9a..57a5bdc 100644 --- a/modules/vigil/vigil.toml.tpl +++ b/modules/vigil/vigil.toml.tpl @@ -54,14 +54,14 @@ queue_nack_dead_above = 5000 queue_loaded_retry_delay = 500 [notify] -startup_notification = false +startup_notification = ${startup_notification} reminder_interval = 600 reminder_backoff_function = "linear" reminder_backoff_limit = 3 -#[notify.telegram] -#bot_token = "xxxxxxxxxx:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -#chat_id = "xxxxxxxxx" +[notify.telegram] +bot_token = "${telegram_bot_token}" +chat_id = "${telegram_chat_id}" [probe] diff --git a/vigil.tf b/vigil.tf index c4208cd..a4b5960 100644 --- a/vigil.tf +++ b/vigil.tf @@ -9,7 +9,15 @@ module "vigil_nginx_config" { allow_non_ssl = true allow_ssl = false } - +variable "telegram_token" { + type = string +} +variable "telegram_channel" { + type = string +} +variable "telegram_topic" { + type = string +} module "vigil" { source = "./modules/vigil" monitored_services = { @@ -53,7 +61,7 @@ module "vigil" { id = "backup" label = "Backup Server" endpoints = [ - "icmp://backup.ti", + #"icmp://backup.ti", # ??? Doesn't work? "tcp://backup.ti:22", "http://backup.ti", ] @@ -205,4 +213,10 @@ module "vigil" { docker_networks = [ docker_network.loadbalancer ] + notify_on_startup = true + notify_telegram = { + token = var.telegram_token + channel = var.telegram_channel + topic = var.telegram_topic + } } \ No newline at end of file