[icinga-checkins] icinga.org: icinga2/feature/configconvert-2743: configconvert: final stage, rework notification type handling, fix naming amd template output

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


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

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

configconvert: final stage, rework notification type handling, fix naming amd template output

the config dump must take care of which notification type is dumped,
otherwise there would be yet another look required. Instead we are just
passing a reference from users to hosts/services with all prepared
notification attributes, and check them lazy on dump then.

further fixe on the notification names - they are not unique by their
command (now used on host/service scope, not user/contact) so we'll add
some magic number as suffix.

fixed template name dumping due to changed conversion vars too.

refs #4008

---

 contrib/configconvert/Icinga2/Convert.pm          |   20 +++++++++++++++-----
 contrib/configconvert/Icinga2/ExportIcinga2Cfg.pm |   11 ++++++++++-
 2 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/contrib/configconvert/Icinga2/Convert.pm b/contrib/configconvert/Icinga2/Convert.pm
index 96a9265..5eb9b78 100644
--- a/contrib/configconvert/Icinga2/Convert.pm
+++ b/contrib/configconvert/Icinga2/Convert.pm
@@ -1303,6 +1303,7 @@ sub convert_2x {
     #       host/service->notifications[type]->notification_templates,users
     ######################################
     my $notification_obj_cnt = 0;
+    my $obj_notification_cnt = 0;
     # add a dummy value so that we can check against it
     $cfg_obj_2x->{'notification'}->{$notification_obj_cnt}->{'__I2CONVERT_NOTIFICATION_NAME'} = '__I2CONVERT_NOTIFICATION_DUMMY';
 
@@ -1325,16 +1326,23 @@ sub convert_2x {
 
                 my $notification_command_name_2x = $notification_command_type."-".$notification_command_name;
 
+                my $notification_name_2x = $notification_command_name_2x.$obj_notification_cnt;
+                $obj_notification_cnt++;
+
                 # save a relation to this user and which notification templates are now linked ( ["name"] = { templates = "template" } )
                 # we'll use that later on when processing hosts/services and linking to users and notifications
-                $user_notification->{$notification_command_name_2x}->{'name'} = $notification_command_name;
-                push @{$user_notification->{$notification_command_name_2x}->{'templates'}}, $notification_command_name_2x;
-                push @{$user_notification->{$notification_command_name_2x}->{'users'}}, $obj_2x_user->{'user_name'};
+                $user_notification->{$notification_name_2x}->{'name'} = $notification_name_2x;
+                
+                push @{$user_notification->{$notification_name_2x}->{'templates'}}, $notification_command_name_2x;
+                push @{$user_notification->{$notification_name_2x}->{'users'}}, $obj_2x_user->{'user_name'};
+
+                # save the type for later objects (host or service)
+                $user_notification->{$notification_name_2x}->{'type'} = $notification_command_type;
 
-                # do not add duplicate notifications, they must remain unique by their notification_command origin!
+                # XXX do not add duplicate notifications, they must remain unique by their notification_command origin!
                 next if (obj_2x_notification_exists($cfg_obj_2x, $notification_command_name_2x) == 1);
 
-                $cfg_obj_2x->{'notification'}->{$notification_obj_cnt}->{'__I2CONVERT_NOTIFICATION_NAME'} = $notification_command_name_2x; 
+                $cfg_obj_2x->{'notification'}->{$notification_obj_cnt}->{'__I2CONVERT_NOTIFICATION_TEMPLATE_NAME'} = $notification_command_name_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
 
@@ -1372,6 +1380,7 @@ sub convert_2x {
         foreach my $uniq_user (@uniq_users) {
             my $obj_2x_user = obj_get_user_obj_by_user_name($cfg_obj_2x, $uniq_user);
             push @{$cfg_obj_2x->{'host'}->{$host_obj_2x_key}->{'__I2CONVERT_NOTIFICATIONS'}}, $obj_2x_user->{'__I2CONVERT_NOTIFICATIONS'};
+            # we'll add a reference to all notifications here. decide on dump which object type is given, and dump only those notifications!
         }
         #say Dumper($obj_2x_service);
 
@@ -1402,6 +1411,7 @@ sub convert_2x {
         foreach my $uniq_user (@uniq_users) {
             my $obj_2x_user = obj_get_user_obj_by_user_name($cfg_obj_2x, $uniq_user);
             push @{$cfg_obj_2x->{'service'}->{$service_obj_2x_key}->{'__I2CONVERT_NOTIFICATIONS'}}, $obj_2x_user->{'__I2CONVERT_NOTIFICATIONS'};      
+            # we'll add a reference to all notifications here. decide on dump which object type is given, and dump only those notifications!
         }
         #say Dumper($obj_2x_service);
 
diff --git a/contrib/configconvert/Icinga2/ExportIcinga2Cfg.pm b/contrib/configconvert/Icinga2/ExportIcinga2Cfg.pm
index 767da9d..3099d50 100644
--- a/contrib/configconvert/Icinga2/ExportIcinga2Cfg.pm
+++ b/contrib/configconvert/Icinga2/ExportIcinga2Cfg.pm
@@ -134,6 +134,9 @@ sub dump_service_2x {
                 my $service_notification = $service_notification_hash->{$service_notification_key};
                 #say Dumper($service_notification);
 
+                # skip everything not related to service notifications
+                next if ($service_notification->{'type'} ne 'service');
+
                 dump_config_line($icinga2_cfg, "\t\tnotifications[\"$service_notification->{'name'}\"] = {");
 
                 if (defined ($service_notification->{'templates'}) && @{$service_notification->{'templates'}} > 0) {
@@ -261,6 +264,9 @@ sub dump_host_2x {
                 my $host_notification = $host_notification_hash->{$host_notification_key};
                 #say Dumper($host_notification);
 
+                # skip everything not related to host notifications
+                next if ($host_notification->{'type'} ne 'host');
+
                 dump_config_line($icinga2_cfg, "\t\tnotifications[\"$host_notification->{'name'}\"] = {");
 
                 if (defined ($host_notification->{'templates'}) && @{$host_notification->{'templates'}} > 0) {
@@ -391,6 +397,9 @@ sub dump_host_2x {
                     my $service_notification = $service_notification_hash->{$service_notification_key};
                     #say Dumper($service_notification);
 
+                    # skip everything not related to service notifications
+                    next if ($service_notification->{'type'} ne 'service');
+
                     dump_config_line($icinga2_cfg, "\t\tnotifications[\"$service_notification->{'name'}\"] = {");
 
                     if (defined ($service_notification->{'templates'}) && @{$service_notification->{'templates'}} > 0) {
@@ -494,7 +503,7 @@ sub dump_notification_2x {
     # XXX
     if ($notification_2x->{__I2CONVERT_IS_TEMPLATE} == 1) {
         $object_type = "template";
-        $notification_name = $notification_2x->{'__I2CONVERT_TEMPLATE_NAME'};
+        $notification_name = $notification_2x->{'__I2CONVERT_NOTIFICATION_TEMPLATE_NAME'};
     }
 
     # if this is a _template_ we need to use 'name' instead of 'host_name'





More information about the icinga-checkins mailing list