From 6ab5fb9c6d2e0d309835648e78333ed40d654885 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sun, 21 Nov 2021 09:57:23 +0000 Subject: [PATCH] Add karma frontend for alertmanager --- cookbooks/prometheus/recipes/server.rb | 42 +++++++++++++++++++ .../prometheus/templates/default/apache.erb | 7 ++++ .../templates/default/karma.yml.erb | 21 ++++++++++ 3 files changed, 70 insertions(+) create mode 100644 cookbooks/prometheus/templates/default/karma.yml.erb diff --git a/cookbooks/prometheus/recipes/server.rb b/cookbooks/prometheus/recipes/server.rb index 675a206ec..2e3ab53ad 100644 --- a/cookbooks/prometheus/recipes/server.rb +++ b/cookbooks/prometheus/recipes/server.rb @@ -37,6 +37,7 @@ cache_dir = Chef::Config[:file_cache_path] prometheus_version = "2.31.1" alertmanager_version = "0.23.0" +karma_version = "0.93" directory "/opt/prometheus-server" do owner "root" @@ -80,6 +81,23 @@ archive_file "#{cache_dir}/alertmanager.linux-amd64.tar.gz" do subscribes :extract, "remote_file[#{cache_dir}/alertmanager.linux-amd64.tar.gz]" end +remote_file "#{cache_dir}/karma-linux-amd64.tar.gz" do + source "https://github.com/prymitive/karma/releases/download/v#{karma_version}/karma-linux-amd64.tar.gz" + owner "root" + group "root" + mode "644" + backup false +end + +archive_file "#{cache_dir}/karma-linux-amd64.tar.gz" do + action :nothing + destination "/opt/prometheus-server/karma" + overwrite true + owner "root" + group "root" + subscribes :extract, "remote_file[#{cache_dir}/karma-linux-amd64.tar.gz]" +end + package %w[ prometheus prometheus-alertmanager @@ -311,6 +329,30 @@ template "/etc/prometheus/amtool.yml" do mode "644" end +template "/etc/prometheus/karma.yml" do + source "karma.yml.erb" + owner "root" + group "root" + mode "644" +end + +systemd_service "prometheus-karma" do + description "Alert dashboard for Prometheus Alertmanager" + user "prometheus" + exec_start "/opt/prometheus-server/karma/karma-linux-amd64 --config.file=/etc/prometheus/karma.yml" + private_tmp true + private_devices true + protect_system "full" + protect_home true + no_new_privileges true + restart "on-failure" +end + +service "prometheus-karma" do + action [:enable, :start] + subscribes :reload, "template[/etc/prometheus/karma.yml]" +end + package "grafana-enterprise" template "/etc/grafana/grafana.ini" do diff --git a/cookbooks/prometheus/templates/default/apache.erb b/cookbooks/prometheus/templates/default/apache.erb index edc1647af..629e409e2 100644 --- a/cookbooks/prometheus/templates/default/apache.erb +++ b/cookbooks/prometheus/templates/default/apache.erb @@ -26,12 +26,19 @@ ProxyPass /prometheus http://localhost:9090/prometheus Redirect 403 /alertmanager/api ProxyPass /alertmanager http://localhost:9093/alertmanager + ProxyPass /karma http://localhost:8081/karma ProxyPass / http://localhost:3000/ ProxyPreserveHost on <% @admin_hosts.each do |host| -%> Require ip <%= host %> +<% end -%> + + + +<% @admin_hosts.each do |host| -%> + Require ip <%= host %> <% end -%> diff --git a/cookbooks/prometheus/templates/default/karma.yml.erb b/cookbooks/prometheus/templates/default/karma.yml.erb new file mode 100644 index 000000000..cc61c6e2c --- /dev/null +++ b/cookbooks/prometheus/templates/default/karma.yml.erb @@ -0,0 +1,21 @@ +karma: + name: OpenStreetMap +alertmanager: + interval: 1m + servers: + - name: openstreetmap + uri: http://127.0.0.1:9093/alertmanager/ + external_uri: https://prometheus.openstreetmap.org/alertmanager/ + proxy: true +listen: + port: 8081 + prefix: /karma/ +filters: + default: + - "@state=active" +labels: + color: + static: + - instance + strip: + - "@cluster" -- 2.39.5