Skip to content

Commit b4f04a5

Browse files
committed
Merge branch 'devel'
2 parents 5efcbcd + 3341079 commit b4f04a5

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM python:2.7-slim
2+
3+
COPY . /policykeeper
4+
WORKDIR /policykeeper
5+
6+
RUN pip install --upgrade pip && \
7+
pip install -r requirements.txt
8+
9+
CMD /policykeeper/policy_keeper.py --srv
10+

handle_prometheus.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,24 @@ def add_exporters_to_prometheus_config(policy, template_file, config_file):
147147
exp = exporter_endpoint.split(':')
148148
if len(exp) == 1:
149149
continue
150-
static_config['targets'].append(exporter_endpoint)
150+
elif '.' not in exp[0]:
151+
kube_job = [x for x in config_content['scrape_configs'] if x.get('job_name') == 'kube-services']
152+
if not kube_job:
153+
continue
154+
relabel = kube_job[0].get('relabel_configs', [])
155+
old_label = [x for x in relabel if x.get('action') == 'keep']
156+
if old_label:
157+
old_label = old_label[0]
158+
old_regex = old_label.get('regex')
159+
new_regex = '{}|.*{}'.format(old_regex, exp[1])
160+
old_label['regex'] = new_regex
161+
else:
162+
label = {'source_labels': ['__address__'],
163+
'action': 'keep',
164+
'regex': '.*{}'.format(exp[1])}
165+
relabel.append(label)
166+
else:
167+
static_config['targets'].append(exporter_endpoint)
151168
config_changed = True
152169
log.info('(C) => exporter "{0}" added to config'.format(exporter_endpoint))
153170
else:

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ idna==2.6
1111
ipaddress==1.0.19
1212
itsdangerous==0.24
1313
Jinja2==2.10
14+
kubernetes==8.0.1
1415
MarkupSafe==1.0
1516
numpy==1.14.0
1617
post==0.0.26

0 commit comments

Comments
 (0)