[icinga-checkins] icinga.org: icinga2/feature/configconvert-2743: configconvert: add ITL templates automatically (for services, notifications)

git at icinga.org git at icinga.org
Thu May 2 22:17:33 CEST 2013


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

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Thu May  2 21:31:28 2013 +0200

configconvert: add ITL templates automatically (for services, notifications)

this currently only makes sense for services and notifications.

refs #4037

---

 contrib/configconvert/Icinga2/Convert.pm          |   11 +++++++++++
 contrib/configconvert/Icinga2/ExportIcinga2Cfg.pm |    2 +-
 contrib/configconvert/icinga2_convert_v1_v2.pl    |    7 ++++++-
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/contrib/configconvert/Icinga2/Convert.pm b/contrib/configconvert/Icinga2/Convert.pm
index ca50f5b..5fd9dc3 100644
--- a/contrib/configconvert/Icinga2/Convert.pm
+++ b/contrib/configconvert/Icinga2/Convert.pm
@@ -600,6 +600,7 @@ sub convert_2x {
 # check_command => command_name => define command == command in service
 
     # hashref is selectable by type first
+    my $icinga2_cfg = shift;
     my $cfg_obj_1x = shift;
     my $cfg_obj_cache_1x = shift;
     my $user_macros_1x = shift;
@@ -646,6 +647,11 @@ sub convert_2x {
         
         push @{$obj_1x_service->{'__I2CONVERT_TEMPLATE_NAMES'}}, @service_templates;
 
+        # add dependency to ITL template to objects
+        if ($obj_1x_service->{'__I2CONVERT_IS_TEMPLATE'} == 0) {
+            push @{$obj_1x_service->{'__I2CONVERT_TEMPLATE_NAMES'}}, $icinga2_cfg->{'itl'}->{'service-template'};
+            $obj_1x_service->{'__I2CONVERT_USES_TEMPLATE'} = 1;
+        }
 
         ####################################################
         # get related host_name/service_description
@@ -1347,6 +1353,11 @@ sub convert_2x {
                 $cfg_obj_2x->{'notification'}->{$notification_obj_cnt}->{'__I2CONVERT_NOTIFICATION_COMMAND'} = $notification_command_line;
                 $cfg_obj_2x->{'notification'}->{$notification_obj_cnt}->{'__I2CONVERT_IS_TEMPLATE'} = 1; # this is a template, used in hosts/services then
 
+                # add dependency to ITL template to objects
+                @{$cfg_obj_2x->{'notification'}->{$notification_obj_cnt}->{'__I2CONVERT_TEMPLATE_NAMES'}} = ();
+                push @{$cfg_obj_2x->{'notification'}->{$notification_obj_cnt}->{'__I2CONVERT_TEMPLATE_NAMES'}}, $icinga2_cfg->{'itl'}->{'notification-template'};
+                $cfg_obj_2x->{'notification'}->{$notification_obj_cnt}->{'__I2CONVERT_USES_TEMPLATE'} = 1; # we now use a template, otherwise it won't be dumped
+
                 $notification_obj_cnt++;
             }
         }
diff --git a/contrib/configconvert/Icinga2/ExportIcinga2Cfg.pm b/contrib/configconvert/Icinga2/ExportIcinga2Cfg.pm
index 1b2ec5f..7bd38ec 100644
--- a/contrib/configconvert/Icinga2/ExportIcinga2Cfg.pm
+++ b/contrib/configconvert/Icinga2/ExportIcinga2Cfg.pm
@@ -667,7 +667,7 @@ sub dump_notification_2x {
     my $object_type = "object"; # object or template
     my $notification_name = $notification_2x->{'__I2CONVERT_NOTIFICATION_NAME'}; # default, may be changed for templates
 
-    #say Dumper($user_2x);
+    say Dumper($notification_2x);
     # XXX
     if ($notification_2x->{__I2CONVERT_IS_TEMPLATE} == 1) {
         $object_type = "template";
diff --git a/contrib/configconvert/icinga2_convert_v1_v2.pl b/contrib/configconvert/icinga2_convert_v1_v2.pl
index af58509..a375f9b 100644
--- a/contrib/configconvert/icinga2_convert_v1_v2.pl
+++ b/contrib/configconvert/icinga2_convert_v1_v2.pl
@@ -49,6 +49,11 @@ $icinga2_cfg->{'groups'}= "$conf_prefix/icinga2-groups.conf";
 $icinga2_cfg->{'notifications'}= "$conf_prefix/icinga2-notifications.conf";
 $icinga2_cfg->{'timeperiods'}= "$conf_prefix/icinga2-timeperiods.conf";
 
+$icinga2_cfg->{'itl'}->{'host-template'} = "";
+$icinga2_cfg->{'itl'}->{'service-template'} = "plugin-service";
+$icinga2_cfg->{'itl'}->{'user-template'} = "";
+$icinga2_cfg->{'itl'}->{'notification-template'} = "plugin-notification";
+$icinga2_cfg->{'itl'}->{'timeperiod-template'} = "";
 
 
 my $verbose = 1;
@@ -72,7 +77,7 @@ my $icinga1_cfg_obj_cache = Icinga2::ImportIcinga1Cfg::parse_icinga1_objects_cac
 my $icinga1_user_macros = Icinga2::ImportIcinga1Cfg::parse_icinga1_user_macros($icinga1_cfg);
 
 # the conversion magic inside
-my $icinga2_cfg_obj = Icinga2::Convert::convert_2x($icinga1_cfg_obj, $icinga1_cfg_obj_cache, $icinga1_user_macros);
+my $icinga2_cfg_obj = Icinga2::Convert::convert_2x($icinga2_cfg, $icinga1_cfg_obj, $icinga1_cfg_obj_cache, $icinga1_user_macros);
 
 # the export
 Icinga2::ExportIcinga2Cfg::dump_cfg_obj_2x($icinga2_cfg, $icinga2_cfg_obj);





More information about the icinga-checkins mailing list