diff --git a/prometheus/config/args/clean.sls b/prometheus/config/args/clean.sls index 25e35a8..1b3ed5e 100644 --- a/prometheus/config/args/clean.sls +++ b/prometheus/config/args/clean.sls @@ -46,9 +46,17 @@ prometheus-config-args-{{ name }}-all: {%- elif grains.os_family != 'FreeBSD' %} + {%- set args_file = prometheus.pkg.get(name, {}).get('args_file', False) %} + {%- if not args_file %} + {%- set args_file = prometheus.dir.args | path_join(name) %} + {%- if not grains.os_family in ['Debian'] %} + {%- set args_file = "{}.sh".format(args_file) %} + {%- endif %} + {%- endif %} + prometheus-config-args-{{ name }}-file-absent: file.absent: - - name: {{ prometheus.dir.args }}/{{ name }}.sh + - name: {{ args_file }} - require: - service: prometheus-service-clean-{{ name }}-service-dead - require_in: diff --git a/prometheus/config/args/install.sls b/prometheus/config/args/install.sls index d354aff..06a8227 100644 --- a/prometheus/config/args/install.sls +++ b/prometheus/config/args/install.sls @@ -94,9 +94,17 @@ prometheus-config-args-{{ name }}-all: {%- elif grains.os_family != 'FreeBSD' %} + {%- set args_file = prometheus.pkg.get(name, {}).get('args_file', False) %} + {%- if not args_file %} + {%- set args_file = prometheus.dir.args | path_join(name) %} + {%- if not grains.os_family in ['Debian'] %} + {%- set args_file = "{}.sh".format(args_file) %} + {%- endif %} + {%- endif %} + prometheus-config-args-{{ name }}-file-managed: file.managed: - - name: {{ prometheus.dir.args }}/{{ name }}.sh + - name: {{ args_file }} - contents: | ARGS="{{ concat_args(args) }}" - watch_in: diff --git a/prometheus/osfamilymap.yaml b/prometheus/osfamilymap.yaml index f28397a..f65b6cf 100644 --- a/prometheus/osfamilymap.yaml +++ b/prometheus/osfamilymap.yaml @@ -10,7 +10,14 @@ # you will need to provide at least an empty dict in this file, e.g. # osfamilymap: {} --- -Debian: {} +Debian: + pkg: + node_exporter: + name: prometheus-node-exporter + args_file: /etc/default/prometheus-node-exporter + service: + node_exporter: + name: prometheus-node-exporter RedHat: pkg: diff --git a/prometheus/service/clean.sls b/prometheus/service/clean.sls index 6ac6364..a2e0900 100644 --- a/prometheus/service/clean.sls +++ b/prometheus/service/clean.sls @@ -8,12 +8,17 @@ {%- for name in prometheus.wanted %} {%- if name in prometheus.service %} + {%- set service_name = prometheus.service.get(name, {}).get('name', False) %} + {%- if not service_name %} + {%- set service_name = name %} + {%- endif %} + prometheus-service-clean-{{ name }}-service-dead: service.dead: - name: {{ name }} - enable: False {%- if grains.kernel|lower == 'linux' %} - - onlyif: systemctl list-unit-files | grep {{ name }} >/dev/null 2>&1 + - onlyif: systemctl list-units | grep {{ service_name }} >/dev/null 2>&1 {%- endif %} file.absent: - name: {{ prometheus.dir.service }}/{{ name }}.service diff --git a/prometheus/service/running.sls b/prometheus/service/running.sls index f174e37..4c4351b 100644 --- a/prometheus/service/running.sls +++ b/prometheus/service/running.sls @@ -23,20 +23,26 @@ prometheus-config-file-var-file-directory: {%- for name in prometheus.wanted %} {%- if name in prometheus.service %} + + {%- set service_name = prometheus.service.get(name, {}).get('name', False) %} + {%- if not service_name %} + {%- set service_name = name %} + {%- endif %} + {%- if grains.kernel|lower == 'linux' %} prometheus-service-running-{{ name }}-service-unmasked: service.unmasked: - - name: {{ name }} + - name: {{ service_name }} - require: - file: prometheus-config-file-var-file-directory - onlyif: - - systemctl list-unit-files | grep {{ name }} >/dev/null 2>&1 + - systemctl list-units | grep {{ service_name }} >/dev/null 2>&1 {%- endif %} prometheus-service-running-{{ name }}-service-running: service.running: - - name: {{ name }} + - name: {{ service_name }} - enable: True {%- if name in prometheus.config %} - watch: @@ -46,7 +52,7 @@ prometheus-service-running-{{ name }}-service-running: - file: prometheus-config-file-var-file-directory {%- if grains.kernel|lower == 'linux' %} - service: prometheus-service-running-{{ name }}-service-unmasked - - onlyif: systemctl list-unit-files | grep {{ name }} >/dev/null 2>&1 + - onlyif: systemctl list-units | grep {{ service_name }} >/dev/null 2>&1 {%- endif %} {%- endif %} diff --git a/test/integration/default/controls/environ_spec.rb b/test/integration/default/controls/environ_spec.rb index e5a99bd..41c4787 100644 --- a/test/integration/default/controls/environ_spec.rb +++ b/test/integration/default/controls/environ_spec.rb @@ -1,7 +1,14 @@ control 'prometheus configuration environment' do title 'should match desired lines' - describe file('/etc/default/prometheus.sh') do + args_file = case os[:family] + when 'debian' + '/etc/default/prometheus' + else + '/etc/default/prometheus.sh' + end + + describe file(args_file) do it { should be_file } it { should be_owned_by 'root' } it { should be_grouped_into 'root' }