Skip to content

Commit badd17e

Browse files
absmith82myii
andauthored
refactor(map and defaults): update the map.jinja file and add yaml maps
* Updated the map.jinja file and added yaml maps This changes the map.jinja file to be more like the standard template. It also adds defaults, osfamlymap, osfingermap, and osmap yaml files for easy mapping of the proper packages and settings for each OS and version of the OS. * fix: modify to ensure identical results before and after * fix(map.jinja): use literal value instead of `tplroot` - Avoid issues with template: - `[ERROR ] Unable to manage file: Jinja variable 'tpldir' is undefined` Co-authored-by: Imran Iqbal <[email protected]>
1 parent 347c21f commit badd17e

File tree

5 files changed

+370
-238
lines changed

5 files changed

+370
-238
lines changed

zabbix/defaults.yaml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=yaml
3+
---
4+
zabbix:
5+
version_repo: 2.2
6+
user: zabbix
7+
group: zabbix
8+
home: /var/lib/zabbix
9+
shell: /sbin/nologin
10+
agent:
11+
pkgs:
12+
- zabbix-agent
13+
- zabbix-sender
14+
service: zabbix-agent
15+
config: /etc/zabbix/zabbix_agentd.conf
16+
pidfile: /var/run/zabbix/zabbix_agentd.pid
17+
logfile: /var/log/zabbix/zabbix_agentd.log
18+
logfilesize: '0'
19+
server:
20+
- 127.0.0.1
21+
serveractive:
22+
- 127.0.0.1
23+
includes:
24+
- /etc/zabbix/zabbix_agentd.d/
25+
server:
26+
pkgs:
27+
- zabbix-server-mysql
28+
- zabbix-get
29+
service: zabbix-server
30+
config: /etc/zabbix/zabbix_server.conf
31+
pidfile: /var/run/zabbix/zabbix_server.pid
32+
socketdir: /var/run/zabbix
33+
logfile: /var/log/zabbix/zabbix_server.log
34+
logfilesize: '0'
35+
dbhost: localhost
36+
dbname: zabbix
37+
dbuser: zabbix
38+
dbpassword: zabbix
39+
dbsocket: /var/run/mysqld/mysqld.sock
40+
timeout: '4'
41+
alertscriptspath: /usr/lib/zabbix/alertscripts
42+
externalscripts: /usr/lib/zabbix/externalscripts
43+
fpinglocation: /usr/bin/fping
44+
fping6location: /usr/bin/fping6
45+
logslowqueries: '3000'
46+
frontend:
47+
pkgs:
48+
- zabbix-web-mysql
49+
config: /etc/zabbix/web/zabbix.conf.php
50+
dbtype: MYSQL
51+
dbhost: localhost
52+
dbname: zabbix
53+
dbuser: zabbix
54+
dbpassword: zabbix
55+
zbxserver: localhost
56+
zbxserverport: '10051'
57+
zbxservername: Zabbix installed with SaltStack
58+
proxy:
59+
pkgs:
60+
- zabbix-proxy-sqlite3
61+
- zabbix-get
62+
service: zabbix-proxy
63+
config: /etc/zabbix/zabbix_proxy.conf
64+
dbname: /var/lib/zabbix/zabbix_proxy.db
65+
pidfile: /var/run/zabbix/zabbix_proxy.pid
66+
logfile: /var/log/zabbix/zabbix_proxy.log
67+
mysql:
68+
skip_pkgs: false
69+
dbhost: localhost
70+
dbname: zabbix
71+
dbuser: zabbix
72+
dbpassword: zabbix
73+
dbuser_host: localhost
74+
pgsql:
75+
skip_pkgs: false
76+
dbhost: localhost
77+
dbname: zabbix
78+
dbuser: zabbix
79+
dbpassword: zabbix

zabbix/map.jinja

