From b1c9d22823fda36f7ba60fec7e5175aafd52a296 Mon Sep 17 00:00:00 2001 From: Waldemar Tomme Date: Mon, 21 Mar 2022 16:14:58 +0100 Subject: [PATCH] fix(textfile): corrected the textfile collector installation --- .../textfile_collectors/init.sls | 19 +++++++++---------- .../textfile_collectors/ipmitool/install.sls | 5 +++-- .../textfile_collectors/smartmon/install.sls | 5 +++-- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/prometheus/exporters/node_exporter/textfile_collectors/init.sls b/prometheus/exporters/node_exporter/textfile_collectors/init.sls index 4ea4f71..7978d42 100644 --- a/prometheus/exporters/node_exporter/textfile_collectors/init.sls +++ b/prometheus/exporters/node_exporter/textfile_collectors/init.sls @@ -5,14 +5,11 @@ {%- from tplroot ~ "/map.jinja" import prometheus as p with context %} {%- set sls_config_users = tplroot ~ '.config.users' %} -include: - - {{ sls_config_users }} - {%- set states = [] %} {%- set name = 'node_exporter' %} {%- if name in p.wanted.component and 'service' in p.pkg.component[name] %} - {%- if 'collector' in p.pkg.component[name]['service']['args'] %} + {%- if 'collector.textfile.directory' in p.pkg.component[name]['service']['args'] %} prometheus-exporters-{{ name }}-collector-textfile-dir: file.directory: - name: {{ p.pkg.component[name]['service']['args']['collector.textfile.directory'] }} @@ -32,7 +29,7 @@ prometheus-exporters-{{ name }}-collector-textfile-dir: {%- if v.get('remove', False) %} {%- set state = ".{}.clean".format(k) %} {%- else %} -{%- set state = ".{}".format(k) %} +{%- set state = ".{}.install".format(k) %} {%- endif %} {%- do states.append(state) %} {%- endif %} @@ -44,12 +41,14 @@ prometheus-exporters-{{ name }}-textfile-dependencies: - pkgs: {{ p.exporters[name]['textfile_collectors_dependencies'] }} - require_in: {%- for state in states %} - - sls: p.pkg.component[name]['config'][textfile_collectors{{ state }} + - sls: {{ tplroot }}.exporters.{{ name }}.textfile_collectors{{ state }} {%- endfor %} -include: -{%- for state in states %} - - {{ state }} -{% endfor %} {%- endif %} {%- endif %} + +include: + - {{ sls_config_users }} +{%- for state in states %} + - {{ state }} +{% endfor %} diff --git a/prometheus/exporters/node_exporter/textfile_collectors/ipmitool/install.sls b/prometheus/exporters/node_exporter/textfile_collectors/ipmitool/install.sls index d3f1ff4..61c85eb 100644 --- a/prometheus/exporters/node_exporter/textfile_collectors/ipmitool/install.sls +++ b/prometheus/exporters/node_exporter/textfile_collectors/ipmitool/install.sls @@ -6,7 +6,7 @@ {%- set name = 'node_exporter' %} {%- set config = p.exporters[name]['textfile_collectors']['ipmitool'] %} -{%- set dir = {{ p.pkg.component[name]['service']['args']['collector.textfile.directory'] }} +{%- set dir = p.pkg.component[name]['service']['args']['collector.textfile.directory'] %} {%- set script = p.dir.archive ~ '/textfile_collectors/ipmitool' %} {%- set cmd_prefix = 'awk -f ' if grains.os_family in ['FreeBSD'] else '' %} @@ -15,10 +15,11 @@ prometheus-exporters-install-{{ name }}-textfile_collectors-ipmitool: - name: {{ config.pkg }} file.managed: - name: {{ script }} - - source: salt://prometheus/exporters-install/{{ name }}/textfile_collectors/files/ipmitool + - source: salt://prometheus/exporters/{{ name }}/textfile_collectors/files/ipmitool {%- if grains.os != 'Windows' %} - mode: 755 {%- endif %} + - makedirs: True cron.present: - identifier: prometheus-exporters-{{ name }}-textfile_collectors-ipmitool-cronjob - name: cd {{ dir }} && LANG=C ipmitool sensor | {{ cmd_prefix }}{{ script }} > .ipmitool.prom$$; mv .ipmitool.prom$$ ipmitool.prom diff --git a/prometheus/exporters/node_exporter/textfile_collectors/smartmon/install.sls b/prometheus/exporters/node_exporter/textfile_collectors/smartmon/install.sls index 51e1474..0ba1b30 100644 --- a/prometheus/exporters/node_exporter/textfile_collectors/smartmon/install.sls +++ b/prometheus/exporters/node_exporter/textfile_collectors/smartmon/install.sls @@ -2,11 +2,11 @@ # vim: ft=sls {%- set tplroot = tpldir.split('/')[0] %} -{%- from tplroot ~ "/map.jinja" import prometheus with context %} +{%- from tplroot ~ "/map.jinja" import prometheus as p with context %} {%- set name = 'node_exporter' %} {%- set config = p.exporters[name]['textfile_collectors']['smartmon'] %} -{%- set dir = {{ p.pkg.component[name]['service']['args']['collector.textfile.directory'] }} +{%- set dir = p.pkg.component[name]['service']['args']['collector.textfile.directory'] %} {%- set script = p.dir.archive ~ '/textfile_collectors/smartmon.sh' %} prometheus-exporters-install-{{ name }}-textfile_collectors-smartmon: @@ -23,6 +23,7 @@ prometheus-exporters-install-{{ name }}-textfile_collectors-smartmon: {%- if grains.os != 'Windows' %} - mode: 755 {%- endif %} + - makedirs: True cron.present: - identifier: prometheus-exporters-{{ name }}-textfile_collectors-smartmon-cronjob - name: cd {{ dir }} && LANG=C {{ script }} > .smartmon.prom$$ && mv .smartmon.prom$$ smartmon.prom