[icinga-checkins] icinga.org: icinga2/feature/configconvert-2743: configconvert: fix import parser - timeperiods require regex (thx LConfImport)

git at icinga.org git at icinga.org
Thu May 2 22:45:07 CEST 2013


Module: icinga2
Branch: feature/configconvert-2743
Commit: d1d3fb561d0f3bb96179059141fc64e4c53227ac
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=d1d3fb561d0f3bb96179059141fc64e4c53227ac

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Thu May  2 22:43:18 2013 +0200

configconvert: fix import parser - timeperiods require regex (thx LConfImport)

somehow, the Icinga2 import still fails with us holiday definitions. bug
that's not yet determined whose bug that is.

refs #4039
refs #4013

---

 contrib/configconvert/Icinga2/ImportIcinga1Cfg.pm |   22 ++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)

diff --git a/contrib/configconvert/Icinga2/ImportIcinga1Cfg.pm b/contrib/configconvert/Icinga2/ImportIcinga1Cfg.pm
index 378787c..ec4db81 100644
--- a/contrib/configconvert/Icinga2/ImportIcinga1Cfg.pm
+++ b/contrib/configconvert/Icinga2/ImportIcinga1Cfg.pm
@@ -105,6 +105,7 @@ sub parse_icinga1_object_cfg {
 
     my $obj = {}; #hashref
     my $in_define = 0;
+    my $in_timeperiod = 0;
     my $type;
     my $append; # this is a special case where multiple lines are appended with \ - not sure if we support THAT.
     my $inline_comment;
@@ -141,6 +142,11 @@ sub parse_icinga1_object_cfg {
         elsif ($line =~ /define\s+(\w+)\s*{?(.*)$/) {
             $type = $1;
             $append = $2;
+            if ($type eq "timeperiod") {
+                $in_timeperiod = 1;
+            } else {
+                $in_timeperiod = 0;
+            }
 
             # save the type
             $cfg_obj->{$type}->{$cfg_obj->{'type_cnt'}->{$type}}->{'__I2CONVERT_TYPE'} = $type;
@@ -158,7 +164,21 @@ sub parse_icinga1_object_cfg {
             $inline_comment = $1;
 
             # then split it and save it by type->cnt->attr->val
-            ($attr, $val) = split (/\s+/, $line, 2); # important - only split into 2 elements 
+            #($attr, $val) = split (/\s+/, $line, 2); # important - only split into 2 elements 
+
+            # timeperiods require special parser
+            if ($in_timeperiod == 1) {
+                if ($line =~ /timeperiod_name/ || $line =~ /alias/ || $line =~ /exclude/) {
+                    $line =~ m/([\w]+)\s*(.*)/;
+                    $attr = Icinga2::Utils::strip($1); $val = Icinga2::Utils::strip($2);
+                } else {
+                    $line =~ m/(.*)\s+([\d\W]+)/;
+                    $attr = Icinga2::Utils::strip($1); $val = Icinga2::Utils::strip($2);
+                }
+            } else {
+                    $line =~ m/([\w]+)\s*(.*)/;
+                    $attr = Icinga2::Utils::strip($1); $val = Icinga2::Utils::strip($2);
+            }
             # ignore empty values
             next if (!defined($val));
             next if ($val eq "");





More information about the icinga-checkins mailing list