Lines changed: 31 additions & 238 deletions
Original file line numberDiff line numberDiff line change
@@ -1,242 +1,35 @@
1-
{% set zabbix = salt['grains.filter_by']({
2-
'Debian': {
3-
'version_repo': '2.2',
4-
'user': 'zabbix',
5-
'group': 'zabbix',
6-
'home': '/var/lib/zabbix',
7-
'shell': '/bin/false',
8-
'agent': {
9-
'pkgs': ['zabbix-agent', 'zabbix-sender'],
10-
'service': 'zabbix-agent',
11-
'config': '/etc/zabbix/zabbix_agentd.conf',
12-
'pidfile': '/var/run/zabbix/zabbix_agentd.pid',
13-
'logfile': '/var/log/zabbix/zabbix_agentd.log',
14-
'logfilesize': '0',
15-
'server': ['127.0.0.1'],
16-
'serveractive': ['127.0.0.1'],
17-
'includes': ['/etc/zabbix/zabbix_agentd.d/']
18-
},
19-
'server': {
20-
'pkgs': ['zabbix-server-mysql', 'zabbix-get'],
21-
'service': 'zabbix-server',
22-
'config': '/etc/zabbix/zabbix_server.conf',
23-
'pidfile': '/var/run/zabbix/zabbix_server.pid',
24-
'socketdir': '/var/run/zabbix',
25-
'logfile': '/var/log/zabbix/zabbix_server.log',
26-
'logfilesize': '0',
27-
'dbhost': 'localhost',
28-
'dbname': 'zabbix',
29-
'dbuser': 'zabbix',
30-
'dbpassword': 'zabbix',
31-
'dbsocket': '/var/run/mysqld/mysqld.sock',
32-
'snmptrapperfile': '/var/log/snmptrap/snmptrap.log',
33-
'timeout': '4',
34-
'alertscriptspath': '/usr/lib/zabbix/alertscripts',
35-
'externalscripts': '/usr/lib/zabbix/externalscripts',
36-
'fpinglocation': '/usr/bin/fping',
37-
'fping6location': '/usr/bin/fping6',
38-
'logslowqueries': '3000'
39-
},
40-
'frontend': {
41-
'pkgs': ['zabbix-frontend-php'],
42-
'config': '/etc/zabbix/web/zabbix.conf.php'
43-
},
44-
'proxy': {
45-
'pkgs': ['zabbix-proxy-sqlite3', 'zabbix-get'],
46-
'service': 'zabbix-proxy',
47-
'config': '/etc/zabbix/zabbix_proxy.conf',
48-
'dbname': '/var/lib/zabbix/zabbix_proxy.db',
49-
'pidfile': '/var/run/zabbix/zabbix_proxy.pid',
50-
'logfile': '/var/log/zabbix/zabbix_proxy.log',
51-
'logfilesize': '0',
52-
'socketdir': '/var/run/zabbix',
53-
'startpreprocessors': '3',
54-
'externalscripts': '/usr/lib/zabbix/externalscripts',
55-
'fpinglocation': '/usr/bin/fping',
56-
'fping6location': '/usr/bin/fping6',
57-
'statsallowedip': '127.0.0.1',
58-
'includes': ['/etc/zabbix/zabbix_proxy.d/']
59-
},
60-
'mysql': {
61-
'pkgs': ['python-mysqldb']
62-
},
63-
'pgsql': {
64-
'pkgs': ['postgresql-client-common', 'postgresql-client']
65-
}
66-
},
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=jinja
673

68-
'RedHat': {
69-
'version_repo': '2.2',
70-
'user': 'zabbix',
71-
'group': 'zabbix',
72-
'shell': '/sbin/nologin',
73-
'agent': {
74-
'pkgs': ['zabbix-agent'],
75-
'service': 'zabbix-agent',
76-
'config': '/etc/zabbix/zabbix_agentd.conf',
77-
'pidfile': '/var/run/zabbix/zabbix_agentd.pid',
78-
'logfile': '/var/log/zabbix/zabbix_agentd.log',
79-
'includes': ['/etc/zabbix/zabbix_agentd.d/*.conf']
80-
},
81-
'server': {
82-
'pkgs': ['zabbix-server-mysql'],
83-
'service': 'zabbix-server',
84-
'config': '/etc/zabbix/zabbix_server.conf',
85-
'dbsocket': '/var/lib/mysql/mysql.sock',
86-
'pidfile': '/var/run/zabbix/zabbix_server.pid',
87-
'logfile': '/var/log/zabbix/zabbix_server.log',
88-
'snmptrapperfile': '/var/log/snmptrap/snmptrap.log',
89-
'fpinglocation': '/usr/sbin/fping',
90-
'fping6location': '/usr/sbin/fping6'
91-
},
92-
'frontend': {
93-
'pkgs': ['zabbix-web-mysql'],
94-
'config': '/etc/zabbix/web/zabbix.conf.php'
95-
},
96-
'proxy': {
97-
'pkgs': ['zabbix-proxy-sqlite3'],
98-
'service': 'zabbix-proxy',
99-
'config': '/etc/zabbix/zabbix_proxy.conf',
100-
'dbname': '/var/lib/zabbix/zabbix_proxy.db',
101-
'pidfile': '/var/run/zabbix/zabbix_proxy.pid',
102-
'logfile': '/var/log/zabbix/zabbix_proxy.log'
103-
},
104-
'mysql': {
105-
'pkgs': ['MySQL-python']
106-
}
107-
},
4+
{#- Start imports as #}
5+
{%- import_yaml "zabbix/defaults.yaml" as default_settings %}
6+
{%- import_yaml "zabbix/osfamilymap.yaml" as osfamilymap %}
7+
{%- import_yaml "zabbix/osmap.yaml" as osmap %}
8+
{%- import_yaml "zabbix/osfingermap.yaml" as osfingermap %}
1089

109-
'FreeBSD': {
110-
'version_repo': '2.2',
111-
'user': 'zabbix',
112-
'group': 'zabbix',
113-
'home': '/var/lib/zabbix',
114-
'shell': '/sbin/nologin',
115-
'agent': {
116-
'pkgs': ['zabbix22-agent'],
117-
'service': 'zabbix_agentd',
118-
'config': '/usr/local/etc/zabbix22/zabbix_agentd.conf',
119-
'pidfile': '/var/run/zabbix/zabbix_agentd.pid',
120-
'logfile': '/var/log/zabbix/zabbix_agentd.log'
121-
},
122-
'server': {
123-
'pkgs': ['zabbix22-server'],
124-
'service': 'zabbix',
125-
'config': '/usr/local/etc/zabbix22/zabbix_server.conf',
126-
'dbsocket': '/var/run/mysqld/mysqld.sock',
127-
'pidfile': '/var/run/zabbix/zabbix_server.pid',
128-
'logfile': '/var/log/zabbix/zabbix_server.log'
129-
},
130-
'proxy': {
131-
'pkgs': ['zabbix22-proxy'],
132-
'service': 'zabbix_proxy',
133-
'config': '/usr/local/etc/zabbix22/zabbix_proxy.conf',
134-
'dbname': '/var/lib/zabbix/zabbix_proxy.db',
135-
'pidfile': '/var/run/zabbix/zabbix_proxy.pid',
136-
'logfile': '/var/log/zabbix/zabbix_proxy.log'
137-
}
138-
},
10+
{#- Retrieve the config dict only once #}
11+
{%- set _config = salt['config.get']('zabbix', default={}) %}
13912

140-
'OpenBSD': {
141-
'version_repo': '2.4',
142-
'user': '_zabbix',
143-
'group': '_zabbix',
144-
'shell': '/sbin/nologin',
145-
'agent': {
146-
'pkgs': ['zabbix-agent'],
147-
'service': 'zabbix_agentd',
148-
'config': '/etc/zabbix/zabbix_agentd.conf',
149-
'pidfile': '/var/run/zabbix/zabbix_agentd.pid',
150-
'logfile': '/var/log/zabbix/zabbix_agentd.log'
151-
},
152-
},
13+
{%- set config = salt['grains.filter_by'](
14+
default_settings,
15+
default='zabbix',
16+
merge=salt['grains.filter_by'](
17+
osfamilymap,
18+
grain='os_family',
19+
merge=salt['grains.filter_by'](
20+
osmap,
21+
grain='os',
22+
merge=salt['grains.filter_by'](
23+
osfingermap,
24+
grain='osfinger',
25+
merge=salt['grains.filter_by'](
26+
_config,
27+
default='lookup'
28+
)
29+
)
30+
)
31+
)
32+
)
33+
%}
15334

154-
'Windows':{
155-
'user': 'Administrator',
156-
'group': 'Administrators',
157-
'agent': {
158-
'version': '3.0.28.2400',
159-
'pkgs': ['zabbix-agent'],
160-
'service': 'Zabbix Agent',
161-
'config': 'C:\\Program Files\\Zabbix Agent\\zabbix_agentd.conf',
162-
'logfile': 'C:\\Program Files\\Zabbix Agent\\zabbix_agentd.log',
163-
'logfilesize': '5',
164-
'pidfile': '',
165-
'includes': [],
166-
},
167-
},
168-
169-
'default': {
170-
'version_repo': '2.2',
171-
'user': 'zabbix',
172-
'group': 'zabbix',
173-
'home': '/var/lib/zabbix',
174-
'shell': '/sbin/nologin',
175-
'agent': {
176-
'pkgs': ['zabbix-agent', 'zabbix-sender'],
177-
'service': 'zabbix-agent',
178-
'config': '/etc/zabbix/zabbix_agentd.conf',
179-
'pidfile': '/var/run/zabbix/zabbix_agentd.pid',
180-
'logfile': '/var/log/zabbix/zabbix_agentd.log',
181-
'logfilesize': '0',
182-
'server': ['127.0.0.1'],
183-
'serveractive': ['127.0.0.1'],
184-
'includes': ['/etc/zabbix/zabbix_agentd.d/']
185-
},
186-
'server': {
187-
'pkgs': ['zabbix-server-mysql', 'zabbix-get'],
188-
'service': 'zabbix-server',
189-
'config': '/etc/zabbix/zabbix_server.conf',
190-
'pidfile': '/var/run/zabbix/zabbix_server.pid',
191-
'socketdir': '/var/run/zabbix',
192-
'logfile': '/var/log/zabbix/zabbix_server.log',
193-
'logfilesize': '0',
194-
'dbhost': 'localhost',
195-
'dbname': 'zabbix',
196-
'dbuser': 'zabbix',
197-
'dbpassword': 'zabbix',
198-
'dbsocket': '/var/run/mysqld/mysqld.sock',
199-
'timeout': '4',
200-
'alertscriptspath': '/usr/lib/zabbix/alertscripts',
201-
'externalscripts': '/usr/lib/zabbix/externalscripts',
202-
'fpinglocation': '/usr/bin/fping',
203-
'fping6location': '/usr/bin/fping6',
204-
'logslowqueries': '3000'
205-
},
206-
'frontend': {
207-
'pkgs': ['zabbix-web-mysql'],
208-
'config': '/etc/zabbix/web/zabbix.conf.php',
209-
'dbtype': 'MYSQL',
210-
'dbhost': 'localhost',
211-
'dbname': 'zabbix',
212-
'dbuser': 'zabbix',
213-
'dbpassword': 'zabbix',
214-
'zbxserver': 'localhost',
215-
'zbxserverport': '10051',
216-
'zbxservername': 'Zabbix installed with SaltStack'
217-
},
218-
'proxy': {
219-
'pkgs': ['zabbix-proxy-sqlite3', 'zabbix-get'],
220-
'service': 'zabbix-proxy',
221-
'config': '/etc/zabbix/zabbix_proxy.conf',
222-
'dbname': '/var/lib/zabbix/zabbix_proxy.db',
223-
'pidfile': '/var/run/zabbix/zabbix_proxy.pid',
224-
'logfile': '/var/log/zabbix/zabbix_proxy.log'
225-
},
226-
'mysql': {
227-
'skip_pkgs': false,
228-
'dbhost': 'localhost',
229-
'dbname': 'zabbix',
230-
'dbuser': 'zabbix',
231-
'dbpassword': 'zabbix',
232-
'dbuser_host': 'localhost'
233-
},
234-
'pgsql': {
235-
'skip_pkgs': false,
236-
'dbhost': 'localhost',
237-
'dbname': 'zabbix',
238-
'dbuser': 'zabbix',
239-
'dbpassword': 'zabbix'
240-
}
241-
},
242-
}, merge=salt['pillar.get']('zabbix:lookup'), base='default') %}
35+
{%- set zabbix = config %}

0 commit comments

Comments
 (0)