From 5c6f7085fae796301a730b5900104e766ed577e2 Mon Sep 17 00:00:00 2001
From: Eric Zillmann <zillmann@arocom.de>
Date: Tue, 26 May 2020 16:13:40 +0200
Subject: [PATCH] #2838 added filtering of cronjobs by host

---
 .../config/crontabs_collector.php.jinja2      | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/templates/scripts/config/crontabs_collector.php.jinja2 b/templates/scripts/config/crontabs_collector.php.jinja2
index b7e3a32..7f194fb 100755
--- a/templates/scripts/config/crontabs_collector.php.jinja2
+++ b/templates/scripts/config/crontabs_collector.php.jinja2
@@ -38,6 +38,25 @@ foreach ($input_files as $input_file) {
     continue;
   }
 
+  // Make sure to only use cronjobs for this host.
+  $host = gethostname();
+
+  foreach ($input_file_decoded as $key => $cronjob) {
+    // Make sure we have a valid entry.
+    if (!is_array($cronjob) || !isset($cronjob['host'])) {
+      continue;
+    }
+
+    // Remove non matching entries.
+    if ($host && $cronjob['host'] !== $host) {
+      unset($input_file_decoded[$key]);
+      continue;
+    }
+
+    // Remove the "host" key as this is not a valid cron key.
+    unset($input_file_decoded[$key]['host']);
+  }
+
   // Merge the decoded file contents to the result.
   $crontab_definitions = array_merge($crontab_definitions, $input_file_decoded);
 }
-- 
GitLab