diff --git a/prometheus/archive/clean.sls b/prometheus/archive/clean.sls index 49fb61d..71a0568 100644 --- a/prometheus/archive/clean.sls +++ b/prometheus/archive/clean.sls @@ -20,7 +20,7 @@ prometheus-archive-clean-{{ name }}: file.absent: - name: {{ p.pkg.component[name]['path'] }} - {%- if p.linux.altpriority|int <= 0 or grains.os_family|lower in ('macos', 'arch') %} + {%- if (grains.kernel|lower == 'linux' and p.linux.altpriority|int <= 0) or grains.os_family|lower in ('macos', 'arch') %} {%- if 'commands' in p.pkg.component[name] and p.pkg.component[name]['commands'] is iterable %} {%- for cmd in p.pkg.component[name]['commands'] %} diff --git a/prometheus/archive/install.sls b/prometheus/archive/install.sls index abef357..76744cc 100644 --- a/prometheus/archive/install.sls +++ b/prometheus/archive/install.sls @@ -11,46 +11,55 @@ include: - {{ sls_config_users }} prometheus-archive-install-prerequisites: + {%- if grains.os != 'Windows' %} pkg.installed: - names: {{ p.pkg.deps|json }} + {%- endif %} file.directory: - name: {{ p.dir.var }} - - user: {{ p.identity.rootuser }} - - group: {{ p.identity.rootgroup }} - - mode: 755 - makedirs: True - require: - sls: {{ sls_config_users }} + {%- if grains.os != 'Windows' %} + - mode: 755 + - user: {{ p.identity.rootuser }} + - group: {{ p.identity.rootgroup }} + {%- endif %} {%- for name in p.wanted.component %} prometheus-archive-install-{{ name }}: file.directory: - name: {{ p.pkg.component[name]['path'] }} - - user: {{ p.identity.rootuser }} - - group: {{ p.identity.rootgroup }} - - mode: '0755' - makedirs: True - require: - file: prometheus-archive-install-prerequisites - require_in: - archive: prometheus-archive-install-{{ name }} + {%- if grains.os != 'Windows' %} + - user: {{ p.identity.rootuser }} + - group: {{ p.identity.rootgroup }} + - mode: '0755' - recurse: - user - group - mode + {%- endif %} archive.extracted: {{- format_kwargs(p.pkg.component[name]['archive']) }} - trim_output: true - enforce_toplevel: false - options: --strip-components=1 + - force: {{ p.force }} - retry: {{ p.retry_option|json }} - - user: {{ p.identity.rootuser }} - - group: {{ p.identity.rootgroup }} - require: - file: prometheus-archive-install-{{ name }} + {%- if grains.os != 'Windows' %} + - user: {{ p.identity.rootuser }} + - group: {{ p.identity.rootgroup }} + {%- endif %} - {%- if p.linux.altpriority|int <= 0 or grains.os_family|lower in ('macos', 'arch') %} + {%- if (grains.kernel|lower == 'linux' and p.linux.altpriority|int <= 0) or grains.os_family|lower in ('macos', 'arch') %} {%- if 'commands' in p.pkg.component[name] and p.pkg.component[name]['commands'] is iterable %} {%- for cmd in p.pkg.component[name]['commands'] %} @@ -73,15 +82,17 @@ prometheus-archive-install-{{ name }}-file-symlink-{{ cmd }}: prometheus-archive-install-{{ name }}-file-directory: file.directory: - - name: {{ p.dir.var }}/{{ name }} + - name: {{ p.dir.var }}{{ p.div }}{{ name }} + - makedirs: True + {%- if grains.os != 'Windows' %} - user: {{ name }} - group: {{ name }} - mode: '0755' - - makedirs: True - require: - user: prometheus-config-user-install-{{ name }}-user-present - group: prometheus-config-user-install-{{ name }}-user-present + {%- endif %} {%- if grains.kernel|lower == 'linux' %} prometheus-archive-install-{{ name }}-managed-service: @@ -118,6 +129,6 @@ prometheus-archive-install-{{ name }}-managed-service: - require: - archive: prometheus-archive-install-{{ name }} - {%- endif %} - {%- endif %} + {%- endif %}{# linux #} + {%- endif %}{# service #} {%- endfor %} diff --git a/prometheus/clientlibs/install.sls b/prometheus/clientlibs/install.sls index 42a04cf..4c8bf7d 100644 --- a/prometheus/clientlibs/install.sls +++ b/prometheus/clientlibs/install.sls @@ -30,6 +30,7 @@ prometheus-clientlibs-install-{{ name }}: {{- format_kwargs(p.pkg.clientlibs[name]['archive']) }} - trim_output: true - enforce_toplevel: false + - force: {{ p.force }} - options: --strip-components=1 - retry: {{ p.retry_option|json }} - user: {{ p.identity.rootuser }} diff --git a/prometheus/config/clean.sls b/prometheus/config/clean.sls index a908821..4208f0d 100644 --- a/prometheus/config/clean.sls +++ b/prometheus/config/clean.sls @@ -12,7 +12,7 @@ include: prometheus-config-clean-{{ name }}: - names: - - {{ p.dir.etc }}/{{ name }}.yml + - {{ p.dir.etc }}{{ d.div }}{{ name }}.yml - {{ p.pkg.component[name]['environ_file'] }} {%- if grains.os_family|lower in ('freebsd',) %} sysrc.absent: diff --git a/prometheus/config/environ.sls b/prometheus/config/environ.sls index 559a600..0aaf6ee 100644 --- a/prometheus/config/environ.sls +++ b/prometheus/config/environ.sls @@ -22,11 +22,13 @@ prometheus-config-install-{{ name }}-environ_file: lookup='prometheus-config-install-' ~ name ~ '-environ_file' ) }} + - makedirs: True + - template: jinja + {%- if grains.os != 'Windows' %} - mode: 640 - user: {{ p.identity.rootuser }} - group: {{ p.identity.rootgroup }} - - makedirs: True - - template: jinja + {%- endif %} - contents: | command_args="{{ concat_environ(environ) }}" - watch_in: diff --git a/prometheus/config/file.sls b/prometheus/config/file.sls index 115c52c..828e6d1 100644 --- a/prometheus/config/file.sls +++ b/prometheus/config/file.sls @@ -16,10 +16,12 @@ include: prometheus-config-file-etc-file-directory: file.directory: - name: {{ p.dir.etc }} + - makedirs: True + {%- if grains.os != 'Windows' %} + - mode: '0755' - user: {{ p.identity.rootuser }} - group: {{ p.identity.rootgroup }} - - mode: '0755' - - makedirs: True + {%- endif %} - require: - sls: {{ sls_archive_install if p.pkg.use_upstream_archive else sls_package_install }} @@ -28,16 +30,18 @@ prometheus-config-file-etc-file-directory: prometheus-config-file-{{ name }}-file-managed: file.managed: - - name: {{ p.dir.etc }}/{{ name }}.yml + - name: {{ p.dir.etc }}{{ p.div }}{{ name }}.yml - source: {{ files_switch(['config.yml.jinja'], lookup='prometheus-config-file-' ~ name ~ '-file-managed' ) }} + - makedirs: True + - template: jinja + {%- if grains.os != 'Windows' %} - mode: 644 - user: {{ name }} - group: {{ name }} - - makedirs: True - - template: jinja + {%- endif %} - context: config: {{ p.pkg.component[name]['config']|json }} - require: diff --git a/prometheus/config/users.sls b/prometheus/config/users.sls index fcd0d0d..ba0a48e 100644 --- a/prometheus/config/users.sls +++ b/prometheus/config/users.sls @@ -13,12 +13,14 @@ prometheus-config-user-install-{{ name }}-user-present: - user: prometheus-config-user-install-{{ name }}-user-present user.present: - name: {{ name }} - - shell: /bin/false - - createhome: false - groups: - {{ name }} - {%- if grains.os_family == 'MacOS' %} + {%- if grains.os != 'Windows' %} + - shell: /bin/false + {%- if grains.kernel|lower == 'linux' %} + - createhome: false + {%- elif grains.os_family == 'MacOS' %} - unless: /usr/bin/dscl . list /Users | grep {{ name }} >/dev/null 2>&1 + {%- endif %} {%- endif %} - {%- endfor %} diff --git a/prometheus/defaults.yaml b/prometheus/defaults.yaml index d5cf6f8..4ef0f9b 100644 --- a/prometheus/defaults.yaml +++ b/prometheus/defaults.yaml @@ -2,6 +2,9 @@ # vim: ft=yaml --- prometheus: + div: '/' + force: false + overwrite: true wanted: clientlibs: [] component: diff --git a/prometheus/exporters/node_exporter/textfile_collectors/init.sls b/prometheus/exporters/node_exporter/textfile_collectors/init.sls index 96b75fd..b77a76b 100644 --- a/prometheus/exporters/node_exporter/textfile_collectors/init.sls +++ b/prometheus/exporters/node_exporter/textfile_collectors/init.sls @@ -9,7 +9,6 @@ include: - {{ sls_config_users }} {%- set states = [] %} - {%- set name = 'node_exporter' %} {%- if name in p.wanted.component and 'service' in p.pkg.component[name] %} @@ -17,9 +16,11 @@ include: prometheus-exporters-{{ name }}-collector-textfile-dir: file.directory: - name: {{ p.pkg.component[name]['service']['args']['collector.textfile.directory'] }} + {%- if grains.os != 'Windows' %} - mode: 755 - user: {{ name }} - group: {{ name }} + {%- endif %} - makedirs: True - requre: - user: prometheus-config-user-install-{{ name }}-user-present diff --git a/prometheus/exporters/node_exporter/textfile_collectors/ipmitool/clean.sls b/prometheus/exporters/node_exporter/textfile_collectors/ipmitool/clean.sls index 2f1e9af..7d4f450 100644 --- a/prometheus/exporters/node_exporter/textfile_collectors/ipmitool/clean.sls +++ b/prometheus/exporters/node_exporter/textfile_collectors/ipmitool/clean.sls @@ -10,7 +10,7 @@ prometheus-exporters-clean-{{ name }}-textfile_collectors-ipmitool: - name: {{ p.exporters[name]['textfile_collectors']['ipmitool']['pkg'] }} file.absent: - names: - - {{ p.dir.archive ~ '/textfile_collectors/ipmitool' }} - - {{ p.pkg.component[name]['service']['args']['collector.textfile.directory'] }}/ipmitool.prom + - {{ p.dir.archive ~ p.div ~ 'textfile_collectors' ~ p.div ~ 'ipmitool' }} + - {{ p.pkg.component[name]['service']['args']['collector.textfile.directory'] }}{{ p.div }}ipmitool.prom cron.absent: - identifier: prometheus-exporters-{{ name }}-textfile_collectors-ipmitool-cronjob diff --git a/prometheus/exporters/node_exporter/textfile_collectors/ipmitool/init.sls b/prometheus/exporters/node_exporter/textfile_collectors/ipmitool/init.sls index 6a9d234..d3e5518 100644 --- a/prometheus/exporters/node_exporter/textfile_collectors/ipmitool/init.sls +++ b/prometheus/exporters/node_exporter/textfile_collectors/ipmitool/init.sls @@ -1,26 +1,5 @@ # -*- coding: utf-8 -*- # vim: ft=sls -{%- set tplroot = tpldir.split('/')[0] %} -{%- from tplroot ~ "/map.jinja" import prometheus as p with context %} - -{%- set name = 'node_exporter' %} -{%- set config = p.exporters[name]['textfile_collectors']['ipmitool'] %} -{%- 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 '' %} - -prometheus-exporters-install-{{ name }}-textfile_collectors-ipmitool: - pkg.installed: - - name: {{ config.pkg }} - file.managed: - - name: {{ script }} - - source: salt://prometheus/exporters-install/{{ name }}/textfile_collectors/files/ipmitool - - mode: 755 - 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 - - minute: "{{ config.get('minute', '*') }}" - - comment: Prometheus' {{ name }}'s ipmitool textfile collector - - require: - - file: prometheus-exporters-install-{{ name }}-textfile_collectors-ipmitool +include: + - .install diff --git a/prometheus/exporters/node_exporter/textfile_collectors/ipmitool/install.sls b/prometheus/exporters/node_exporter/textfile_collectors/ipmitool/install.sls new file mode 100644 index 0000000..d3f1ff4 --- /dev/null +++ b/prometheus/exporters/node_exporter/textfile_collectors/ipmitool/install.sls @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import prometheus as p with context %} + +{%- set name = 'node_exporter' %} +{%- set config = p.exporters[name]['textfile_collectors']['ipmitool'] %} +{%- 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 '' %} + +prometheus-exporters-install-{{ name }}-textfile_collectors-ipmitool: + pkg.installed: + - name: {{ config.pkg }} + file.managed: + - name: {{ script }} + - source: salt://prometheus/exporters-install/{{ name }}/textfile_collectors/files/ipmitool + {%- if grains.os != 'Windows' %} + - mode: 755 + {%- endif %} + 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 + - minute: "{{ config.get('minute', '*') }}" + - comment: Prometheus' {{ name }}'s ipmitool textfile collector + - require: + - file: prometheus-exporters-install-{{ name }}-textfile_collectors-ipmitool diff --git a/prometheus/exporters/node_exporter/textfile_collectors/smartmon/clean.sls b/prometheus/exporters/node_exporter/textfile_collectors/smartmon/clean.sls index 1b02374..687defb 100644 --- a/prometheus/exporters/node_exporter/textfile_collectors/smartmon/clean.sls +++ b/prometheus/exporters/node_exporter/textfile_collectors/smartmon/clean.sls @@ -10,7 +10,7 @@ prometheus-exporters-clean-{{ name }}-textfile_collectors-smartmon: - name: {{ p.exporters[name]['textfile_collectors']['smartmon']['pkg'] }} file.absent: - names: - - {{ p.dir.archive ~ '/textfile_collectors/smartmon.sh' }} - - {{ p.pkg.component[name]['service']['args']['collector.textfile.directory'] }}/smartmon.prom + - {{ p.dir.archive ~ p.div ~ 'textfile_collectors' ~ p.div ~ 'smartmon.sh' }} + - {{ p.pkg.component[name]['service']['args']['collector.textfile.directory'] }}{{ p.div }}smartmon.prom cron.absent: - identifier: prometheus-exporters-{{ name }}-textfile_collectors-smartmon-cronjob diff --git a/prometheus/exporters/node_exporter/textfile_collectors/smartmon/init.sls b/prometheus/exporters/node_exporter/textfile_collectors/smartmon/init.sls index 7f967b0..d3e5518 100644 --- a/prometheus/exporters/node_exporter/textfile_collectors/smartmon/init.sls +++ b/prometheus/exporters/node_exporter/textfile_collectors/smartmon/init.sls @@ -1,30 +1,5 @@ # -*- coding: utf-8 -*- # vim: ft=sls -{%- set tplroot = tpldir.split('/')[0] %} -{%- from tplroot ~ "/map.jinja" import prometheus 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 script = p.dir.archive ~ '/textfile_collectors/smartmon.sh' %} - -prometheus-exporters-install-{{ name }}-textfile_collectors-smartmon: - pkg.installed: - - names: - - {{ config.pkg }} - - {{ config.bash_pkg }} - file.managed: - - name: {{ script }} - - source: salt://prometheus/exporters/{{ name }}/textfile_collectors/files/smartmon.sh.jinja - - template: jinja - - context: - smartctl: {{ config.smartctl }} - - mode: 755 - cron.present: - - identifier: prometheus-exporters-{{ name }}-textfile_collectors-smartmon-cronjob - - name: cd {{ dir }} && LANG=C {{ script }} > .smartmon.prom$$ && mv .smartmon.prom$$ smartmon.prom - - minute: "{{ config.get('minute', '*') }}" - - comment: Prometheus' {{ name }}'s smartmon textfile collector - - require: - - file: prometheus-exporters-install-{{ name }}-textfile_collectors-smartmon +include: + - .install diff --git a/prometheus/exporters/node_exporter/textfile_collectors/smartmon/install.sls b/prometheus/exporters/node_exporter/textfile_collectors/smartmon/install.sls new file mode 100644 index 0000000..51e1474 --- /dev/null +++ b/prometheus/exporters/node_exporter/textfile_collectors/smartmon/install.sls @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import prometheus 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 script = p.dir.archive ~ '/textfile_collectors/smartmon.sh' %} + +prometheus-exporters-install-{{ name }}-textfile_collectors-smartmon: + pkg.installed: + - names: + - {{ config.pkg }} + - {{ config.bash_pkg }} + file.managed: + - name: {{ script }} + - source: salt://prometheus/exporters/{{ name }}/textfile_collectors/files/smartmon.sh.jinja + - template: jinja + - context: + smartctl: {{ config.smartctl }} + {%- if grains.os != 'Windows' %} + - mode: 755 + {%- endif %} + cron.present: + - identifier: prometheus-exporters-{{ name }}-textfile_collectors-smartmon-cronjob + - name: cd {{ dir }} && LANG=C {{ script }} > .smartmon.prom$$ && mv .smartmon.prom$$ smartmon.prom + - minute: "{{ config.get('minute', '*') }}" + - comment: Prometheus' {{ name }}'s smartmon textfile collector + - require: + - file: prometheus-exporters-install-{{ name }}-textfile_collectors-smartmon diff --git a/prometheus/osfamilymap.yaml b/prometheus/osfamilymap.yaml index 1389a38..75a77ec 100644 --- a/prometheus/osfamilymap.yaml +++ b/prometheus/osfamilymap.yaml @@ -301,9 +301,14 @@ OpenBSD: Solaris: {} Windows: + div: '\\' kernel: windows dir: - opt: C:\\Program Files + archive: C:\\prometheus + etc: C:\\prometheus\\etc + tmp: C:\\temp\\prometheus-salt-tmp + var: C:\\prometheus\var + pkg: component: prometheus: @@ -338,6 +343,7 @@ Windows: source_hash: 9362b7482e74792f111c4bb1a372b18a88f6354c78f24713bacfbcb050883556 MacOS: + div: '/' dir: default: /etc/defaults identity: diff --git a/prometheus/package/repo/clean.sls b/prometheus/package/repo/clean.sls index 26cb144..58b636d 100644 --- a/prometheus/package/repo/clean.sls +++ b/prometheus/package/repo/clean.sls @@ -1,8 +1,9 @@ # -*- coding: utf-8 -*- # vim: ft=sls -{%- set tplroot = tpldir.split('/')[0] %} -{%- from tplroot ~ "/map.jinja" import prometheus as p with context %} +{%- if grains.os_family|lower == 'redhat' %} + {%- set tplroot = tpldir.split('/')[0] %} + {%- from tplroot ~ "/map.jinja" import prometheus as p with context %} {%- if p.pkg.use_upstream_repo and 'repo' in p.pkg and p.pkg.repo %} @@ -11,3 +12,4 @@ prometheus-package-repo-clean-pkgrepo-managed: - name: {{ p.pkg['repo']['name'] }} {%- endif %} +{%- endif %} diff --git a/prometheus/package/repo/install.sls b/prometheus/package/repo/install.sls index 73ed856..02b1e83 100644 --- a/prometheus/package/repo/install.sls +++ b/prometheus/package/repo/install.sls @@ -2,12 +2,11 @@ # vim: ft=sls {%- if grains.os_family == 'RedHat' %} + {%- set tplroot = tpldir.split('/')[0] %} + {%- from tplroot ~ "/map.jinja" import prometheus as p with context %} - {%- set tplroot = tpldir.split('/')[0] %} - {%- from tplroot ~ "/map.jinja" import prometheus as p with context %} - - {%- if p.pkg.use_upstream_repo and 'repo' in p.pkg and p.pkg.repo %} - {%- from tplroot ~ "/files/macros.jinja" import format_kwargs with context %} + {%- if p.pkg.use_upstream_repo and 'repo' in p.pkg and p.pkg.repo %} + {%- from tplroot ~ "/files/macros.jinja" import format_kwargs with context %} prometheus-package-repo-install-pkgrepo-managed: pkgrepo.managed: @@ -18,8 +17,8 @@ prometheus-package-repo-install-pkgrepo-managed: - pattern: ' gpgkey2=' - repl: '\n ' - ignore_if_missing: True - {%- endif %} + {%- endif %} {%- else %} prometheus-package-repo-install-pkgrepo-managed: diff --git a/prometheus/service/clean.sls b/prometheus/service/clean.sls index d11a5c9..63dd048 100644 --- a/prometheus/service/clean.sls +++ b/prometheus/service/clean.sls @@ -16,7 +16,7 @@ prometheus-service-clean-{{ name }}: - onlyif: systemctl list-units | grep {{ service_name }} >/dev/null 2>&1 {%- endif %} file.absent: - - name: {{ p.dir.service }}/{{ name }}.service + - name: {{ p.dir.service }}{{ p.div }}{{ name }}.service - require: - service: prometheus-service-clean-{{ name }} cmd.run: diff --git a/prometheus/service/running.sls b/prometheus/service/running.sls index 15dc882..65f73bc 100644 --- a/prometheus/service/running.sls +++ b/prometheus/service/running.sls @@ -14,39 +14,40 @@ include: {%- if 'service' in p.pkg.component[name] and p.pkg.component[name]['service'] %} {%- set service_name = p.pkg.component[name]['service'].get('name', name) %} + {%- if grains.kernel|lower == 'linux' %} prometheus-service-running-{{ name }}-unmasked: service.unmasked: - name: {{ service_name }} - - onlyif: - - {{ grains.kernel|lower == 'linux' }} - - systemctl list-unit-files | grep {{ service_name }} >/dev/null 2>&1 + - onlyif: systemctl list-unit-files | grep {{ service_name }} >/dev/null 2>&1 - require_in: - service: prometheus-service-running-{{ name }} - require: - sls: {{ sls_config_file }} - file: prometheus-config-file-etc-file-directory + {%- endif %} prometheus-service-running-{{ name }}: - {%- if p.wanted.firewall and grains.kernel|lower == 'linux' %} + {%- if grains.kernel|lower == 'linux' and p.wanted.firewall %} pkg.installed: - name: firewalld - reload_modules: true {%- endif %} service.running: - - onlyif: systemctl list-unit-files | grep {{ service_name }} >/dev/null 2>&1 + - names: + - {{ service_name }} - enable: True - require: - sls: {{ sls_config_file }} - - names: - - {{ service_name }} - {%- if p.wanted.firewall and grains.kernel|lower == 'linux' %} + {%- if grains.kernel|lower == 'linux' %} + - onlyif: systemctl list-unit-files | grep {{ service_name }} >/dev/null 2>&1 + {%- if p.wanted.firewall %} - firewalld firewalld.present: - name: public - ports: {{ p.pkg.component[name]['firewall']['ports']|json }} - require: - service: prometheus-service-running-{{ name }} + {%- endif %} {%- endif %} - {%- endif %} {%- endfor %}