[icinga-checkins] icinga.org: icinga2/mfriedrich/config: ConfigConvert: basic servicegroup parsing method
git at icinga.org
git at icinga.org
Mon Apr 8 11:20:15 CEST 2013
Module: icinga2
Branch: mfriedrich/config
Commit: 858e58a1886a999d15e0495845af9d82409658ea
URL: https://git.icinga.org/?p=icinga2.git;a=commit;h=858e58a1886a999d15e0495845af9d82409658ea
Author: Michael Friedrich <michael.friedrich at netways.de>
Date: Thu Apr 4 22:11:10 2013 +0200
ConfigConvert: basic servicegroup parsing method
---
contrib/configconvert/Icinga2/Convert.pm | 26 +++++++++++++++++++-------
1 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/contrib/configconvert/Icinga2/Convert.pm b/contrib/configconvert/Icinga2/Convert.pm
index 39ab440..170ed77 100644
--- a/contrib/configconvert/Icinga2/Convert.pm
+++ b/contrib/configconvert/Icinga2/Convert.pm
@@ -493,8 +493,9 @@ sub convert_2x {
##########################################
# servicegroups
##########################################
+ delete($cfg_obj_2x->{'service'}->{$service_obj_1x_key}->{'servicegroups'});
+
if(defined($obj_1x_service->{'servicegroups'})) {
- delete($cfg_obj_2x->{'service'}->{$service_obj_1x_key}->{'servicegroups'});
# convert comma seperated list to array
push @{$cfg_obj_2x->{'service'}->{$service_obj_1x_key}->{'servicegroups'}}, sort (map { s/^\s+//; s/\s+$//; $_ } split (/,/, $obj_1x_service->{'servicegroups'}) );
#print "DEBUG: servicegroups " . join (" ", @{$cfg_obj_2x->{'service'}->{$service_obj_1x_key}->{'servicegroups'}});
@@ -629,8 +630,9 @@ sub convert_2x {
##########################################
# hostgroups
##########################################
+ delete($cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'hostgroups'});
+
if(defined($obj_1x_host->{'hostgroups'})) {
- delete($cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'hostgroups'});
# convert comma seperated list to array
push @{$cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'hostgroups'}}, sort (map { s/^\s+//; s/\s+$//; $_ } split (/,/, $obj_1x_host->{'hostgroups'}) );
#print "DEBUG: hostgroups " . join (" ", @{$cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'hostgroups'}});
@@ -827,12 +829,22 @@ sub convert_2x {
# check if there are members defined, we must re-link them in their service object again
if(defined($obj_1x_servicegroup->{'members'})) {
+
+ # host1,svc1,host2,svc2 is just an insane way of parsing stuff
my @sg_members = sort (map { s/^\s+//; s/\s+$//; $_ } split (/,/, $obj_1x_servicegroup->{'members'}) );
- #foreach my $hg_member (@sg_members) { # XXX host1,svc1,host2,svc2 is just an insane way of parsing stuff
- # my $obj_2x_hg_member = obj_get_service_obj_by_host_name_service_description($cfg_obj_2x, 'FIXMEHOST', 'FIXMESVC');
- # #print "DEBUG: $hg_member found.\n";
- # push @{$obj_2x_hg_member->{'hostgroups'}}, $obj_1x_hostgroup->{'hostgroup_name'};
- #}
+ # just some safety for debugging
+ if(@sg_members % 2 != 0) {
+ print "DEBUG: servicegroup $obj_1x_servicegroup->{'servicegroup_name'} members list not even: $obj_1x_servicegroup->{'members'} \n";
+ }
+
+ while (scalar(@sg_members) > 0) {
+ my $sg_member_host = shift(@sg_members);
+ my $sg_member_service = shift(@sg_members);
+ my $obj_2x_sg_member = obj_get_service_obj_by_host_name_service_description($cfg_obj_2x, $sg_member_host, $sg_member_service);
+
+ print "DEBUG: $sg_member_host,$sg_member_service found.\n";
+ push @{$obj_2x_sg_member->{'servicegroups'}}, $obj_1x_servicegroup->{'servicegroup_name'};
+ }
}
}
More information about the icinga-checkins
mailing list