chore(windows): tentative windows support

This commit is contained in:
noelmcloughlin 2020-10-19 13:57:29 +01:00
parent d00473a70c
commit 9abc98274e
20 changed files with 146 additions and 100 deletions

View File

@ -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'] %}

View File

@ -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 %}

View File

@ -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 }}

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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 %}

View File

@ -2,6 +2,9 @@
# vim: ft=yaml
---
prometheus:
div: '/'
force: false
overwrite: true
wanted:
clientlibs: []
component:

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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 %}

View File

@ -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:

View File

@ -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:

View File

@ -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 %}