From 7acca7e92b3b9a8ddca9ea41c0239d0a16628f2a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Th=C3=A9o=20-=20Le=20Filament?= <theo@le-filament.com>
Date: Thu, 2 Mar 2023 17:32:24 +0100
Subject: [PATCH] fix: notification for host checks and backup check every
 morning

---
 templates/templates.cfg.j2   | 20 +++++++++++++++-----
 templates/timeperiods.cfg.j2 | 12 ++++++++++++
 templates/vps.cfg.j2         |  6 +++---
 3 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/templates/templates.cfg.j2 b/templates/templates.cfg.j2
index ca7dbf6..a02929a 100644
--- a/templates/templates.cfg.j2
+++ b/templates/templates.cfg.j2
@@ -26,12 +26,12 @@
 
 define contact{
         name                            generic-contact         ; The name of this contact template
-        service_notification_period     heures-ouvres           ; service notifications can be sent anytime during working hours
-        host_notification_period        heures-ouvres           ; host notifications can be sent anytime during working hours
-        service_notification_options    w,u,c,r,f,s             ; send notifications for all service states, flapping events, and scheduled downtime events
+        host_notification_period        24x7                    ; host notifications can be sent anytime
         host_notification_options       d,u,r,f,s               ; send notifications for all host states, flapping events, and scheduled downtime events
-        service_notification_commands   notify-service-by-email ; send service notifications via email
         host_notification_commands      notify-host-by-email    ; send host notifications via email
+        service_notification_period     24x7                    ; service notifications can be sent anytime
+        service_notification_options    w,u,c,r,f,s             ; send notifications for all service states, flapping events, and scheduled downtime events
+        service_notification_commands   notify-service-by-email ; send service notifications via email
         register                        0                       ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!
         }
 
@@ -64,6 +64,7 @@ define host{
         check_interval                  10              ; Actively check the host every 10 minutes
         retry_interval                  2               ; Schedule host check retries at 2 minute intervals
         max_check_attempts              3               ; Check each host 3 times (max)
+        contact_groups                  admins          ; Notifications get sent out to everyone in the 'admins' group
         register                        0               ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
         }
 
@@ -199,7 +200,8 @@ define service{
         name                            daily-service
         use                             generic-service
         max_check_attempts              2
-        check_interval                  1440
+        check_period                    morning
+        check_interval                  120
         retry_interval                  5
         notification_interval           1440
         register                        0
@@ -217,6 +219,14 @@ define service{
         register                        0
         }
 
+# Everytine notification service.
+define service{
+        name                            everytime-notification
+        use                             generic-service
+        notification_period             24x7
+        register                        0
+        }
+
 # Graph service definition template - This is NOT a real service, just a template!
 
 define service {
diff --git a/templates/timeperiods.cfg.j2 b/templates/timeperiods.cfg.j2
index c8c0d58..90265ac 100644
--- a/templates/timeperiods.cfg.j2
+++ b/templates/timeperiods.cfg.j2
@@ -75,3 +75,15 @@ define timeperiod{
         }
 
 
+# Morning, before people start to work.
+define timeperiod{
+        timeperiod_name morning
+        alias           Morning
+        sunday          07:00-08:00
+        monday          07:00-08:00
+        tuesday         07:00-08:00
+        wednesday       07:00-08:00
+        thursday        07:00-08:00
+        friday          07:00-08:00
+        saturday        07:00-08:00
+        }
diff --git a/templates/vps.cfg.j2 b/templates/vps.cfg.j2
index 774fec6..bb5ffb2 100644
--- a/templates/vps.cfg.j2
+++ b/templates/vps.cfg.j2
@@ -106,21 +106,21 @@ define service{
 {% endif %}
 {% endfor %}
 define service{
-        use                             daily-service
+        use                             daily-service,everytime-notification
         host_name                       {{ groups['backup_server'] | map('extract', hostvars, ['inventory_hostname']) | sort | join(',') }}
         service_description             Backup Odoo Dockers
         check_command                   check_nrpe!check_odoo_storage
         }
 
 define service{
-        use                             daily-service
+        use                             daily-service,everytime-notification
         host_name                       {{ groups['backup_server'] | map('extract', hostvars, ['inventory_hostname']) | sort | join(',') }}
         service_description             Backup2 Odoo Dockers
         check_command                   check_nrpe!check_odoo2_storage
         }
 
 define service{
-        use                             daily-service,graphed-service
+        use                             daily-service,everytime-notification,graphed-service
         host_name                       {{ groups['backup_server'] | map('extract', hostvars, ['inventory_hostname']) | sort | join(',') }}
         service_description             Backup Cloud Files
         check_command                   check_nrpe!check_cloud_storage
-- 
GitLab