diff --git a/states/zabbix/agent2/config.sls b/states/zabbix/agent2/config.sls new file mode 100644 index 0000000..a4e3f81 --- /dev/null +++ b/states/zabbix/agent2/config.sls @@ -0,0 +1,61 @@ +--- +{%- from "zabbix/map.jinja" import zabbix with context %} +zabbix-config-dir: + file.directory: + - name: /etc/zabbix + - user: {{ zabbix.agent2.user }} + - group: {{ zabbix.agent2.user }} + - mode: 755 + - watch_in: + - service: zabbix-agent2-service + +zabbix-log-dir: + file.directory: + - name: /var/log/zabbix + - user: {{ zabbix.agent2.user }} + - group: {{ zabbix.agent2.user }} + - mode: 755 + - watch_in: + - service: zabbix-agent2-service + +zabbix-agent2-config-dir: + file.directory: + - name: /etc/zabbix/zabbix_agent2.d + - user: {{ zabbix.agent2.user }} + - group: {{ zabbix.agent2.user }} + - mode: 755 + - watch_in: + - service: zabbix-agent2-service + +zabbix-agent2-config: + file.managed: + - name: /etc/zabbix/zabbix_agent2.conf + - user: {{ zabbix.agent2.user }} + - group: {{ zabbix.agent2.user }} + - source: salt://zabbix/templates/zabbix_agent2.conf.j2 + - template: jinja + - watch_in: + - service: zabbix-agent2-service + +{% if zabbix.agent2.config.TLSPSKFile is iterable %} +zabbix-agent2-tlspsk-file: + file.managed: + - name: {{ zabbix.agent2.config.TLSPSKFile }} + - user: {{ zabbix.agent2.user }} + - group: {{ zabbix.agent2.user }} + - contents: {{ zabbix.agent2.psk }} + - create: true + - watch_in: + - service: zabbix-agent2-service +{% endif %} + +zabbix-userparameters: + file.managed: + - name: /etc/zabbix/zabbix_agent2.d/user_parameters.conf + - source: salt://zabbix/templates/user_parameters.j2 + - user: {{ zabbix.agent2.user }} + - group: {{ zabbix.agent2.user }} + - mode: 0755 + - template: jinja + - watch_in: + - service: zabbix-agent2-service diff --git a/states/zabbix/agent2/init.sls b/states/zabbix/agent2/init.sls new file mode 100644 index 0000000..d3f46a7 --- /dev/null +++ b/states/zabbix/agent2/init.sls @@ -0,0 +1,6 @@ +--- +include: + - .install + - .config + - .scripts + - .service diff --git a/states/zabbix/agent2/install.sls b/states/zabbix/agent2/install.sls new file mode 100644 index 0000000..4e3f972 --- /dev/null +++ b/states/zabbix/agent2/install.sls @@ -0,0 +1,7 @@ +--- +{%- from "zabbix/map.jinja" import zabbix with context %} +zabbix-agent2-pkgs: + pkg.installed: + - pkgs: {{ zabbix.agent2.pkgs }} + - watch_in: + - service: zabbix-agent2-service diff --git a/states/zabbix/agent2/scripts.sls b/states/zabbix/agent2/scripts.sls new file mode 100644 index 0000000..94a219b --- /dev/null +++ b/states/zabbix/agent2/scripts.sls @@ -0,0 +1,21 @@ +--- +{%- from "zabbix/map.jinja" import zabbix with context %} +zabbix-script-dir: + file.directory: + - name: /etc/zabbix/scripts + - user: {{ zabbix.agent2.user }} + - group: {{ zabbix.agent2.group }} + - watch_in: + - service: zabbix-agent2-service + +{% for key, value in zabbix.agent2.scripts.items() -%} +zabbix-script-{{ key }}: + file.managed: + - name: /etc/zabbix/scripts/{{ value.name }} + - source: salt://zabbix/scripts/{{ value.name }} + - user: {{ zabbix.agent2.user }} + - group: {{ zabbix.agent2.group }} + - mode: 0755 + - watch_in: + - service: zabbix-agent2-service +{% endfor -%} diff --git a/states/zabbix/agent2/service.sls b/states/zabbix/agent2/service.sls new file mode 100644 index 0000000..c855c2c --- /dev/null +++ b/states/zabbix/agent2/service.sls @@ -0,0 +1,6 @@ +--- +{%- from "zabbix/map.jinja" import zabbix with context %} +zabbix-agent2-service: + service.running: + - name: zabbix-agent2 + - enable: true diff --git a/states/zabbix/defaults.yaml b/states/zabbix/defaults.yaml index c852436..970dd29 100644 --- a/states/zabbix/defaults.yaml +++ b/states/zabbix/defaults.yaml @@ -19,24 +19,24 @@ zabbix: PidFile: /run/zabbix/zabbix_server.pid StartDBSyncers: 1 CacheSize: 33554432 - agent: + agent2: enable: true user: zabbix group: zabbix pkgs: - python3-pyzabbix - - zabbix-agent + # - zabbix-agent - zabbix-agent2 # - zabbix-get # - zabbix-sender config: BufferSize: 10000 Hostname: localhost - Include: "/etc/zabbix/zabbix_agentd.conf.d/*.conf" - LogFile: /var/log/zabbix/zabbix_agentd.log + Include: "/etc/zabbix/zabbix_agent2.d/*.conf" + LogFile: /var/log/zabbix/zabbix_agent2.log LogFileSize: 0 LogType: file - PidFile: /var/run/zabbix/zabbix_agentd.pid + PidFile: /var/run/zabbix/zabbix_agent2.pid Server: 127.0.0.1 ServerActive: zabbix.paulbsd.com Timeout: 10 diff --git a/states/zabbix/init.sls b/states/zabbix/init.sls index 6537bd6..1e5630c 100644 --- a/states/zabbix/init.sls +++ b/states/zabbix/init.sls @@ -9,5 +9,11 @@ include: {% endif %} {% if zabbix.agent.enable %} - repo - - .agent + - .agent2 + +## for upgrade +zabbix-agent-service: + service.stopped: + - name: zabbix-agent + - enable: false {% endif %} diff --git a/states/zabbix/templates/zabbix_agent2.conf.j2 b/states/zabbix/templates/zabbix_agent2.conf.j2 new file mode 100644 index 0000000..0c30637 --- /dev/null +++ b/states/zabbix/templates/zabbix_agent2.conf.j2 @@ -0,0 +1,4 @@ +{%- from "zabbix/map.jinja" import zabbix with context -%} +{%- for key, value in zabbix.agent2.config.items() %} +{{ key }}={{ value }} +{%- endfor -%} \ No newline at end of file