From f978a9a700887abeb7d29f63614436eb699c64ab Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Sat, 4 Mar 2023 19:34:48 +0900 Subject: [PATCH] Delete `promtail` dependency. --- cookbooks/promtail/attributes.rb | 14 - cookbooks/promtail/default.rb | 6 - .../promtail/files/etc/logrotate.d/promtail | 13 - .../files/etc/rsyslog.d/30-promtail.conf | 7 - .../lib/systemd/system/promtail-base.service | 12 - cookbooks/promtail/install.rb | 55 --- cookbooks/promtail/setup.rb | 53 --- .../promtail/templates/etc/promtail/base.yaml | 390 ------------------ roles/base.rb | 1 - 9 files changed, 551 deletions(-) delete mode 100644 cookbooks/promtail/attributes.rb delete mode 100644 cookbooks/promtail/default.rb delete mode 100644 cookbooks/promtail/files/etc/logrotate.d/promtail delete mode 100644 cookbooks/promtail/files/etc/rsyslog.d/30-promtail.conf delete mode 100644 cookbooks/promtail/files/lib/systemd/system/promtail-base.service delete mode 100644 cookbooks/promtail/install.rb delete mode 100644 cookbooks/promtail/setup.rb delete mode 100644 cookbooks/promtail/templates/etc/promtail/base.yaml diff --git a/cookbooks/promtail/attributes.rb b/cookbooks/promtail/attributes.rb deleted file mode 100644 index 71adf26..0000000 --- a/cookbooks/promtail/attributes.rb +++ /dev/null @@ -1,14 +0,0 @@ -# ------------------------------------------- -# Specifying the default settings: -# ------------------------------------------- -node.reverse_merge!({ - 'promtail' => { - 'url' => 'https://github.com/grafana/loki/releases/download/', - 'bin' => 'promtail-linux-amd64.zip', - 'storage' => '/opt/promtail/bin/', - 'location' => '/usr/local/bin/', - 'data' => '/var/opt/promtail/', - 'lokiendpoint' => 'loki.service.consul:3100' - }, -}) - diff --git a/cookbooks/promtail/default.rb b/cookbooks/promtail/default.rb deleted file mode 100644 index 340c25a..0000000 --- a/cookbooks/promtail/default.rb +++ /dev/null @@ -1,6 +0,0 @@ -# Loading the attributes: -include_recipe './attributes.rb' - -include_recipe './install.rb' - -include_recipe './setup.rb' diff --git a/cookbooks/promtail/files/etc/logrotate.d/promtail b/cookbooks/promtail/files/etc/logrotate.d/promtail deleted file mode 100644 index 4ed9451..0000000 --- a/cookbooks/promtail/files/etc/logrotate.d/promtail +++ /dev/null @@ -1,13 +0,0 @@ -/var/log/promtail.log -{ - rotate 4 - weekly - missingok - notifempty - compress - delaycompress - sharedscripts - postrotate - /usr/lib/rsyslog/rsyslog-rotate - endscript -} diff --git a/cookbooks/promtail/files/etc/rsyslog.d/30-promtail.conf b/cookbooks/promtail/files/etc/rsyslog.d/30-promtail.conf deleted file mode 100644 index 9f6d43f..0000000 --- a/cookbooks/promtail/files/etc/rsyslog.d/30-promtail.conf +++ /dev/null @@ -1,7 +0,0 @@ -# Log kernel generated promtail log messages to file -:syslogtag,contains,"promtail" /var/log/promtail.log - -# Uncomment the following to stop logging anything that matches the last rule. -# Doing this will stop logging kernel generated UFW log messages to the file -# normally containing kern.* messages (eg, /var/log/kern.log) -& stop diff --git a/cookbooks/promtail/files/lib/systemd/system/promtail-base.service b/cookbooks/promtail/files/lib/systemd/system/promtail-base.service deleted file mode 100644 index 1766380..0000000 --- a/cookbooks/promtail/files/lib/systemd/system/promtail-base.service +++ /dev/null @@ -1,12 +0,0 @@ -[Unit] -Description=Grafana Promtail -Documentation=https://github.com/grafana/loki -After=network-online.target - -[Service] -User=root -Restart=always -ExecStart=/usr/local/bin/promtail --config.file=/etc/promtail/base.yaml - -[Install] -WantedBy=multi-user.target diff --git a/cookbooks/promtail/install.rb b/cookbooks/promtail/install.rb deleted file mode 100644 index 8b60269..0000000 --- a/cookbooks/promtail/install.rb +++ /dev/null @@ -1,55 +0,0 @@ -promtail_url = '' -promtail_bin = '' - -tag = '' -vtag = '' - -# Calculate the Download URL: -begin - require 'net/http' - - uri = URI.parse('https://github.com/grafana/loki/releases/latest') - - Timeout.timeout(3) do - response = Net::HTTP.get_response(uri) - - vtag = $1 if response['location'] =~ %r{tag\/(v\d+\.\d+\.\d+)} - tag = vtag.sub(/^v/, '') - - promtail_url = "#{node['promtail']['url']}/#{vtag}/#{node['promtail']['bin']}" - end -rescue - # Abort the chef client process: - raise 'Cannot connect to http://github.com.' -end - -# バージョン確認して、アップデート必要かどうか確認 -result = run_command("promtail --version 2>&1 | grep #{tag}", error: false) -if result.exit_status != 0 - # Download: - TMP = "/tmp/#{node['promtail']['bin']}" - - execute "wget #{promtail_url} -O #{TMP}" - - # Install: - directory node['promtail']['storage'] do - owner 'root' - group 'root' - mode '755' - end - - execute "unzip #{TMP} -d #{node['promtail']['storage']}" - execute "mv #{node['promtail']['storage']}promtail-linux-amd64 #{node['promtail']['storage']}promtail" - - # Change Owner and Permissions: - file "#{node['promtail']['storage']}promtail" do - owner 'root' - group 'root' - mode '755' - end - - # Create Link - link "#{node['promtail']['location']}promtail" do - to "#{node['promtail']['storage']}promtail" - end -end diff --git a/cookbooks/promtail/setup.rb b/cookbooks/promtail/setup.rb deleted file mode 100644 index cdfee71..0000000 --- a/cookbooks/promtail/setup.rb +++ /dev/null @@ -1,53 +0,0 @@ -# Deploy the configuration file: -%w( /etc/promtail /var/opt/promtail ).each do |d| - directory d do - owner 'root' - group 'root' - mode '755' - end -end - -# Deploy /etc/hosts file: -HOSTNAME = run_command('uname -n').stdout.chomp - -template '/etc/promtail/base.yaml' do - owner 'root' - group 'root' - mode '644' - - variables(HOSTNAME: HOSTNAME, LOKIENDPOINT: node['promtail']['lokiendpoint']) - - notifies :restart, 'service[promtail-base]' -end - -# Deploy the `systemd` configuration: -remote_file '/lib/systemd/system/promtail-base.service' do - owner 'root' - group 'root' - mode '644' -end - -# Service setting: -service 'promtail-base' do - action [ :enable, :restart ] -end - -# Deploy the `systemd` configuration: -remote_file '/etc/rsyslog.d/30-promtail.conf' do - owner 'root' - group 'root' - mode '644' - - notifies :restart, 'service[rsyslog]' -end - -service 'rsyslog' do - action [ :nothing ] -end - -# Deploy the `logrotated` configuration: -remote_file '/etc/logrotate.d/promtail' do - owner 'root' - group 'root' - mode '644' -end diff --git a/cookbooks/promtail/templates/etc/promtail/base.yaml b/cookbooks/promtail/templates/etc/promtail/base.yaml deleted file mode 100644 index 8eb7cb8..0000000 --- a/cookbooks/promtail/templates/etc/promtail/base.yaml +++ /dev/null @@ -1,390 +0,0 @@ -server: - disable: true - -positions: - filename: /var/opt/promtail/promtail_base_position.yaml - -clients: - - url: http://<%= @LOKIENDPOINT %>/loki/api/v1/push - -scrape_configs: - - job_name: apt - static_configs: - - targets: - - localhost - labels: - job: apt - hostname: <%= @HOSTNAME %> - level: notice - __path__: /var/log/apt/history.log - - - job_name: sudo - static_configs: - - targets: - - localhost - labels: - job: sudo - hostname: <%= @HOSTNAME %> - __path__: /var/log/auth.log - - pipeline_stages: - - match: - selector: '{job="sudo"} |~ "(CRON|sshd|session|securetty|systemd-logind|/bin/sh)"' - action: drop - - - match: - selector: '{job="sudo"} !~ "/bin/sh"' - stages: - - regex: - expression: '^(?P\w+ +[0-9]+ [0-9]+:[0-9]+:[0-9]+) [^ ]+ sudo: +(?P[^ ]+) : TTY=(?P[^ ]+) ; PWD=(?P[^ ]+) ; USER=(?P[^ ]+) ; COMMAND=(?P.+)$' - - - timestamp: - source: timestamp - format: Jan 2 15:04:05 - location: Asia/Tokyo - - - template: - source: message - template: 'USER={{ .user }} PWD={{ .pwd }} CMD={{ .cmd }}' - - - template: - source: level - template: 'notice' - - - labels: - level: - - - output: - source: message - - - job_name: sshd - static_configs: - - targets: - - localhost - labels: - job: sshd - hostname: <%= @HOSTNAME %> - level: info - __path__: /var/log/auth.log - - pipeline_stages: - - match: - selector: '{job="sshd"} |~ "(CRON|sudo|session)"' - action: drop - - - match: - selector: '{job="sshd"}' - - stages: - - regex: - expression: '^(?P\w+ +[0-9]+ [0-9]+:[0-9]+:[0-9]+) [^:]+: (?P.+)$' - - - timestamp: - source: timestamp - format: Jan 2 15:04:05 - location: Asia/Tokyo - - - output: - source: message - - - job_name: supervisord - static_configs: - - targets: - - localhost - labels: - job: supervisord - hostname: <%= @HOSTNAME %> - level: notice - __path__: /var/log/supervisor/supervisord.log - - pipeline_stages: - - match: - selector: '{job="supervisord"}' - stages: - - regex: - expression: '^(?P[0-9]+\-[0-9]+\-[0-9]+ [0-9]+:[0-9]+:[0-9]+),[0-9]+ (?P[^ ]+) (?P.+)$' - - - timestamp: - source: timestamp - format: 2006-01-02 15:04:05 - location: Asia/Tokyo - - - template: - source: level - template: '{{ ToLower .level }}' - - - template: - source: level - template: '{{ regexReplaceAllLiteral "warn" .Value "warning" }}' - - - template: - source: level - template: '{{ regexReplaceAllLiteral "crit" .Value "critical" }}' - - - labels: - level: - - - output: - source: message - - - job_name: fail2ban - static_configs: - - targets: - - localhost - labels: - job: fail2ban - hostname: <%= @HOSTNAME %> - level: info - __path__: /var/log/fail2ban.log - - pipeline_stages: - - match: - selector: '{job="fail2ban"} !~ "already banned"' - stages: - - regex: - expression: '^(?P[0-9]+\-[0-9]+\-[0-9]+ [0-9]+:[0-9]+:[0-9]+),[0-9]+ [^:]+: (?P[^ ]+)[^\[]+(?P.+)$' - - - timestamp: - source: timestamp - format: 2006-01-02 15:04:05 - location: Asia/Tokyo - - - template: - source: level - template: '{{ ToLower .level }}' - - - labels: - level: - - - output: - source: message - - - match: - selector: '{job="fail2ban"} |~ "already banned"' - stages: - - regex: - expression: '^(?P[0-9]+\-[0-9]+\-[0-9]+ [0-9]+:[0-9]+:[0-9]+),[0-9]+ [^:]+: (?P[^ ]+)[^\[]+(?P.+)$' - - - timestamp: - source: timestamp - format: 2006-01-02 15:04:05 - location: Asia/Tokyo - - - output: - source: message - - - job_name: promtail - static_configs: - - targets: - - localhost - labels: - job: promtail - hostname: <%= @HOSTNAME %> - __path__: /var/log/promtail.log - - pipeline_stages: - - match: - selector: '{job="promtail"}' - stages: - - - drop: - expression: 'entry out of order' - - - regex: - expression: '^[^ ]+ +[0-9]+ [0-9]+:[0-9]+:[0-9]+ [^ ]+ promtail[^ ]+ .*ts=(?P[^ ]+) (?P.+)$' - - - timestamp: - source: timestamp - format: 2006-01-02T15:04:05.999999999Z - location: Etc/GMT - - - regex: - expression: '^[^ ]+ +[0-9]+ [0-9]+:[0-9]+:[0-9]+ [^ ]+ promtail[^ ]+ .*level=(?P[^\\" ]+).*$' - - - template: - source: level - template: '{{ regexReplaceAllLiteral "warn" .Value "warning" }}' - - - labels: - level: - - - output: - source: message - - - job_name: login - journal: - json: false - max_age: 12h - path: /var/log/journal - labels: - job: login - level: notice - hostname: <%= @HOSTNAME %> - - relabel_configs: - - action: keep - regex: 'systemd-logind.service' - source_labels: - - __journal__systemd_unit - - - job_name: init - journal: - json: false - max_age: 12h - path: /var/log/journal - labels: - job: init - hostname: <%= @HOSTNAME %> - - pipeline_stages: - - match: - selector: '{job="init"} |~ "(apt|Message of the Day|motd-news|Temporary Directories|man-db|fwupd|Firmware update daemon|systemd-tmpfiles-clean.service|Rotate log files|logrotate.service|[Pp]ackage[Kk]it|/run/dbus/system_bus_socket|[Ss]nap|lxd|Reloading|Mount unit|ext4 Metadata|e2scrub_all.service|docker|tmp-sanity|libcontainer container)"' - stages: - - template: - source: level - template: 'info' - - - labels: - level: - - - match: - selector: '{job="init"} !~ "(apt|Message of the Day|motd-news|Temporary Directories|man-db|fwupd|Firmware update daemon|systemd-tmpfiles-clean.service|Rotate log files|logrotate.service|[Pp]ackage[Kk]it|/run/dbus/system_bus_socket|[Ss]nap|lxd|Reloading|Mount unit|ext4 Metadata|e2scrub_all.service|docker|tmp-sanity|libcontainer container)"' - stages: - - template: - source: level - template: 'notice' - - - labels: - level: - - relabel_configs: - - action: keep - regex: 'init\.scope' - source_labels: - - __journal__systemd_unit - - - job_name: systemd - journal: - json: false - max_age: 12h - path: /var/log/journal - labels: - job: systemd - level: info - hostname: <%= @HOSTNAME %> - - pipeline_stages: - - match: - selector: '{job="systemd"} !~ "(temperature|nf_conntrack)"' - stages: - - drop: - expression: (CMD|UFW|session|TTY) - - - match: - selector: '{job="systemd"} |~ "nf_conntrack"' - stages: - - template: - source: level - template: 'error' - - - labels: - level: - - - match: - selector: '{job="systemd"} |~ "temperature"' - - stages: - - regex: - expression: '^(?P.+)$' - - - template: - source: level - template: '{{ .message }}' - - - template: - source: level - template: '{{ regexReplaceAllLiteral ".*normal.*" .Value "notice" }}' - - - template: - source: level - template: '{{ regexReplaceAllLiteral ".*temperature.*" .Value "error" }}' - - - labels: - level: - - - output: - source: message - - relabel_configs: - - source_labels: ['__journal__systemd_unit'] - target_label: 'unit' - - - action: drop - regex: '.*(cron|supervisor|ssh|promtail|local|grafana|motd|dnsmasq|snapd|logind|init|session|loki|monit|consul).*' - source_labels: - - __journal__systemd_unit - - - job_name: consul - static_configs: - - targets: - - localhost - labels: - job: consul - hostname: <%= @HOSTNAME %> - level: info - __path__: /var/log/consul/consul-*.log - - pipeline_stages: - - match: - selector: '{job="consul"}' - stages: - - regex: - expression: '^(?P\d+-\d+-[^T]+T\d+:\d+:\d+\.\d+\+\d+) \[(?P[^\]]+)\] *(?P.+)$' - - - timestamp: - source: timestamp - format: 2006-01-02T15:04:05.000-0700 - - - template: - source: level - template: '{{ ToLower .level }}' - - - template: - source: level - template: '{{ regexReplaceAllLiteral "warn" .Value "warning" }}' - - - template: - source: level - template: '{{ regexReplaceAllLiteral "crit" .Value "critical" }}' - - - labels: - level: - - - output: - source: message - - - job_name: unattended-upgrades - static_configs: - - targets: - - localhost - labels: - job: unattended-upgrades - hostname: <%= @HOSTNAME %> - level: notice - __path__: /var/log/unattended-upgrades/unattended-upgrades.log - - pipeline_stages: - - match: - selector: '{job="unattended-upgrades"}' - stages: - - regex: - expression: '^(?P\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}),\d{3} (?P[^ ]+) (?P.+)$' - - - timestamp: - source: timestamp - format: 2006-01-02 15:04:05 - location: Asia/Tokyo - - - output: - source: message - diff --git a/roles/base.rb b/roles/base.rb index 9391abf..8838d79 100644 --- a/roles/base.rb +++ b/roles/base.rb @@ -4,7 +4,6 @@ include_recipe '../cookbooks/vault/default.rb' include_recipe '../cookbooks/consul-template/default.rb' include_recipe '../cookbooks/consul/default.rb' include_recipe '../cookbooks/fzf/default.rb' -include_recipe '../cookbooks/promtail/default.rb' include_recipe '../cookbooks/vector/default.rb' include_recipe '../cookbooks/prometheus-exporters/default.rb' include_recipe '../cookbooks/nomad/default.rb'