[icinga-checkins] icinga.org: icinga2/feature/configconvert-2743: configconvert: replace colon in object names with underscore

git at icinga.org git at icinga.org
Tue May 28 18:49:29 CEST 2013


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

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Tue May 28 18:48:30 2013 +0200

configconvert: replace colon in object names with underscore

it's a special delimiter and therefore forbidden.

fixes #4225

---

 contrib/configconvert/Icinga2/ImportIcinga1Cfg.pm |   12 ++++++++++++
 contrib/configconvert/Icinga2/Utils.pm            |   13 +++++++++++--
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/contrib/configconvert/Icinga2/ImportIcinga1Cfg.pm b/contrib/configconvert/Icinga2/ImportIcinga1Cfg.pm
index ec4db81..ba67375 100644
--- a/contrib/configconvert/Icinga2/ImportIcinga1Cfg.pm
+++ b/contrib/configconvert/Icinga2/ImportIcinga1Cfg.pm
@@ -189,6 +189,18 @@ sub parse_icinga1_object_cfg {
             #Icinga2::Utils::debug("val: $val");
             #Icinga2::Utils::debug("\n");
 
+            # strip illegal object name characters, replace with _
+            if ( ($attr =~ /name/ && $attr !~ /display_name/) || 
+                    $attr =~ /description/ ||
+                    $attr =~ /contact/ ||
+                    $attr =~ /groups/ ||
+                    $attr =~ /members/ ||
+                    $attr =~ /use/ || 
+                    $attr =~ /parents/
+                ) {
+                $val = Icinga2::Utils::strip_object_name($val);
+            }
+
             $cfg_obj->{$type}->{$cfg_obj->{'type_cnt'}->{$type}}->{$attr} = $val;
 
             # ignore duplicated attributes, last one wins
diff --git a/contrib/configconvert/Icinga2/Utils.pm b/contrib/configconvert/Icinga2/Utils.pm
index 47c7281..ea32512 100644
--- a/contrib/configconvert/Icinga2/Utils.pm
+++ b/contrib/configconvert/Icinga2/Utils.pm
@@ -91,8 +91,6 @@ sub uniq {
     return keys %{{ map { $_ => 1 } @_ }};
 }
 
-1;
-
 sub str2arr_by_delim_without_excludes {
     my $str = shift;
     my $delim = shift;
@@ -111,5 +109,16 @@ sub str2arr_by_delim_without_excludes {
     return @arr;
 }
 
+sub strip_object_name {
+    my $obj_str = shift;
+
+    #$obj_str =~ s/[`~!\\\$%\^&\*|'"<>\?,\(\)=:]/_/g;
+    $obj_str =~ s/[:]/_/g;
+
+    return $obj_str;
+}
+
+1;
+
 __END__
 # vi: sw=4 ts=4 expandtab :





More information about the icinga-checkins mailing list