]> granicus.if.org Git - icinga2/commitdiff
Config Conversion: Allow to define external global templates referenced by all objects.
authorMichael Friedrich <michael.friedrich@netways.de>
Wed, 18 Sep 2013 09:39:38 +0000 (11:39 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Wed, 18 Sep 2013 09:42:16 +0000 (11:42 +0200)
tests:

$ ./icinga2_convert_v1_v2.pl -c /etc/icinga/icinga.cfg -o conf/
--hosttmpl="hostbumstitmpl"
--servicetmpl="servicebumstitmpl"
--usertmpl="userbumstitmpl"
--timeperiodtmpl="timeperiodbumstitmpl"
--notificationtmpl="notificationbumstitmpl"
--checkcommandtmpl="checkcommandbumstitmpl"
--eventcommandtmpl="eventcommandbumstitmpl"
--notificationcommandtmpl="notificationcommandbumstitmpl"

refs #4697

tools/configconvert/Icinga2/Convert.pm
tools/configconvert/Icinga2/Utils.pm
tools/configconvert/icinga2_convert_v1_v2.pl

index baa8afa0e7ab80fb21b974aaadc43c73e390f3c7..05a63dd4eff5c889bf184fde814117588da22e54 100644 (file)
@@ -30,7 +30,7 @@ use File::Find;
 use Storable qw(dclone);
 
 use feature 'say';
-our $dbg_lvl = 1;
+our $dbg_lvl;
 
 ################################################################################
 ## Validation
@@ -2846,7 +2846,32 @@ sub convert_2x {
     }
 
     ############################################################################
+    # add custom templates to every existing object
     ############################################################################
+    my @objects = ('host', 'service', 'user', 'notification', 'timeperiod', 'command');
+
+    foreach my $object (@objects) {
+        Icinga2::Utils::debug("Custom template for $object");
+        #say "Custom template for $object";
+
+        foreach my $obj_2x_key (keys %{@$cfg_obj_2x{$object}}) {
+            my $obj_2x = @$cfg_obj_2x{$object}->{$obj_2x_key};
+
+            my $obj_template = "$object-template";
+            if (defined($obj_2x->{'__I2CONVERT_COMMAND_TYPE'})) {
+                $obj_template = lc $obj_2x->{'__I2CONVERT_COMMAND_TYPE'} . "$object-template";
+            }
+
+            if(defined($icinga2_cfg->{'customtmpl'}->{$obj_template}) && $icinga2_cfg->{'customtmpl'}->{$obj_template} ne "") {
+                if (!defined($cfg_obj_2x->{$object}->{$obj_2x_key}->{'__I2CONVERT_TEMPLATE_NAMES'})) {
+                    @{$cfg_obj_2x->{$object}->{$obj_2x_key}->{'__I2CONVERT_TEMPLATE_NAMES'}} = ();
+                }
+                push @{$cfg_obj_2x->{$object}->{$obj_2x_key}->{'__I2CONVERT_TEMPLATE_NAMES'}}, $icinga2_cfg->{'customtmpl'}->{$obj_template};
+                $cfg_obj_2x->{$object}->{$obj_2x_key}->{'__I2CONVERT_USES_TEMPLATE'} = 1;
+            }
+        }
+    }
+
     # export takes place outside again
 
     return $cfg_obj_2x;
index 6f432721b17273c652fe7ef060633582ac7823f7..557b2b5e03e290e44a4d48e5b48394601a22b384 100644 (file)
@@ -26,7 +26,7 @@ package Icinga2::Utils;
 use strict;
 #use Icinga2;
 
-our $dbg_lvl = 1;
+our $dbg_lvl;
 
 ################################################################################
 # HELPER FUNCTIONS
index 701937c18d7cbbe3f0c05e91be5d2124f79ac0fd..df97553b2385565f70d6cf82b8590ad5c79608d0 100755 (executable)
@@ -83,18 +83,28 @@ my $version = "0.0.1";
 # get command-line parameters
 our $opt;
 GetOptions(
-    "c|icingacfgfile=s" => \$opt->{icinga1xcfg},
-    "o|outputcfgdir=s"  => \$opt->{icinga2xoutputprefix},
-    "v|verbose"         => \$opt->{verbose},
-    "h|help"            => \$opt->{help},
-    "V|version"         => \$opt->{version}
+    "c|icingacfgfile=s"         => \$opt->{icinga1xcfg},
+    "o|outputcfgdir=s"          => \$opt->{icinga2xoutputprefix},
+    "hosttmpl=s"                => \$opt->{hosttmpl},
+    "servicetmpl=s"             => \$opt->{servicetmpl},
+    "usertmpl=s"                => \$opt->{usertmpl},
+    "notificationtmpl=s"        => \$opt->{notificationtmpl},
+    "timeperiodtmpl=s"          => \$opt->{timeperiodtmpl},
+    "checkcommandtmpl=s"        => \$opt->{checkcommandtmpl},
+    "notificationcommandtmpl=s" => \$opt->{notificationcommandtmpl},
+    "eventcommandtmpl=s"        => \$opt->{eventcommandtmpl},
+    "tmpl=s"                    => \$opt->{tmpl},
+    "tmpl=s"                    => \$opt->{tmpl},
+    "v|verbose"                 => \$opt->{verbose},
+    "h|help"                    => \$opt->{help},
+    "V|version"                 => \$opt->{version}
 );
 
 my $icinga1_cfg;
 my $icinga2_cfg = {};
 my $conf_prefix = "./conf";
-my $verbose = 1;
-our $dbg_lvl = 1;
+my $verbose = 0;
+our $dbg_lvl = 0;
 $icinga2_cfg->{'__I2EXPORT_DEBUG'} = 0;
 
 if(defined($opt->{icinga1xcfg})) {
@@ -106,6 +116,7 @@ if(defined($opt->{icinga2xoutputprefix})) {
 if(defined($opt->{verbose})) {
     $verbose = $opt->{verbose};
     $icinga2_cfg->{'__I2EXPORT_DEBUG'} = 1;
+    $dbg_lvl = 1;
 }
 
 if (defined $opt->{version}) { print $version."\n"; exit 0; }
@@ -130,6 +141,40 @@ $icinga2_cfg->{'itl'}->{'checkcommand-template'} = "plugin-check-command";
 $icinga2_cfg->{'itl'}->{'notificationcommand-template'} = "plugin-notification-command";
 $icinga2_cfg->{'itl'}->{'eventcommand-template'} = "plugin-event-command";
 
+if (defined($opt->{hosttmpl})) {
+    $icinga2_cfg->{'customtmpl'}->{'host-template'} = $opt->{hosttmpl};
+    print "Custom host template: '" . $icinga2_cfg->{'customtmpl'}->{'host-template'} . "'\n";
+}
+if (defined($opt->{servicetmpl})) {
+    $icinga2_cfg->{'customtmpl'}->{'service-template'} = $opt->{servicetmpl};
+    print "Custom service template: '" . $icinga2_cfg->{'customtmpl'}->{'service-template'} . "'\n";
+}
+if (defined($opt->{usertmpl})) {
+    $icinga2_cfg->{'customtmpl'}->{'user-template'} = $opt->{usertmpl};
+    print "Custom user template: '" . $icinga2_cfg->{'customtmpl'}->{'user-template'} . "'\n";
+}
+if (defined($opt->{notificationtmpl})) {
+    $icinga2_cfg->{'customtmpl'}->{'notification-template'} = $opt->{notificationtmpl};
+    print "Custom notification template: '" . $icinga2_cfg->{'customtmpl'}->{'notification-template'} . "'\n";
+}
+if (defined($opt->{timeperiodtmpl})) {
+    $icinga2_cfg->{'customtmpl'}->{'timeperiod-template'} = $opt->{timeperiodtmpl};
+    print "Custom timeperiod template: '" . $icinga2_cfg->{'customtmpl'}->{'timeperiod-template'} . "'\n";
+}
+if (defined($opt->{checkcommandtmpl})) {
+    $icinga2_cfg->{'customtmpl'}->{'checkcommand-template'} = $opt->{checkcommandtmpl};
+    print "Custom checkcommand template: '" . $icinga2_cfg->{'customtmpl'}->{'checkcommand-template'} . "'\n";
+}
+if (defined($opt->{notificationcommandtmpl})) {
+    $icinga2_cfg->{'customtmpl'}->{'notificationcommand-template'} = $opt->{notificationcommandtmpl};
+    print "Custom notificationcommand template: '" . $icinga2_cfg->{'customtmpl'}->{'notificationcommand-template'} . "'\n";
+}
+if (defined($opt->{eventcommandtmpl})) {
+    $icinga2_cfg->{'customtmpl'}->{'eventcommand-template'} = $opt->{eventcommandtmpl};
+    print "Custom eventcommand template: '" . $icinga2_cfg->{'customtmpl'}->{'eventcommand-template'} . "'\n";
+}
+
+
 
 my $type_cnt;