[icinga-checkins] icinga.org: icinga-core/master: Added test for testing status. cgi with a large number of comments and downtime

git at icinga.org git at icinga.org
Sat Jan 9 21:58:16 CET 2010


Module: icinga-core
Branch: master
Commit: 5acac5ac4dc3fea82ea2d5a1932b3d55591e3199
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=5acac5ac4dc3fea82ea2d5a1932b3d55591e3199

Author: Ton Voon <ton.voon at opsera.com>
Date:   Thu Dec 31 11:49:31 2009 +0000

Added test for testing status.cgi with a large number of comments and downtime

---

 t/.cvsignore                           |    2 +-
 t/.gitignore                           |    2 +-
 t/660status-downtimes-comments.t       |   42 +++++++++++++++++++
 t/bin/generate_downtimes               |   71 ++++++++++++++++++++++++++++++++
 t/var/.cvsignore                       |    1 +
 t/var/.gitignore                       |    3 +
 6 files changed, 119 insertions(+), 2 deletions(-)

diff --git a/t/.cvsignore b/t/.cvsignore
index ee23d4d..47c79bd 100644
--- a/t/.cvsignore
+++ b/t/.cvsignore
@@ -1,3 +1,3 @@
 var/objects.precache
 var/objects.precache.generated
-
+Makefile
diff --git a/t/.gitignore b/t/.gitignore
index ee23d4d..47c79bd 100644
--- a/t/.gitignore
+++ b/t/.gitignore
@@ -1,3 +1,3 @@
 var/objects.precache
 var/objects.precache.generated
-
+Makefile
diff --git a/t/660status-downtimes-comments.t b/t/660status-downtimes-comments.t
new file mode 100644
index 0000000..5593f56
--- /dev/null
+++ b/t/660status-downtimes-comments.t
@@ -0,0 +1,42 @@
+#!/usr/bin/perl
+#
+# Checks for status.cgi, with large number of comments and downtimes
+
+use warnings;
+use strict;
+use Test::More;
+
+use FindBin qw($Bin);
+
+chdir $Bin or die "Cannot chdir";
+
+my $topdir = "$Bin/..";
+my $cgi_dir = "$topdir/cgi";
+my $status_cgi = "$cgi_dir/status.cgi";
+my $status_dat = "$Bin/var/status.dat";
+my $generated = "$Bin/var/status-generated.dat";
+my $generator = "$Bin/bin/generate_downtimes";
+
+my $output;
+my $expected;
+
+
+my $iteration = 1;
+my $iterations_max = 5;
+my $copies;
+
+plan tests => 3 * $iterations_max;
+
+while($iteration <= $iterations_max) {
+	$copies = (10)**($iteration);
+	is( system("cat $status_dat > $generated"), 0, "New status.dat file" );
+	is( system("$generator $copies >> $generated"), 0, "Generated $copies downtimes");
+	my $num_comments = $copies + 1;
+
+	my $start = time;
+	$output = `NAGIOS_CGI_CONFIG=etc/cgi-with-generated-status.cfg REQUEST_METHOD=GET REMOTE_USER=icingaadmin QUERY_STRING="host=host1" $status_cgi`;
+	my $duration = time-$start;
+	like( $output, "/This service has $num_comments comments associated with it/", "Found $num_comments comments in HTML output from status.dat. Took $duration seconds" );
+	$iteration++;
+}
+
diff --git a/t/bin/generate_downtimes b/t/bin/generate_downtimes
new file mode 100755
index 0000000..429f2c1
--- /dev/null
+++ b/t/bin/generate_downtimes
@@ -0,0 +1,71 @@
+#!/usr/bin/perl
+# Prints to stdout lots of host and service downtimes
+
+use warnings;
+use strict;
+
+my $max_iterations = shift @ARGV || 1000;
+
+my $hostname = "host1";
+my $servicename = "Dummy service";
+
+my $downtime_id = 2596;
+my $starttime = 9000000000;
+my $downtime_template = <<EOF;
+servicecomment {
+    host_name=$hostname
+    service_description=$servicename
+    entry_type=1
+    comment_id=%DOWNTIMEID%
+    source=1
+    persistent=1
+    entry_time=1262254781
+    expires=0
+    expire_time=0
+    author=Nagios Admin
+    comment_data=Test Comment
+    }
+
+hostdowntime {
+    host_name=$hostname
+    downtime_id=%DOWNTIMEID1%
+    entry_time=1262254781
+    start_time=%STARTTIME%
+    end_time=%ENDTIME%
+    triggered_by=0
+    fixed=1
+    duration=7200
+    author=nagiosadmin
+    comment=Future host downtime
+    }
+
+servicedowntime {
+    host_name=$hostname
+    service_description=$servicename
+    downtime_id=%DOWNTIMEID2%
+    entry_time=1262254781
+    start_time=%STARTTIME%
+    end_time=%ENDTIME%
+    triggered_by=0
+    fixed=1
+    duration=7200
+    author=nagiosadmin
+    comment=Future service downtime
+    }
+
+EOF
+
+for(my $i=0; $i < $max_iterations; $i++ ) {
+	my $downtime = $downtime_template;
+	$downtime =~ s/%DOWNTIMEID1%/$downtime_id/g;
+	$downtime_id++;
+	$downtime =~ s/%DOWNTIMEID2%/$downtime_id/g;
+	$downtime_id++;
+
+	my $endtime = $starttime + 7200;
+	$downtime =~ s/%STARTTIME%/$starttime/g;
+	$downtime =~ s/%ENDTIME%/$endtime/g;
+	$starttime += 60;
+
+	print $downtime;
+}
diff --git a/t/etc/cgi-with-generated-status.cfg b/t/etc/cgi-with-generated-status.cfg
new file mode 100644
index 0000000..e69de29
diff --git a/t/etc/nagios-with-generated-status.cfg b/t/etc/nagios-with-generated-status.cfg
new file mode 100644
index 0000000..e69de29
diff --git a/t/var/.cvsignore b/t/var/.cvsignore
index fe6535e..1ee2d5b 100644
--- a/t/var/.cvsignore
+++ b/t/var/.cvsignore
@@ -1,2 +1,3 @@
 objects.precache
 objects.precache.generated
+status-generated.dat
diff --git a/t/var/.gitignore b/t/var/.gitignore
new file mode 100644
index 0000000..1ee2d5b
--- /dev/null
+++ b/t/var/.gitignore
@@ -0,0 +1,3 @@
+objects.precache
+objects.precache.generated
+status-generated.dat





More information about the icinga-checkins mailing list