[icinga-checkins] icinga.org: icinga-core/mfriedrich/ido: core issue #2918: fixed processing of "all" services

git at icinga.org git at icinga.org
Wed Oct 3 01:14:53 CEST 2012


Module: icinga-core
Branch: mfriedrich/ido
Commit: e02d8c5c3e71bc2779ed4b0784d36dfd734e47ad
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=e02d8c5c3e71bc2779ed4b0784d36dfd734e47ad

Author: Wolfgang <wnd at gmx.net>
Date:   Mon Sep 24 22:27:20 2012 +0200

core issue #2918: fixed processing of "all" services

---

 contrib/downtimes/sched_down.pl |   47 +++++++++++++++++++++++---------------
 1 files changed, 28 insertions(+), 19 deletions(-)

diff --git a/contrib/downtimes/sched_down.pl b/contrib/downtimes/sched_down.pl
old mode 100644
new mode 100755
index 89b441b..ba31002
--- a/contrib/downtimes/sched_down.pl
+++ b/contrib/downtimes/sched_down.pl
@@ -33,6 +33,7 @@
 # 2012.03.22:  0.08 bugfix: set author/comment if blank
 #                   enable no blank before opening brace (2nd try)
 # 2012.07.13:  0.09 bugfix: fix exit from procedure
+# 2012.09.24:  0.10 bugfix: fix "all" services
 
 use strict;
 use Getopt::Long qw(:config no_ignore_case bundling);
@@ -51,7 +52,7 @@ EOT
 #
 
 my $creator = "2012 Icinga Team";
-my $version = "0.09";
+my $version = "0.10";
 my $script  = "sched_down.pl";
 
 my $cFile = "/usr/local/icinga/etc/icinga.cfg";
@@ -116,7 +117,10 @@ if ($examine) {
 } else {
 	read_config_file ($cFile,1);
  	%cDowntimes = read_status_file ($sFile,2);
-	(%hg,%sg) = read_object_file ($oFile,3);
+	my ($ref_hg, $ref_sg) = read_object_file ($oFile,3);
+	%hg = %$ref_hg;
+	%sg = %$ref_sg;
+#	(%hg,%sg) = read_object_file ($oFile,3);
 	@sDowntimes = read_downtimes ($dFile,4);
 }
 plan_downtimes ();
