From 90a9121a3c5eedc521895e696fe85b4b463b16eb Mon Sep 17 00:00:00 2001
From: Tunui Franken <tfranken@easter-eggs.com>
Date: Wed, 26 Mar 2025 18:32:02 +0100
Subject: [PATCH] Add check_local_unread_emails

---
 playbooks/icinga2.yml                                    | 9 +++++++++
 .../templates/zones.d/global-templates/commands.conf.j2  | 4 ++++
 .../templates/zones.d/master/services/common.conf.j2     | 7 +++++++
 3 files changed, 20 insertions(+)

diff --git a/playbooks/icinga2.yml b/playbooks/icinga2.yml
index 8ee4e42..f0082fd 100644
--- a/playbooks/icinga2.yml
+++ b/playbooks/icinga2.yml
@@ -26,6 +26,15 @@
         group: root
         mode: 0440
         validate: 'visudo -cf %s'
+    - name: Copy check_local_unread_emails script
+      become: true
+      ansible.builtin.get_url:
+        url: "https://gitlab.easter-eggs.com/brenard/check_local_unread_emails/-/raw/master/check_local_unread_emails"
+        checksum: "sha256:1b8a10ab32255b56a405bc43d391b1545b052181f2be964ae08828d05da4690e"
+        dest: /usr/lib/nagios/plugins/check_local_unread_emails
+        owner: root
+        group: root
+        mode: 0755
 
 - name: Setup Icinga2 master
   gather_facts: true
diff --git a/roles/icinga2_master/templates/zones.d/global-templates/commands.conf.j2 b/roles/icinga2_master/templates/zones.d/global-templates/commands.conf.j2
index 13e7765..0c0e458 100644
--- a/roles/icinga2_master/templates/zones.d/global-templates/commands.conf.j2
+++ b/roles/icinga2_master/templates/zones.d/global-templates/commands.conf.j2
@@ -76,3 +76,7 @@ object CheckCommand "memory" {
     vars.memory_output_g = false
     vars.memory_vmstats = false
 }
+
+object CheckCommand "local_unread_emails" {
+    command = [ PluginDir + "/check_local_unread_emails" ]
+}
diff --git a/roles/icinga2_master/templates/zones.d/master/services/common.conf.j2 b/roles/icinga2_master/templates/zones.d/master/services/common.conf.j2
index 4d631c1..b90fae1 100644
--- a/roles/icinga2_master/templates/zones.d/master/services/common.conf.j2
+++ b/roles/icinga2_master/templates/zones.d/master/services/common.conf.j2
@@ -114,3 +114,10 @@ apply Service for (device => config in host.vars.smart_devices) {
     assign where true
     vars += config
 }
+
+apply Service "local_unread_emails" {
+    import "generic-service"
+    check_command = "local_unread_emails"
+    command_endpoint = host.name
+    assign where true
+}