From 75b9a740597ed6b19cd7a999d830c007ad02b6be Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Thu, 16 Feb 2023 21:45:10 +0900 Subject: [PATCH] Deploy `/etc/systemd/system/vector-alertmanager.service`. --- cookbooks/prometheus/alertmanager_setup.rb | 8 +++ .../files/etc/vector/alertmanager.toml | 60 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 cookbooks/prometheus/files/etc/vector/alertmanager.toml diff --git a/cookbooks/prometheus/alertmanager_setup.rb b/cookbooks/prometheus/alertmanager_setup.rb index 253f780..5715c68 100644 --- a/cookbooks/prometheus/alertmanager_setup.rb +++ b/cookbooks/prometheus/alertmanager_setup.rb @@ -70,6 +70,14 @@ remote_file '/etc/vector/alertmanager.toml' do notifies :restart, 'service[vector-alertmanager]' end +remote_file '/etc/systemd/system/vector-alertmanager.service' do + owner 'root' + group 'root' + mode '644' + + notifies :restart, 'service[vector-alertmanager]' +end + service 'vector-alertmanager' do action [:enable, :start] end diff --git a/cookbooks/prometheus/files/etc/vector/alertmanager.toml b/cookbooks/prometheus/files/etc/vector/alertmanager.toml new file mode 100644 index 0000000..f96570e --- /dev/null +++ b/cookbooks/prometheus/files/etc/vector/alertmanager.toml @@ -0,0 +1,60 @@ +data_dir = "/var/lib/vector/" + +[sources.alertmanager] + type = "file" + include = [ "/var/log/alertmanager.log" ] + ignore_older_secs = 600 + read_from = "beginning" + +[transforms.alertmanager_transform] + type = "remap" + inputs = ["alertmanager"] + source = ''' + . |= parse_syslog!(.message) + del(.host) + + errmsg = parse_regex(.message, r'err=(?P.+)$') ?? {} + . = merge(., errmsg) + .message = replace(.message, r'err=.+$', "") + + . |= parse_logfmt!(.message) + del(.message) + + .message = .msg + del(.msg) + + .timestamp = .ts + del(.ts) + ''' + +[sinks.alertmanager_output] +type = "file" +inputs = [ "alertmanager_transform" ] +compression = "none" +path = "/tmp/alertmanager-%Y-%m-%d.log" + + [sinks.alertmanager_output.encoding] + codec = "json" + + [sinks.alertmanager_output.buffer] + max_size = 268435488 + type = "disk" + +[sinks.alertmanager_loki] +type = "loki" +inputs = [ "alertmanager_transform" ] +endpoint = "http://loki.service.consul:3100" +compression = "snappy" + + [sinks.alertmanager_loki.labels] + level = "{{ level }}" + hostname = "{{ hostname }}" + job = "alertmanager" + filename = "/var/log/alertmanager.log" + + [sinks.alertmanager_loki.encoding] + codec = "json" + + [sinks.alertmanager_loki.buffer] + max_size = 268435488 + type = "disk"