[icinga-checkins] icinga.org: icingaweb2-module-director/feature/template-resolver-12969: Templateresolver: playground, mostly for benchmarks

git at icinga.org git at icinga.org
Tue Oct 25 00:05:36 CEST 2016


Module: icingaweb2-module-director
Branch: feature/template-resolver-12969
Commit: 31758a3df3ab2d037aa227d8df695feda79616ee
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=31758a3df3ab2d037aa227d8df695feda79616ee

Author: Thomas Gelf <thomas at gelf.net>
Date:   Mon Oct 24 21:19:23 2016 +0000

Templateresolver: playground, mostly for benchmarks

---

 .../clicommands/TemplateresolverCommand.php        |   14 ++++++
 library/Director/Objects/IcingaObject.php          |   46 ++++++++++++++++++++
 2 files changed, 60 insertions(+)

diff --git a/application/clicommands/TemplateresolverCommand.php b/application/clicommands/TemplateresolverCommand.php
new file mode 100644
index 0000000..2c27b07
--- /dev/null
+++ b/application/clicommands/TemplateresolverCommand.php
@@ -0,0 +1,14 @@
+<?php
+
+namespace Icinga\Module\Director\Clicommands;
+
+use Icinga\Module\Director\Cli\Command;
+use Icinga\Module\Director\Objects\IcingaHost;
+
+class TemplateresolverCommand extends Command
+{
+    public function testAction()
+    {
+        IcingaHost::fetchAllFullyResolved($this->db());
+    }
+}
diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php
index 6d1a7cb..6ccc88c 100644
--- a/library/Director/Objects/IcingaObject.php
+++ b/library/Director/Objects/IcingaObject.php
@@ -1076,6 +1076,52 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
         return $vals;
     }
 
+    public static function fetchAllFullyResolved(Db $db)
+    {
+        PrefetchCache::initialize($db);
+        $all = static::prefetchAll($db);
+        IcingaZone::prefetchAll($db);
+        IcingaCommand::prefetchAll($db);
+        // $filter = Filter::fromQueryString('object_name=WELO*&vars.location=*');
+        $filter = Filter::fromQueryString('object_name=WELO*&vars.psc_dashboard');
+        echo $filter . "\n";
+        $matches = array();
+        $dba = $db->getDbAdapter();
+
+        $dba->beginTransaction();
+
+        foreach ($all as $host) {
+            $db->insert('icinga_host_resolved', (array) $host->getResolvedProperties());
+            continue;
+            $clone = IcingaHost::fromPlainObject($host->toPlainObject(true));
+            $clone->table = 'icinga_host_resolved';
+            $clone->vars = null;
+            $clone->groups = null;
+            $clone->id = $host->id;
+            $clone->setConnection($db)->insertIntoDb();
+            continue;
+            if ($host->matches($filter)) {
+                $matches[] = $host;
+            }
+
+            // $host->toPlainObject(true);
+            if (isset($host->vars()->location)) {
+            // printf("%s: %s\n", $host->object_name, $host->vars()->location->getValue());
+            } else {
+            // printf("%s HAS NO LOCATION\n", $host->object_name);
+            }
+        }
+
+        $dba->commit();
+
+
+        foreach ($matches as $host) {
+            printf("%s: %s (match)\n", $host->object_name, $host->vars()->location->getValue());
+        }
+
+        printf("%d hosts loaded\n", count($all));
+    }
+
     public function matches(Filter $filter)
     {
         // TODO: speed up by passing only desired properties (filter columns) to



More information about the icinga-checkins mailing list