diff --git a/pillar.example b/pillar.example index 6c3a797..1135363 100644 --- a/pillar.example +++ b/pillar.example @@ -9,20 +9,21 @@ prometheus: # no memcached_exporter in upstream repo - only archive # memcached_exporter - use_upstream_repo: False use_upstream_archive: True + {%- if grains.os_family in ('CentOS',) %} + use_upstream_repo: False + {%- endif %} pkg: prometheus: - archive_version: 2.10.0 + archive_version: '2.10.0' archive_hash: f4233783826f18606b79e5cef0686e4a9c2030146a3c7ce134f0add09f5adcb7 - repo: {} alertmanager: archive_version: '0.17.0' archive_hash: ec171b13976baceace193461f8a1e61021ab9657df5ba45157cd0095aee7d569 service: - prometheus + prometheus: args: web.listen-address: 0.0.0.0:9090 pushgateway: @@ -122,33 +123,33 @@ prometheus: slack_api_url: "http://mysecret.example.com/" http_config: proxy_url: 'http://127.0.0.1:1025' - route: - group_by: ['alertname', 'cluster', 'service'] - group_wait: 30s - group_interval: 5m - repeat_interval: 3h - receiver: team-X-mails - routes: - - match_re: - service: ^(foo1|foo2|baz)$ - receiver: team-X-mails - routes: - - match: - severity: critical - receiver: team-X-mails - receivers: - - name: 'team-X-mails' - email_configs: - - to: 'team-X+alerts@example.org' + route: + group_by: ['alertname', 'cluster', 'service'] + group_wait: 30s + group_interval: 5m + repeat_interval: 3h + receiver: team-X-mails + routes: + - match_re: + service: ^(foo1|foo2|baz)$ + receiver: team-X-mails + routes: + - match: + severity: critical + receiver: team-X-mails + receivers: + - name: 'team-X-mails' + email_configs: + - to: 'team-X+alerts@example.org' - inhibit_rules: - - name: opsGenie-receiver - opsgenie_configs: - - api_key: mysecret - - name: slack-receiver - slack_configs: - - channel: '#my-channel' - image_url: 'http://some.img.com/img.png' + inhibit_rules: + - name: opsGenie-receiver + opsgenie_configs: + - api_key: mysecret + - name: slack-receiver + slack_configs: + - channel: '#my-channel' + image_url: 'http://some.img.com/img.png' linux: #'Alternatives system' priority: zero disables (default) diff --git a/prometheus/archive/clean.sls b/prometheus/archive/clean.sls index 43c70c6..c3cf5f1 100644 --- a/prometheus/archive/clean.sls +++ b/prometheus/archive/clean.sls @@ -17,8 +17,6 @@ prometheus-archive-clean-{{ name }}-file-absent: file.absent: - names: - {{ p.dir.basedir }}/{{ name + '-%s.%s-%s'|format(p.pkg[name]['archive_version'], p.kernel, p.arch) }} - - require: - - sls: {{ sls_alternatives_clean }} prometheus-archive-clean-{{ name }}-user-absent: user.absent: @@ -27,13 +25,10 @@ prometheus-archive-clean-{{ name }}-user-absent: - name: {{ name }} - require: - user: prometheus-archive-clean-{{ name }}-user-absent - - sls: {{ sls_alternatives_clean }} {%- endfor %} prometheus-archive-clean-basedir-file-directory: file.absent: - name: {{ p.dir.basedir }} - - require: - - sls: {{ sls_alternatives_clean }} diff --git a/prometheus/archive/install.sls b/prometheus/archive/install.sls index 507b0e7..6b7b1fe 100644 --- a/prometheus/archive/install.sls +++ b/prometheus/archive/install.sls @@ -18,11 +18,12 @@ prometheus-config-file-basedir-file-directory: - group: prometheus - mode: 755 - makedirs: True - # require: - # sls: {{ sls_users_install }} + - require: + - sls: '{{ sls_users_install }}.*' {%- for name in p.wanted %} - {%- set bundle = name + '-%s.%s-%s'|format(p.pkg[name]['archive_version'], p.kernel, p.arch) %} + {%- if name in p.pkg %} + {%- set bundle = name + '-%s.%s-%s'|format(p.pkg[name]['archive_version'], p.kernel, p.arch) %} prometheus-archive-install-{{ name }}-archive-extracted: archive.extracted: @@ -39,7 +40,7 @@ prometheus-archive-install-{{ name }}-archive-extracted: - require: - file: prometheus-config-file-basedir-file-directory - {%- if name in p.service %} + {%- if name in p.service %} prometheus-archive-install-{{ name }}-file-directory: file.directory: @@ -76,5 +77,6 @@ prometheus-archive-install-{{ name }}-managed-service: - file: prometheus-archive-install-{{ name }}-file-directory - file: prometheus-config-file-basedir-file-directory + {%- endif %} {%- endif %} {%- endfor %} diff --git a/prometheus/config/args/clean.sls b/prometheus/config/args/clean.sls index e9da0e3..25e35a8 100644 --- a/prometheus/config/args/clean.sls +++ b/prometheus/config/args/clean.sls @@ -21,7 +21,7 @@ prometheus-config-args-{{ name }}-data-dir: file.absent: - name: {{ args['storage.tsdb.path'] }} - require: - - sls: {{ sls_service_clean }} + - sls: '{{ sls_service_clean }}.*' {%- if grains.os_family == 'FreeBSD' %} @@ -51,6 +51,8 @@ prometheus-config-args-{{ name }}-file-absent: - name: {{ prometheus.dir.args }}/{{ name }}.sh - require: - service: prometheus-service-clean-{{ name }}-service-dead + - require_in: + - file: prometheus-config-file-args-file-absent {%- endif %} {%- endif %} diff --git a/prometheus/config/args/install.sls b/prometheus/config/args/install.sls index 0512dda..d354aff 100644 --- a/prometheus/config/args/install.sls +++ b/prometheus/config/args/install.sls @@ -5,12 +5,13 @@ {%- set tplroot = tpldir.split('/')[0] %} {%- from tplroot ~ "/map.jinja" import prometheus with context %} {%- from tplroot ~ "/map.jinja" import concat_args %} -{%- set sls_config_install = tplroot ~ '.config' %} -{%- set sls_service_install = tplroot ~ '.service' %} +{%- set sls_config_users = tplroot ~ '.config.users' %} +{%- set sls_archive_install = tplroot ~ '.archive' %} +{%- set sls_package_install = tplroot ~ '.package' %} include: - - {{ sls_service_install }} - - {{ sls_config_install }} + - {{ sls_archive_install if prometheus.use_upstream_archive else sls_package_install }} + - {{ sls_config_users }} prometheus-config-file-args-file-directory: file.directory: @@ -19,8 +20,8 @@ prometheus-config-file-args-file-directory: - group: prometheus - mode: 755 - makedirs: True - # require: - # sls: {{ sls_config_install }}.users + - require: + - sls: '{{ sls_archive_install if prometheus.use_upstream_archive else sls_package_install }}.*' {%- for name in prometheus.wanted %} {%- if name in prometheus.config or name in prometheus.service %} @@ -51,6 +52,8 @@ prometheus-config-args-args-web-listen-address: - value: {{ args.pop('web.listen-address') }} - watch_in: - service: prometheus-service-running-{{ name }}-service-running + - require: + - file: prometheus-config-file-args-file-directory {%- endif %} {%- if 'collector.textfile.directory' in args.keys() %} @@ -61,6 +64,8 @@ prometheus-config-args-{{ name }}-collector-textfile-directory: - value: {{ args.pop('collector.textfile.directory') }} - watch_in: - service: prometheus-service-running-{{ name }}-service-running + - require: + - file: prometheus-config-file-args-file-directory {%- endif %} {%- if 'storage.tsdb.path' in args.keys() %} @@ -71,6 +76,8 @@ prometheus-config-args-{{ name }}-{{ key }}: - value: {{ args.pop('storage.tsdb.path') }} - watch_in: - service: prometheus-service-running-{{ name }}-service-running + - require: + - file: prometheus-config-file-args-file-directory {%- endif %} @@ -82,6 +89,8 @@ prometheus-config-args-{{ name }}-all: - value: "{{ concat_args(args) }} >/dev/null 2>&1" - watch_in: - service: prometheus-service-running-{{ name }}-service-running + - require: + - file: prometheus-config-file-args-file-directory {%- elif grains.os_family != 'FreeBSD' %} @@ -92,6 +101,8 @@ prometheus-config-args-{{ name }}-file-managed: ARGS="{{ concat_args(args) }}" - watch_in: - service: prometheus-service-running-{{ name }}-service-running + - require: + - file: prometheus-config-file-args-file-directory {%- endif %} {%- endif %} diff --git a/prometheus/config/file/clean.sls b/prometheus/config/file/clean.sls index 10b6f95..254a0c3 100644 --- a/prometheus/config/file/clean.sls +++ b/prometheus/config/file/clean.sls @@ -15,11 +15,13 @@ include: prometheus-config-file-{{ name }}-file-absent: file.absent: - name: {{ prometheus.dir.etc }}/{{ name }}.yml - - require: - - sls: {{ sls_service_clean }} + - require_in: + - file: prometheus-config-file-etc-file-absent {%- endfor %} prometheus-config-file-etc-file-absent: file.absent: - name: {{ prometheus.dir.etc }} + - require: + - sls: {{ sls_service_clean }} diff --git a/prometheus/config/file/install.sls b/prometheus/config/file/install.sls index bb48a1d..6bd6b02 100644 --- a/prometheus/config/file/install.sls +++ b/prometheus/config/file/install.sls @@ -5,13 +5,13 @@ {%- set tplroot = tpldir.split('/')[0] %} {%- from tplroot ~ "/map.jinja" import prometheus with context %} {%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} -{%- set sls_users_install = tplroot ~ '.config.users' %} +{%- set sls_config_users = tplroot ~ '.config.users' %} {%- set sls_archive_install = tplroot ~ '.archive' %} {%- set sls_package_install = tplroot ~ '.package' %} include: - {{ sls_archive_install if prometheus.use_upstream_archive else sls_package_install }} - - {{ sls_users_install }} + - {{ sls_config_users }} prometheus-config-file-etc-file-directory: file.directory: @@ -20,8 +20,8 @@ prometheus-config-file-etc-file-directory: - group: prometheus - mode: 755 - makedirs: True - # require: - # sls: {{ sls_archive_install if prometheus.use_upstream_archive else sls_package_install }} + - require: + - sls: '{{ sls_archive_install if prometheus.use_upstream_archive else sls_package_install }}.*' {%- for name in prometheus.wanted %} {%- if name in prometheus.config or name in prometheus.service %} @@ -41,8 +41,8 @@ prometheus-config-file-{{ name }}-file-managed: - context: config: {{ '' if name not in prometheus.config else prometheus.config[name]|json }} - require: + - user: prometheus-config-user-install-{{ name }}-user-present - file: prometheus-config-file-etc-file-directory - # user: prometheus-config-user-install-{{ name }}-user-present {%- endif %} {%- endfor %} diff --git a/prometheus/defaults.yaml b/prometheus/defaults.yaml index 1c26294..65ee034 100644 --- a/prometheus/defaults.yaml +++ b/prometheus/defaults.yaml @@ -18,7 +18,6 @@ prometheus: etc: /etc/prometheus var: /var/lib/prometheus args: /etc/default - default: /etc/default service: /usr/lib/systemd/system service: @@ -29,6 +28,7 @@ prometheus: config: prometheus: {} + alertmanager: {} pkg: prometheus: diff --git a/prometheus/map.jinja b/prometheus/map.jinja index 183d72c..ac49be0 100644 --- a/prometheus/map.jinja +++ b/prometheus/map.jinja @@ -7,18 +7,16 @@ {%- import_yaml tplroot ~ "/defaults.yaml" as default_settings %} {%- import_yaml tplroot ~ "/osarchmap.yaml" as osarchmap %} {%- import_yaml tplroot ~ "/osfamilymap.yaml" as osfamilymap %} -{%- import_yaml tplroot ~ "/archive/defaults.yaml" as archive_defaults %} {%- set defaults = salt['grains.filter_by'](default_settings, - merge=salt['grains.filter_by'](archive_defaults, - merge=salt['grains.filter_by'](osarchmap, grain='osarch', - merge=salt['grains.filter_by'](osfamilymap, grain='os_family', - merge=salt['pillar.get']('prometheus:lookup', default={}), - base='prometheus'), - base='prometheus'), - base='prometheus'), - base='prometheus') -%} + default='prometheus', + merge=salt['grains.filter_by'](osarchmap, grain='osarch', + merge=salt['grains.filter_by'](osfamilymap, grain='os_family', + merge=salt['pillar.get']('prometheus:lookup', default={}) + ) + ) +) %} + {#- Merge the prometheus pillar #} {%- set prometheus = salt['pillar.get']('prometheus', default=defaults, merge=True) %}