From d463a2691d6eb0b6aeea6dede9c9f7ab7365f470 Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Sat, 12 Sep 2020 15:04:44 +0900 Subject: [PATCH] Install `alertmanager-webhook-logger`. --- .../alertmanager_webhook_install.rb | 50 +++++++++++++++++++ cookbooks/prometheus/default.rb | 2 + 2 files changed, 52 insertions(+) create mode 100644 cookbooks/prometheus/alertmanager_webhook_install.rb diff --git a/cookbooks/prometheus/alertmanager_webhook_install.rb b/cookbooks/prometheus/alertmanager_webhook_install.rb new file mode 100644 index 0000000..23f48bc --- /dev/null +++ b/cookbooks/prometheus/alertmanager_webhook_install.rb @@ -0,0 +1,50 @@ +alertmanager_webhook_url = '' +alertmanager_webhook_bin = '' + +tag = '' + +# Calculate the Download URL: +begin + require 'net/http' + + uri = URI.parse('https://github.com/tomtom-international/alertmanager-webhook-logger/releases/latest') + + Timeout.timeout(3) do + response = Net::HTTP.get_response(uri) + + tag = $1 if response.body =~ %r{tag\/(\d+\.\d+)} + + alertmanager_webhook_bin = "#{node['alertmanager_webhook']['prefix']}#{tag}#{node['alertmanager_webhook']['postfix']}" + + alertmanager_webhook_url = "#{node['alertmanager_webhook']['url']}/#{tag}/#{alertmanager_webhook_bin}" + end +rescue + # Abort the chef client process: + raise 'Cannot connect to http://github.com.' +end + +# Download: +TMP = "/tmp/#{alertmanager_webhook_bin}" + +execute "wget #{alertmanager_webhook_url} -O #{TMP}" + +# Install: +directory node['alertmanager_webhook']['storage'] do + owner 'root' + group 'root' + mode '755' +end + +execute "tar zxf #{TMP} -C #{node['alertmanager_webhook']['storage']}" + +# Change Owner and Permissions: +file "#{node['alertmanager_webhook']['storage']}alertmanager-webhook-logger" do + owner 'root' + group 'root' + mode '755' +end + +# Create Link +link "#{node['alertmanager_webhook']['location']}alertmanager-webhook-logger" do + to "#{node['alertmanager_webhook']['storage']}alertmanager-webhook-logger" +end diff --git a/cookbooks/prometheus/default.rb b/cookbooks/prometheus/default.rb index 6cfdbbc..a2f0ee4 100644 --- a/cookbooks/prometheus/default.rb +++ b/cookbooks/prometheus/default.rb @@ -8,6 +8,8 @@ if node['prometheus']['manager'] include_recipe './alertmanager_install.rb' include_recipe './alertmanager_setup.rb' + + include_recipe './alertmanager_webhook_install.rb' end # Install the node_exporter here: