[icinga-checkins] icinga.org: icingaweb2-module-director/feature/icinga-legacy-config-13049: doc/testing: fix syntax

git at icinga.org git at icinga.org
Fri Nov 11 10:44:01 CET 2016


Module: icingaweb2-module-director
Branch: feature/icinga-legacy-config-13049
Commit: eb1f1a2c33de48c38d33cc85d275887727225072
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=eb1f1a2c33de48c38d33cc85d275887727225072

Author: Thomas Gelf <thomas at gelf.net>
Date:   Thu Nov 10 20:03:29 2016 +0100

doc/testing: fix syntax

---

 doc/93-Testing.md                          |    3 -
 library/Director/Objects/IcingaFlatVar.php |   56 ++++++++++++++++++
 library/Director/Objects/IcingaVar.php     |   85 ++++++++++++++++++++++++++++
 3 files changed, 141 insertions(+), 3 deletions(-)

diff --git a/doc/93-Testing.md b/doc/93-Testing.md
index c12862b..31ce2e6 100644
--- a/doc/93-Testing.md
+++ b/doc/93-Testing.md
@@ -183,7 +183,6 @@ echo "VACUUM FREEZE" | su - postgres -c psql template1
 su - postgres -c 'createuser -a -d gitlab-runner'
 
 # Register the runner with your Gitlab installation
-```sh
 gitlab-ci-multi-runner register -n \
   -r "$REGISTRATION_TOKEN" \
   --executor shell \
@@ -210,7 +209,6 @@ DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -q -y \
 su - postgres -c 'createuser -a -d gitlab-runner'
 
 # Register the runner with your Gitlab installation
-```sh
 gitlab-ci-multi-runner register -n \
   -r "$REGISTRATION_TOKEN" \
   --executor shell \
@@ -243,7 +241,6 @@ mysql -e "UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE User='roo
 su - postgres -c 'createuser -a -d gitlab-runner'
 
 # Register the runner with your Gitlab installation
-```sh
 gitlab-ci-multi-runner register -n \
   -r "$REGISTRATION_TOKEN" \
   --executor shell \
diff --git a/library/Director/Objects/IcingaFlatVar.php b/library/Director/Objects/IcingaFlatVar.php
new file mode 100644
index 0000000..7a60508
--- /dev/null
+++ b/library/Director/Objects/IcingaFlatVar.php
@@ -0,0 +1,56 @@
+<?php
+
+namespace Icinga\Module\Director\Objects;
+
+use Icinga\Module\Director\CustomVariable\CustomVariable;
+use Icinga\Module\Director\Data\Db\DbObject;
+use Icinga\Module\Director\Db;
+
+class IcingaFlatVar extends DbObject
+{
+    protected $table = 'icinga_flat_var';
+
+    protected $keyName = array(
+        'checksum',
+        'flatname_checksum'
+    );
+
+    protected $defaultProperties = array(
+        'var_checksum'      => null,
+        'flatname_checksum' => null,
+        'flatname'          => null,
+        'flatvalue'         => null,
+    );
+
+    public static function generateForCustomVar(CustomVariable $var, Db $db)
+    {
+        $flatVars = static::forCustomVar($var, $db);
+        foreach ($flatVars as $flat) {
+            $flat->store();
+        }
+
+        return $flatVars;
+    }
+
+    public static function forCustomVar(CustomVariable $var, Db $db)
+    {
+        $flat = array();
+        $varSum = $var->checksum();
+        $var->flatten($flat, $var->getKey());
+        $flatVars = array();
+
+        foreach ($flat as $name => $value) {
+            $flatVar = static::create(array(
+                'var_checksum'      => $varSum,
+                'flatname_checksum' => sha1($name, true),
+                'flatname'          => $name,
+                'flatvalue'         => $value,
+            ), $db);
+
+            $flatVar->store();
+            $flatVars[] = $flatVar;
+        }
+
+        return $flatVars;
+    }
+}
diff --git a/library/Director/Objects/IcingaVar.php b/library/Director/Objects/IcingaVar.php
new file mode 100644
index 0000000..45bf4a3
--- /dev/null
+++ b/library/Director/Objects/IcingaVar.php
@@ -0,0 +1,85 @@
+<?php
+
+namespace Icinga\Module\Director\Objects;
+
+use Icinga\Module\Director\CustomVariable\CustomVariable;
+use Icinga\Module\Director\Data\Db\DbObject;
+use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
+use Icinga\Module\Director\Db;
+
+class IcingaVar extends DbObject
+{
+    protected $table = 'icinga_var';
+
+    protected $keyName = 'checksum';
+
+    /** @var CustomVariable */
+    protected $var;
+
+    protected $defaultProperties = array(
+        'checksum'          => null,
+        'rendered_checksum' => null,
+        'varname'           => null,
+        'varvalue'          => null,
+        'rendered'          => null
+    );
+
+    /**
+     * @param CustomVariable $var
+     * @param Db $db
+     *
+     * @return static
+     */
+    public static function forCustomVar(CustomVariable $customVar, Db $db)
+    {
+        $rendered = static::renderVar($customVar);
+
+        $var = static::create(array(
+            'checksum'          => $customVar->checksum(),
+            'rendered_checksum' => sha1($rendered, true),
+            'varname'           => $customVar->getKey(),
+            'varvalue'          => $customVar->toJson(),
+            'rendered'          => $rendered,
+        ), $db);
+
+        $var->var = $customVar;
+
+        return $var;
+    }
+
+    protected static function renderVar(CustomVariable $var)
+    {
+        $renderExpressions = false; // TODO!
+        return c::renderKeyValue(
+            static::renderKeyName($var->getKey()),
+            $var->toConfigStringPrefetchable($renderExpressions)
+        );
+    }
+
+    protected static function renderKeyName($key)
+    {
+        if (preg_match('/^[a-z0-9_]+\d*$/i', $key)) {
+            return 'vars.' . c::escapeIfReserved($key);
+        } else {
+            return 'vars[' . c::renderString($key) . ']';
+        }
+    }
+
+    /**
+     * @param CustomVariable $var
+     * @param Db $db
+     *
+     * @return static
+     */
+    public static function generateForCustomVar(CustomVariable $customVar, Db $db)
+    {
+        $var = static::forCustomVar($customVar, $db);
+        $var->store();
+        return $var;
+    }
+
+    protected function onInsert()
+    {
+        IcingaFlatVar::generateForCustomVar($this->var, $this->getConnection());
+    }
+}



More information about the icinga-checkins mailing list