From 53932d47a1f1ea6cdb4704f211f7df35818c3034 Mon Sep 17 00:00:00 2001 From: Ildar Svetlov Date: Thu, 5 Apr 2018 17:49:24 +0400 Subject: [PATCH] Collect dns targets from grains Change-Id: If0ca7f7cb917537c0fbba9c6a4da479adada111d --- prometheus/files/server/prometheus.yml | 36 +++++++++++++++++++------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/prometheus/files/server/prometheus.yml b/prometheus/files/server/prometheus.yml index 3bb85f7..17a243c 100644 --- a/prometheus/files/server/prometheus.yml +++ b/prometheus/files/server/prometheus.yml @@ -315,15 +315,31 @@ scrape_configs: {%- endif %} {%- endif %} -{%- if server.get('target', {}).get('dns', {}).get('enabled', False) %} - {%- for target in server.get('target', {}).get('dns', {}).get('endpoint', []) %} - - job_name: {{ target.name }} - dns_sd_configs: - - names: - {%- for domain in target.domain %} - - {{ domain }} - {%- endfor %} - type: {{ target.type }} - port: {{ target.port }} +{%- set dns_endpoints = {} %} +{%- if server.get('use_grains', {}).get('target', True) %} + {%- for node_name, node_grains in salt['mine.get']('*', 'grains.items').iteritems() %} + {%- set dns_grain = node_grains.get('prometheus', {}).get('server', {}).get('target', {}).get('dns', {}) %} + {%- if dns_grain.get('enabled', False) %} + {%- for endpoint in dns_grain.get('endpoint', []) %} + {%- do dns_endpoints.update({endpoint.name: endpoint}) %} + {%- endfor %} + {%- endif %} {%- endfor %} {%- endif %} + +{%- if server.get('target', {}).get('dns', {}).get('enabled', False) %} + {%- for endpoint in server.get('target', {}).get('dns', {}).get('endpoint', []) %} + {%- do dns_endpoints.update({endpoint.name: endpoint}) %} + {%- endfor %} +{%- endif %} + +{%- for name, endpoint in dns_endpoints | dictsort %} + - job_name: {{ endpoint.name }} + dns_sd_configs: + - names: + {%- for domain in endpoint.domain %} + - {{ domain }} + {%- endfor %} + type: {{ endpoint.type }} + port: {{ endpoint.port }} +{%- endfor %}