@@ -283,6 +287,9 @@ sub read_object_file {
 # services per host
 			if ($tmp->{object} =~ /service$/) {
 				my %t = %srv;
+				if (exists ($sObject {"$tmp->{host_name}"})) {
+					%t = (%t, %{$sObject {"$tmp->{host_name}"}});
+				}
 				$sObject {"$tmp->{host_name}"} = \%t;
 			}
 			$tmp = init_entry2 ();
@@ -290,7 +297,7 @@ sub read_object_file {
 			next;
 		}
 		my ($obj,$val) = /(.*?)\s+(.*)/;
-		next unless (defined $val);
+		next unless (defined $val);	# skip if value is empty
 		if ($obj =~ /(.+)group_name/) {
 			$tmp->{type} = $1;
 			$tmp->{name} = $val;
@@ -308,7 +315,7 @@ sub read_object_file {
 	for my $key (sort keys %sGroup) {
 		info (2,"SG $key ($sGroup{$key}{alias}): $sGroup{$key}{members}");
 	}
-	return (%hGroup, %sGroup);
+	return (\%hGroup, \%sGroup);
 }
 
 #
@@ -431,7 +438,7 @@ sub plan_downtimes {
 						info (2, "object $h does not exist");
 						next;
 					}
-				} else  {
+				} elsif ($s ne "all")  {
 					unless (exists ($sObject{"$h;$s"})) {
 						info (2, "object $h;$s does not exist");
 						next;
@@ -500,6 +507,8 @@ sub plan_downtimes {
 							info (1,"Rejected: ==> already planned $key:".localtime($dt->{start_ts})." to ".localtime($dt->{end_ts})." for $duration mins");
 							next;
 						}
+						my $diff = $dt->{end_ts} - $dt->{start_ts};
+						$f = ($diff == ($duration*60)) ? 1 : 0;
 						my $data = "$dt->{start_ts};$dt->{end_ts};$f;$t;".($duration*60).";$a;$c";
 						next if (set_cmd(\@cmd,$dt,$key,$data,$hg,$sg,$h,$s,$c,$p,$duration));
 	
@@ -848,21 +857,21 @@ sub set_cmd {
 	info (1, "possibly on: ".localtime($dt->{start_ts})." to ".localtime($dt->{end_ts})." for $duration mins");
 	if ("$h;$s" =~ /;$/) {	# no service_description
 		if ($hg) {	# host_groups defined
-			my @member = split (/,/,$hg{$hg}->{members});
+			my @member = split (/,/,$hg{$h}->{members});
 			return 1 if (already_planned (\@member,"HG",1,$key,$key2,$duration));
-			$extcmd = "SCHEDULE_HOSTGROUP_HOST_DOWNTIME;$hg;$data";
+			$extcmd = "SCHEDULE_HOSTGROUP_HOST_DOWNTIME;$h;$data";
 			push @$cmd, $extcmd;
-			$pDowntimes{"$hg;;$dt->{start_ts};$dt->{end_ts}"} = $extcmd;
+			$pDowntimes{"$h;;$dt->{start_ts};$dt->{end_ts}"} = $extcmd;
 		} elsif ($sg) {
-			my @mem = split (/,/,$sg{$sg}->{members});
+			my @mem = split (/,/,$sg{$h}->{members});
 			my @member = ();
 			for (my $idx = 0; $idx <= $#mem; $idx+=2) {
 				push @member, $mem[$idx];
 			}
 			return 1 if (already_planned (\@member,"SG",2,$key,$key2,$duration));
-			$extcmd = "SCHEDULE_SERVICEGROUP_HOST_DOWNTIME;$sg;$data";
+			$extcmd = "SCHEDULE_SERVICEGROUP_HOST_DOWNTIME;$h;$data";
 			push @$cmd, $extcmd;
-			$pDowntimes{"$sg;;$dt->{start_ts};$dt->{end_ts}"} = $extcmd;
+			$pDowntimes{"$h;;$dt->{start_ts};$dt->{end_ts}"} = $extcmd;
 		} else {			# host_name defined
 			if (exists($cDowntimes{"$h;;$dt->{start_ts};$dt->{end_ts}"})) {
 				info (1, "Rejected: ==> already planned $key");
@@ -878,11 +887,11 @@ sub set_cmd {
 		}
 	} else {					# service_description defined
 		if ($hg) {			# hostgroups defined
-			my @member = split (/,/,$hg{$hg}->{members});
+			my @member = split (/,/,$hg{$h}->{members});
 			my $cnt = 0;
 			if ($s =~ /^all$/i) {
 				for my $idx (0..$#member) {
-					my %srv = $sObject{$member[$idx]};
+					my %srv = %{$sObject{$member[$idx]}};
 					foreach my $idy (keys %srv) {
 						$cnt++ if (exists($cDowntimes{"$member[$idx];$srv{$idy};$dt->{start_ts};$dt->{end_ts}"}));
 					}
@@ -891,9 +900,9 @@ sub set_cmd {
 					info (1,"Rejected: ==> already planned HGs $key:".localtime($dt->{start_ts})." to ".localtime($dt->{end_ts})." for $duration mins");
 					return 1;
 				}
-				$extcmd = "SCHEDULE_HOSTGROUP_SVC_DOWNTIME;$hg;$data";
+				$extcmd = "SCHEDULE_HOSTGROUP_SVC_DOWNTIME;$h;$data";
 				push @$cmd, $extcmd;
-				$pDowntimes{"$hg;;$dt->{start_ts};$dt->{end_ts}"} = $extcmd;
+				$pDowntimes{"$h;;$dt->{start_ts};$dt->{end_ts}"} = $extcmd;
 			} else { # one or more services defined
 				next if (already_planned (\@member,"HG",1,$key,$key2,$duration));
 				for my $idx (0..$#member) {
@@ -906,12 +915,12 @@ sub set_cmd {
 				return 1;
 			}
 		} elsif ($sg) {	# servicegroups defined
-			my @member = split (/,/,$sg{$sg}->{members});
+			my @member = split (/,/,$sg{$h}->{members});
 			if ($s =~ /^all$/i) {
 				return 1 if (already_planned (\@member,"SG",2,$key,$key2,$duration));
-				$extcmd = "SCHEDULE_SERVICEGROUP_SVC_DOWNTIME;$hg;$data";
+				$extcmd = "SCHEDULE_SERVICEGROUP_SVC_DOWNTIME;$h;$data";
 				push @$cmd, $extcmd;
-				$pDowntimes{"$sg;;$dt->{start_ts};$dt->{end_ts}"} = $extcmd;
+				$pDowntimes{"$h;;$dt->{start_ts};$dt->{end_ts}"} = $extcmd;
 			} else {
 				return 1 if (already_planned (\@member,"SG",2,$key,$key2,$duration));
 				for my $idx (0..$#member) {
@@ -924,7 +933,7 @@ sub set_cmd {
 			}
 		} else {				# host_name defined
 			if ($s =~ /^all$/i) {
-				my %srv = $sObject{$h};
+				my %srv = %{$sObject{$h}};
 				my $cnt = 0;
 				foreach my $idy (keys %srv) {
 					$cnt++ if (exists($cDowntimes{"$h;$srv{$idy};$dt->{start_ts};$dt->{end_ts}"}));





More information about the icinga-checkins mailing list