[icinga-checkins] icinga.org: icingaweb2-module-director/master: Db/Housekeeping: prepare centralized housekeeping

git at icinga.org git at icinga.org
Sat Feb 27 13:00:51 CET 2016


Module: icingaweb2-module-director
Branch: master
Commit: 86f8830bcf077b8b5eff68db8ecf0ea1951ae4c4
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=86f8830bcf077b8b5eff68db8ecf0ea1951ae4c4

Author: Thomas Gelf <thomas at gelf.net>
Date:   Sat Feb 27 12:55:37 2016 +0100

Db/Housekeeping: prepare centralized housekeeping

---

 library/Director/Db/Housekeeping.php           |   74 ++++++++++++++++++++++++
 library/Director/IcingaConfig/IcingaConfig.php |    5 --
 2 files changed, 74 insertions(+), 5 deletions(-)

diff --git a/library/Director/Db/Housekeeping.php b/library/Director/Db/Housekeeping.php
new file mode 100644
index 0000000..43fbafa
--- /dev/null
+++ b/library/Director/Db/Housekeeping.php
@@ -0,0 +1,74 @@
+<?php
+
+namespace Icinga\Module\Director\Db;
+
+use Icinga\Module\Director\Db;
+
+class Housekeeping
+{
+    /**
+     * @var Db
+     */
+    protected $connection;
+
+    /**
+     * @var \Zend_Db_Adapter_Abstract
+     */
+    protected $db;
+
+    /**
+     * @var int
+     */
+    protected $version;
+
+    public function __construct(Db $connection)
+    {
+        $this->connection = $connection;
+        $this->db = $connection->getDbAdapter();
+    }
+
+    public function getTaskSummary()
+    {
+        return array(
+            'oldUndeployedConfigs' => array(
+                'title' => N_('Undeployed configurations'),
+                'count' => $this->countOldUndeployedConfigs()
+            ),
+            'unusedFiles' => array(
+                'title' => N_('Unused rendered files'),
+                'count' => $this->countUnusedFiles()
+            )
+        );
+    }
+
+    public function getPendingTasks()
+    {
+    }
+
+    public function countOldUndeployedConfigs()
+    {
+        $sql = 'SELECT COUNT(*) FROM director_generated_config c'
+             . ' LEFT JOIN director_deployment_log d ON c.checksum = d.config_checksum'
+             . ' WHERE d.config_checksum IS NULL';
+
+        return $this->db->fetchOne($sql);
+    }
+
+    public function countUnusedFiles()
+    {
+        $sql = 'SELECT COUNT(*) FROM director_generated_file f'
+             . ' LEFT JOIN director_generated_config_file cf ON f.checksum = cf.file_checksum'
+             . ' WHERE cf.file_checksum IS NULL';
+
+        return $this->db->fetchOne($sql);
+    }
+
+    public function wipeUnusedFiles()
+    {
+        $sql = 'DELETE f FROM director_generated_file f'
+             . ' LEFT JOIN director_generated_config_file cf ON f.checksum = cf.file_checksum'
+             . ' WHERE cf.file_checksum IS NULL';
+
+        return $this->db->exec($sql);
+    }
+}
diff --git a/library/Director/IcingaConfig/IcingaConfig.php b/library/Director/IcingaConfig/IcingaConfig.php
index 5658518..3460855 100644
--- a/library/Director/IcingaConfig/IcingaConfig.php
+++ b/library/Director/IcingaConfig/IcingaConfig.php
@@ -568,9 +568,4 @@ class IcingaConfig
 
         return $this->lastActivityChecksum;
     }
-
-    // TODO: wipe unused files
-    // DELETE f FROM director_generated_file f
-    // LEFT JOIN director_generated_config_file cf ON f.checksum = cf.file_checksum
-    // WHERE cf.file_checksum IS NULL;
 }



More information about the icinga-checkins mailing list