From bb5ee5085f7f8724b74b3cd50ba274e009b71475 Mon Sep 17 00:00:00 2001 From: Peter Date: Mon, 14 Jul 2025 18:35:42 +0200 Subject: [PATCH] add new zabbix template so we can automatically add new checks --- roles/ppm/files/ppmzabbixagent | 12 ++++++++++++ roles/ppm/handlers/main.yml | 5 +++++ roles/ppm/tasks/main.yml | 3 +++ roles/ppm/tasks/zabbix.yml | 13 +++++++++++++ 4 files changed, 33 insertions(+) create mode 100644 roles/ppm/files/ppmzabbixagent create mode 100644 roles/ppm/tasks/zabbix.yml diff --git a/roles/ppm/files/ppmzabbixagent b/roles/ppm/files/ppmzabbixagent new file mode 100644 index 0000000..7f23a5d --- /dev/null +++ b/roles/ppm/files/ppmzabbixagent @@ -0,0 +1,12 @@ +# Zabbix agent config for ppm + +{%- set ns = namespace() -%} +{%- set ns.allchecks = [] -%} +{%- for app in otherapps -%} +{%- if "monitoring" in otherapps[app]["imports"] -%} +{%- for check in otherapps[app]["imports"]["monitoring"]["checks"] %} +{%- set ns.allchecks = ns.allchecks + [check | combine({'app':app})] -%} +{% endfor -%}{%- endif -%}{%- endfor %} + +UserParameter=ppm.discover,/bin/echo '{{ ns.allchecks | tojson }}' +UserParameter=ppm.app[*],/bin/bash -c 'echo $2 | nc -U {{ statedir }}/$1.monitoring' \ No newline at end of file diff --git a/roles/ppm/handlers/main.yml b/roles/ppm/handlers/main.yml index f64b418..4fe15f5 100644 --- a/roles/ppm/handlers/main.yml +++ b/roles/ppm/handlers/main.yml @@ -1,3 +1,8 @@ - name: Restart firewall ansible.builtin.command: /etc/network/if-pre-up.d/firewall changed_when: true + +- name: Restart zabbix-agent2 + ansible.builtin.service: + name: zabbix-agent2 + state: restarted diff --git a/roles/ppm/tasks/main.yml b/roles/ppm/tasks/main.yml index d8bf828..8a52276 100644 --- a/roles/ppm/tasks/main.yml +++ b/roles/ppm/tasks/main.yml @@ -11,3 +11,6 @@ - name: Arrange firewall ansible.builtin.import_tasks: firewall.yml + +- name: Arrange zabbix + ansible.builtin.import_tasks: zabbix.yml diff --git a/roles/ppm/tasks/zabbix.yml b/roles/ppm/tasks/zabbix.yml new file mode 100644 index 0000000..ad254bd --- /dev/null +++ b/roles/ppm/tasks/zabbix.yml @@ -0,0 +1,13 @@ +- name: Configure firewall options + ansible.builtin.copy: + dest: /home/.zabbixagenttemplate + group: root + owner: root + mode: "0755" + src: ppmzabbixagent + +- name: Render zabbix template + ansible.builtin.command: ppm template /home/.zabbixagenttemplate /etc/zabbix/zabbix_agent2.d/ppm.conf + register: zabbix_render + changed_when: "'content did not change' not in zabbix_render.stdout" + notify: Restart zabbix-agent2