[icinga-checkins] icinga.org: icinga2-migration/master: Fix icon_image, flapping, command import

git at icinga.org git at icinga.org
Tue Jun 10 23:10:31 CEST 2014


Module: icinga2-migration
Branch: master
Commit: af245eab90b5587d429caac709d1e2d05cc69efe
URL:    https://git.icinga.org/?p=icinga2-migration.git;a=commit;h=af245eab90b5587d429caac709d1e2d05cc69efe

Author: Michael Friedrich <michael.friedrich at gmail.com>
Date:   Tue Jun 10 22:47:27 2014 +0200

Fix icon_image, flapping, command import

---

 .../library/Conftool/Icinga2/Icinga2Host.php       |    3 +--
 .../Conftool/Icinga2/Icinga2ObjectDefinition.php   |   28 +++++++++++++++-----
 .../library/Conftool/Icinga2/Icinga2Service.php    |    3 +--
 3 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/modules/conftool/library/Conftool/Icinga2/Icinga2Host.php b/modules/conftool/library/Conftool/Icinga2/Icinga2Host.php
index 0ab0eed..f88ca97 100644
--- a/modules/conftool/library/Conftool/Icinga2/Icinga2Host.php
+++ b/modules/conftool/library/Conftool/Icinga2/Icinga2Host.php
@@ -12,7 +12,6 @@ class Icinga2Host extends Icinga2ObjectDefinition
 
     protected $v1AttributeMap = array(
         //keep
-        'icon_image' => 'icon_image',
         'icon_image_alt' => 'icon_image_alt',
         'max_check_attempts' => 'max_check_attempts',
         //rename
@@ -24,7 +23,7 @@ class Icinga2Host extends Icinga2ObjectDefinition
         'event_handler' => 'event_command',
         'low_flap_threshold' => 'flapping_threshold',
         'high_flap_threshold' => 'flapping_threshold',
-        'flap_detection_enabled' => 'enaple_flapping',
+        'flap_detection_enabled' => 'enable_flapping',
         'process_perf_data' => 'enable_perfdata',
         'notifications_enabled' => 'enable_notifications',
         'is_volatile' => 'volatile',
diff --git a/modules/conftool/library/Conftool/Icinga2/Icinga2ObjectDefinition.php b/modules/conftool/library/Conftool/Icinga2/Icinga2ObjectDefinition.php
index 370d8b2..e8997de 100644
--- a/modules/conftool/library/Conftool/Icinga2/Icinga2ObjectDefinition.php
+++ b/modules/conftool/library/Conftool/Icinga2/Icinga2ObjectDefinition.php
@@ -87,7 +87,7 @@ class Icinga2ObjectDefinition
             }
 
             //check command arguments
-            if ($key == "check_command" && ($object instanceof IcingaService || $object instanceof IcingaHost)) {
+            if ($key == "check_command") {
                 $command_arr = explode("!", $value);
 
                 $this->properties['check_command'] = "\"".$command_arr[0]."\""; //first is always the command name
@@ -95,7 +95,8 @@ class Icinga2ObjectDefinition
                 for($i = 1; $i < count($command_arr); $i++) {
                     $varname = "ARG".$i;
                     $varvalue = addslashes($command_arr[$i]); //escape the string 
-                    //TODO check against legacy macros and replace them
+                    //check against legacy macros and replace them
+		    $varvalue = $this->migrateLegacyMacros($varvalue);
                     $this->vars($varname, $varvalue);
                 }
                 continue;
@@ -182,6 +183,10 @@ class Icinga2ObjectDefinition
             $this->imports("legacy-timeperiod");
         }
 
+        if ($object->getDefinitionType() == "command") {
+            $this->imports("plugin-check-command");
+        }
+
         //custom vars
         foreach ($object->getCustomVars() as $key => $value) {
             $this->vars($key, $value);
@@ -229,6 +234,11 @@ class Icinga2ObjectDefinition
         $this->notes = "\"".$this->migrateLegacyMacros($value)."\"";
     }
 
+    protected function convertIcon_image($value)
+    {
+        $this->icon_image = "\"".$this->migrateLegacyMacros($value)."\"";
+    }
+
     protected function migrateUseImport($value, $key = null)
     {
         if ($key != "use") {
@@ -245,16 +255,20 @@ class Icinga2ObjectDefinition
         if ($key !== null && in_array($key, $this->v1ArrayProperties)) {
             $values = array();
             foreach ($this->splitComma($value) as $value) {
+                //additive is always enabled
+                if (substr($value, 0, 1) === '+') {
+                    $value = substr($value, 1);
+                } 
+		        //TODO: strip exclusions, but fix them somewhere later as blacklisted host
+                if (substr($value, 0, 1) === '!') {
+                    //$value = substr($value, 1);
+                    return;
+                } 
                 $values[] = $this->migrateValue($value);
             }
             return $values;
         }
 
-        //special handling for address
-        if ($key == "address") {
-            return $this->migrateLegacyString($value);
-        }
-        
         if (preg_match('/^\d+/', $value)) {
             return $value;
         }
diff --git a/modules/conftool/library/Conftool/Icinga2/Icinga2Service.php b/modules/conftool/library/Conftool/Icinga2/Icinga2Service.php
index 94b5bb6..2a43ab8 100644
--- a/modules/conftool/library/Conftool/Icinga2/Icinga2Service.php
+++ b/modules/conftool/library/Conftool/Icinga2/Icinga2Service.php
@@ -14,7 +14,6 @@ class Icinga2Service extends Icinga2ObjectDefinition
 
     protected $v1AttributeMap = array(
         //keep
-        'icon_image' => 'icon_image',
         'icon_image_alt' => 'icon_image_alt',
         'max_check_attempts' => 'max_check_attempts',
         //rename
@@ -26,7 +25,7 @@ class Icinga2Service extends Icinga2ObjectDefinition
         'event_handler' => 'event_command',
         'low_flap_threshold' => 'flapping_threshold',
         'high_flap_threshold' => 'flapping_threshold',
-        'flap_detection_enabled' => 'enaple_flapping',
+        'flap_detection_enabled' => 'enable_flapping',
         'process_perf_data' => 'enable_perfdata',
         'notifications_enabled' => 'enable_notifications',
         'is_volatile' => 'volatile',



More information about the icinga-checkins mailing list