From 8d0872bce53c3597c82b61af4261ef721e1169f5 Mon Sep 17 00:00:00 2001 From: m0duspwnens Date: Mon, 13 Dec 2021 15:48:30 -0500 Subject: [PATCH] create node_data pillar from mine data, use node_data pillar for filebeat config --- pillar/node_data/ips.sls | 23 ++++++++++++++++++++++ pillar/node_data/test_ping.sls | 23 ++++++++++++++++++++++ pillar/top.sls | 2 ++ salt/filebeat/etc/filebeat.yml | 8 ++++++-- salt/salt/etc/minion.d/mine_functions.conf | 1 + 5 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 pillar/node_data/ips.sls create mode 100644 pillar/node_data/test_ping.sls diff --git a/pillar/node_data/ips.sls b/pillar/node_data/ips.sls new file mode 100644 index 000000000..40551eafc --- /dev/null +++ b/pillar/node_data/ips.sls @@ -0,0 +1,23 @@ +{% set node_types = {} %} +{% for minionid, ip in salt.saltutil.runner('mine.get', tgt='*', fun='network.ip_addrs', tgt_type='glob') | dictsort() %} +{% set hostname = minionid.split('_')[0] %} +{% set node_type = minionid.split('_')[1] %} +{% if node_type not in node_types.keys() %} +{% do node_types.update({node_type: {hostname: ip[0]}}) %} +{% else %} +{% if hostname not in node_types[node_type] %} +{% do node_types[node_type].update({hostname: ip[0]}) %} +{% else %} +{% do node_types[node_type][hostname].update(ip[0]) %} +{% endif %} +{% endif %} +{% endfor %} + +node_data: +{% for node_type, values in node_types.items() %} + {{node_type}}: +{% for hostname, ip in values.items() %} + {{hostname}}: + ip: {{ip}} +{% endfor %} +{% endfor %} diff --git a/pillar/node_data/test_ping.sls b/pillar/node_data/test_ping.sls new file mode 100644 index 000000000..81cf66004 --- /dev/null +++ b/pillar/node_data/test_ping.sls @@ -0,0 +1,23 @@ +{% set node_types = {} %} +{% for minionid, test_ping in salt.saltutil.runner('mine.get', tgt='*', fun='test.ping', tgt_type='glob') | dictsort() %} +{% set node_type = minionid.split('_')[1] %} +{% set hostname = minionid.split('_')[0] %} +{% if node_type not in node_types.keys() %} +{% do node_types.update({node_type: {hostname: test_ping}}) %} +{% else %} +{% if hostname not in node_types[node_type] %} +{% do node_types[node_type].update({hostname: test_ping}) %} +{% else %} +{% do node_types[node_type][hostname].update(test_ping) %} +{% endif %} +{% endif %} +{% endfor %} + +node_data: +{% for node_type, values in node_types.items() %} + {{node_type}}: +{% for hostname, test_ping in values.items() %} + {{hostname}}: + test_ping: {{test_ping}} +{% endfor %} +{% endfor %} diff --git a/pillar/top.sls b/pillar/top.sls index b3cc8dc8f..6517fce6d 100644 --- a/pillar/top.sls +++ b/pillar/top.sls @@ -2,6 +2,8 @@ base: '*': - patch.needs_restarting - logrotate + - node_data.ips + - node_data.test_ping '*_eval or *_helixsensor or *_heavynode or *_sensor or *_standalone or *_import': - match: compound diff --git a/salt/filebeat/etc/filebeat.yml b/salt/filebeat/etc/filebeat.yml index 02c094f80..f29205743 100644 --- a/salt/filebeat/etc/filebeat.yml +++ b/salt/filebeat/etc/filebeat.yml @@ -324,8 +324,12 @@ output.logstash: hosts: {%- set LOADBALANCE = ['false'] %} {%- if grains.role not in ['so-heavynode', 'so-import', 'so-helix', 'so-eval'] %} -{%- for minionid, ip in salt['mine.get']('G@role:so-standalone or G@role:so-manager or G@role:so-managersearch or G@role:so-receiver', 'network.ip_addrs', tgt_type='compound') | dictsort() %} - - "{{ minionid.split('_')[0] }}:5644" #{{ ip[0] }} +{%- for node_type, node_details in salt['pillar.get']('node_data') | dictsort() %} +{%- if node_type in ['manager', 'managersearch', 'standalone', 'receiver' ] %} +{%- for hostname in node_type.keys() %} + - "{{ hostname }}:5644" #{{ node_details[hostname][ip] }} +{%- endfor %} +{%- endif %} {%- if loop.index == 2 %} {%- do LOADBALANCE.insert(0, 'true') %} {%- endif %} diff --git a/salt/salt/etc/minion.d/mine_functions.conf b/salt/salt/etc/minion.d/mine_functions.conf index 42a543841..023ba0308 100644 --- a/salt/salt/etc/minion.d/mine_functions.conf +++ b/salt/salt/etc/minion.d/mine_functions.conf @@ -1,3 +1,4 @@ mine_functions: + test.ping: [] network.ip_addrs: - interface: {{ pillar.host.mainint }}