diff --git a/states/zabbix/agent/config.sls b/states/zabbix/agent/config.sls new file mode 100644 index 0000000..ae131ea --- /dev/null +++ b/states/zabbix/agent/config.sls @@ -0,0 +1,28 @@ +--- +{%- from "zabbix/map.jinja" import zabbix with context %} +zabbix_log_dir: + file.directory: + - name: /var/log/zabbix + - user: zabbix + - group: zabbix + - mode: 755 + - watch_in: + - service: zabbix_agent_service + +zabbix_agent_config: + file.managed: + - name: /etc/zabbix/zabbix_agentd.conf + - source: salt://zabbix/templates/zabbix_agentd.conf.j2 + - template: jinja + - watch_in: + - service: zabbix_agent_service + +{% if zabbix.agent.config.TLSPSKFile is iterable %} +zabbix_agent_tlspsk_file: + file.managed: + - name: {{ zabbix.agent.config.TLSPSKFile }} + - contents: {{ zabbix.agent.psk }} + - create: true + - watch_in: + - service: zabbix_agent_service +{% endif %} diff --git a/states/zabbix/agent/init.sls b/states/zabbix/agent/init.sls new file mode 100644 index 0000000..383c46b --- /dev/null +++ b/states/zabbix/agent/init.sls @@ -0,0 +1,5 @@ +--- +include: + - .install + - .config + - .service diff --git a/states/zabbix/agent/install.sls b/states/zabbix/agent/install.sls new file mode 100644 index 0000000..3a9ce87 --- /dev/null +++ b/states/zabbix/agent/install.sls @@ -0,0 +1,5 @@ +--- +{%- from "zabbix/map.jinja" import zabbix with context %} +zabbix_agent_pkgs: + pkg.latest: + - pkgs: {{ zabbix.agent.pkgs }} diff --git a/states/zabbix/agent/service.sls b/states/zabbix/agent/service.sls new file mode 100644 index 0000000..fb76766 --- /dev/null +++ b/states/zabbix/agent/service.sls @@ -0,0 +1,6 @@ +--- +{%- from "zabbix/map.jinja" import zabbix with context %} +zabbix_agent_service: + service.running: + - name: zabbix-agent + - enable: true diff --git a/states/zabbix/config.sls b/states/zabbix/config.sls deleted file mode 100644 index da936cc..0000000 --- a/states/zabbix/config.sls +++ /dev/null @@ -1,7 +0,0 @@ ---- -{%- from "zabbix_server/map.jinja" import zabbix_server with context %} -zabbix_server-config: - file.managed: - - name: /etc/zabbix/zabbix_server.conf - - source: salt://zabbix_server/templates/zabbix_server.conf.j2 - - template: jinja diff --git a/states/zabbix/defaults.yaml b/states/zabbix/defaults.yaml index 3fd2f08..0836ffd 100644 --- a/states/zabbix/defaults.yaml +++ b/states/zabbix/defaults.yaml @@ -1,10 +1,26 @@ --- -zabbix_server: - pkgs: - - zabbix-frontend-php - - zabbix-server-pgsql - config: - DBHost: zabbix - DBName: zabbix - DBUser: zabbix - DBPassword: zabbix +zabbix: + server: + enabled: false + pkgs: + - zabbix-frontend-php + - zabbix-server-pgsql + config: + DBHost: zabbix + DBName: zabbix + DBPassword: zabbix + DBUser: zabbix + LogFile: /var/log/zabbix/zabbix_server.log + LogType: file + PidFile: /run/zabbix/zabbix_server.pid + agent: + enabled: true + pkgs: + - zabbix-agent + config: + LogFile: /var/log/zabbix/zabbix_agentd.log + LogFileSize: 0 + LogType: file + PidFile: /var/run/zabbix/zabbix_agentd.pid + Server: 127.0.0.1 + ServerActive: zabbix.paulbsd.com diff --git a/states/zabbix/init.sls b/states/zabbix/init.sls index 5bf7f86..08a5a54 100644 --- a/states/zabbix/init.sls +++ b/states/zabbix/init.sls @@ -1,8 +1,13 @@ --- +{%- from "zabbix/map.jinja" import zabbix with context %} include: +{% if zabbix.server.enabled %} + - repos - postgresql - php - - .install - - .provision - - .config - - .service + - .server +{% endif %} +{% if zabbix.agent.enabled %} + - repos + - .agent +{% endif %} diff --git a/states/zabbix/install.sls b/states/zabbix/install.sls deleted file mode 100644 index 0a44040..0000000 --- a/states/zabbix/install.sls +++ /dev/null @@ -1,5 +0,0 @@ ---- -{%- from "zabbix_server/map.jinja" import zabbix_server with context %} -zabbix_server_pkgs: - pkg.latest: - - pkgs: {{ zabbix_server.pkgs }} diff --git a/states/zabbix/map.jinja b/states/zabbix/map.jinja index cf41913..0729872 100644 --- a/states/zabbix/map.jinja +++ b/states/zabbix/map.jinja @@ -1,5 +1,5 @@ -{%- import_yaml "zabbix_server/defaults.yaml" as default_settings -%} +{%- import_yaml "zabbix/defaults.yaml" as default_settings -%} -{%- set defaults = salt['grains.filter_by'](default_settings, default='zabbix_server') -%} +{%- set defaults = salt['grains.filter_by'](default_settings, default='zabbix') -%} -{%- set zabbix_server = salt['pillar.get']('zabbix_server', default=defaults, merge=True) -%} +{%- set zabbix = salt['pillar.get']('zabbix', default=defaults, merge=True) -%} diff --git a/states/zabbix/provision.sls b/states/zabbix/provision.sls deleted file mode 100644 index e69de29..0000000 diff --git a/states/zabbix/repo.sls b/states/zabbix/repo.sls new file mode 100644 index 0000000..2e9e3ec --- /dev/null +++ b/states/zabbix/repo.sls @@ -0,0 +1,9 @@ +--- +{%- from "zabbix/map.jinja" import zabbix with context %} +zabbix_repo: + pkgrepo.managed: + - name: deb {{ zabbix.repo.url }} {{ zabbix.repo.distro }} main + - humanname: Zabbix repository + - file: /etc/apt/sources.list.d/zabbix.list + - keyid: 082AB56BA14FE591 + - keyserver: keyserver.ubuntu.com diff --git a/states/zabbix/server/config.sls b/states/zabbix/server/config.sls new file mode 100644 index 0000000..7ff5fdd --- /dev/null +++ b/states/zabbix/server/config.sls @@ -0,0 +1,7 @@ +--- +{%- from "zabbix/map.jinja" import zabbix with context %} +zabbix_server_config: + file.managed: + - name: /etc/zabbix/zabbix_server.conf + - source: salt://zabbix/templates/zabbix_server.conf.j2 + - template: jinja diff --git a/states/zabbix/server/init.sls b/states/zabbix/server/init.sls new file mode 100644 index 0000000..383c46b --- /dev/null +++ b/states/zabbix/server/init.sls @@ -0,0 +1,5 @@ +--- +include: + - .install + - .config + - .service diff --git a/states/zabbix/server/install.sls b/states/zabbix/server/install.sls new file mode 100644 index 0000000..63dcf61 --- /dev/null +++ b/states/zabbix/server/install.sls @@ -0,0 +1,5 @@ +--- +{%- from "zabbix/map.jinja" import zabbix with context %} +zabbix_server_pkgs: + pkg.latest: + - pkgs: {{ zabbix.server.pkgs }} diff --git a/states/zabbix/server/service.sls b/states/zabbix/server/service.sls new file mode 100644 index 0000000..5b91044 --- /dev/null +++ b/states/zabbix/server/service.sls @@ -0,0 +1,6 @@ +--- +{%- from "zabbix/map.jinja" import zabbix with context %} +zabbix_server_service: + service.running: + - name: zabbix-server + - enable: true diff --git a/states/zabbix/service.sls b/states/zabbix/service.sls deleted file mode 100644 index 2d6b9bd..0000000 --- a/states/zabbix/service.sls +++ /dev/null @@ -1,6 +0,0 @@ ---- -{%- from "zabbix_server/map.jinja" import zabbix_server with context %} -zabbix_server-service: - service.running: - - name: zabbix-server - - enabled: true diff --git a/states/zabbix/templates/zabbix_agentd.conf.j2 b/states/zabbix/templates/zabbix_agentd.conf.j2 new file mode 100644 index 0000000..6890570 --- /dev/null +++ b/states/zabbix/templates/zabbix_agentd.conf.j2 @@ -0,0 +1,4 @@ +{%- from "zabbix/map.jinja" import zabbix with context %} +{%- for k, v in zabbix.agent.config.items() %} +{{ k }}={{ v }} +{%- endfor %} diff --git a/states/zabbix/templates/zabbix_server.conf.j2 b/states/zabbix/templates/zabbix_server.conf.j2 index 334ceec..8d983bf 100644 --- a/states/zabbix/templates/zabbix_server.conf.j2 +++ b/states/zabbix/templates/zabbix_server.conf.j2 @@ -1,4 +1,4 @@ -{%- from "zabbix_server/map.jinja" import zabbix_server with context %} -{% for k, v in zabbix_server.config.items() %} +{%- from "zabbix/map.jinja" import zabbix with context %} +{%- for k, v in zabbix.server.config.items() %} {{ k }}={{ v }} -{% endfor %} +{%- endfor %}