Permalink
Browse files

fixed performance data for nagios report type

  • Loading branch information...
1 parent 1862e85 commit da354607b6e7f4843bdce504553a274ac352b2fa @sni committed May 31, 2011
View
@@ -10,6 +10,7 @@ Release History:
Version 1.68 - Tue May 31 14:25:35 CEST 2011
- add warning if parsed result does not match
- made overwriting default options in check_webinject possible
+ - fixed performance data for nagios report type
Version 1.67 - Thu Apr 28 16:52:29 CEST 2011
- make parsed respones available in the errormessage
View
@@ -1124,7 +1124,7 @@ sub _parseresponse {
## use critic
else {
push @{$case->{'messages'}}, {'key' => $type.'-success', 'value' => 'false', 'html' => "<span class=\"fail\">Failed Parseresult, cannot find $leftboundary(.*?)$rightboundary</span>" };
- $self->_out("Failed Parseresult, cannot find $leftboundary(.*?)$rightboundary\n");
+ $self->_out("Failed Parseresult, cannot find $leftboundary(*)$rightboundary\n");
$self->{'result'}->{'iswarning'} = 1;
}
@@ -1540,15 +1540,23 @@ sub _finaltasks {
if(defined $self->{'config'}->{globaltimeout}) {
$crit = $self->{'config'}->{globaltimeout};
}
+ my $lastid = 0;
my $perfdata = '|time='.$self->{'result'}->{'totalruntime'}.';0;'.$crit.';0;0';
for my $file (@{$self->{'result'}->{'files'}}) {
for my $case (@{$file->{'cases'}}) {
- my $warn = $case->{'warning'} || 0;
- my $crit = $case->{'critical'} || 0;
- my $label = $case->{'label'} || 'case'.$case->{'id'};
+ my $warn = $case->{'warning'} || 0;
+ my $crit = $case->{'critical'} || 0;
+ my $label = $case->{'label'} || 'case'.$case->{'id'};
$perfdata .= ' '.$label.'='.$case->{'latency'}.';'.$warn.';'.$crit.';0;0';
+ $lastid = $case->{'id'};
}
}
+ # report performance data for missed cases too
+ for my $nr (1..($self->{'result'}->{'casecount'} - $self->{'result'}->{'totalruncount'})) {
+ $lastid++;
+ my $label = 'case'.$lastid;
+ $perfdata .= ' '.$label.'=0;0;0;0;0';
+ }
my $rc;
if($self->{'result'}->{'iscritical'}) {
@@ -1570,6 +1578,7 @@ sub _finaltasks {
if($self->{'result'}->{'iscritical'} or $self->{'result'}->{'iswarning'}) {
print $self->{'out'};
}
+ $self->{'result'}->{'perfdata'} = $perfdata;
return $rc;
}
@@ -77,7 +77,7 @@ sub test_case_config {
my $webinject = Webinject->new();
$webinject->{'config'}->{'baseurl'} = 'http://localhost:58080';
my $rc = $webinject->engine();
- is($rc, 0, '07-config_options.xml - return code');
+ is($rc, 1, '07-config_options.xml - return code');
my $firstcase = $webinject->{'result'}->{'files'}->[0]->{'cases'}->[0];
delete $firstcase->{'messages'};
delete $firstcase->{'latency'};
@@ -0,0 +1,64 @@
+#!/usr/bin/env perl
+
+##################################################
+
+use strict;
+use Test::More;
+use Data::Dumper;
+use FindBin qw($Bin);
+use lib 't';
+
+
+if($ENV{TEST_AUTHOR}) {
+ eval "use HTTP::Server::Simple::CGI";
+ if($@) {
+ plan skip_all => 'HTTP::Server::Simple::CGI required';
+ }
+ else{
+ plan tests => 6;
+ }
+}
+else{
+ plan skip_all => 'Author test. Set $ENV{TEST_AUTHOR} to a true value to run.';
+}
+
+
+use_ok('Webinject');
+
+my $webinject = Webinject->new();
+isa_ok($webinject, "Webinject", 'Object is a Webinject');
+
+require TestWebServer;
+TestWebServer->start_webserver();
+
+##################################################
+# start our test cases
+test_case_01();
+test_case_02();
+
+
+##################################################
+# SUBs
+##################################################
+
+##################################################
+# Test File 01
+sub test_case_01 {
+ @ARGV = ('-r', 'nagios', $Bin."/data/30-nagios_perf_data.xml");
+ my $webinject = Webinject->new();
+ $webinject->{'config'}->{'baseurl'} = 'http://localhost:58080';
+ my $rc = $webinject->engine();
+ is($rc, 2, '30-nagios_perf_data.xml - return code');
+ like($webinject->{'result'}->{'perfdata'}, '/time=([\d\.]+);0;0;0;0 case1=([\d\.]+);0;0;0;0 case2=([\d\.]+);0;0;0;0 testlabel=([\d\.]+);0;0;0;0 case4=([\d\.]+);0;0;0;0/', 'performance data');
+}
+
+##################################################
+# Test File 02
+sub test_case_02 {
+ @ARGV = ('-r', 'nagios', '-s', 'break_on_errors=1', $Bin."/data/30-nagios_perf_data.xml");
+ my $webinject = Webinject->new();
+ $webinject->{'config'}->{'baseurl'} = 'http://localhost:58080';
+ my $rc = $webinject->engine();
+ is($rc, 2, '30-nagios_perf_data.xml - return code');
+ like($webinject->{'result'}->{'perfdata'}, '/time=([\d\.]+);0;0;0;0 case1=([\d\.]+);0;0;0;0 case2=0;0;0;0;0 case3=0;0;0;0;0 case4=0;0;0;0;0/', 'performance data');
+}
@@ -0,0 +1,31 @@
+<testcases repeat="1">
+<case
+ id = "1"
+ description1 = "test response code 500"
+ method = "get"
+ url = "{BASEURL}/code/500"
+ verifyresponsecode = "200"
+/>
+<case
+ id = "2"
+ description1 = "test response code 500"
+ method = "get"
+ url = "{BASEURL}/code/500"
+ verifyresponsecode = "200"
+/>
+<case
+ id = "3"
+ label = "testlabel"
+ description1 = "test response code 500"
+ method = "get"
+ url = "{BASEURL}/code/500"
+ verifyresponsecode = "200"
+/>
+<case
+ id = "4"
+ description1 = "test response code 500"
+ method = "get"
+ url = "{BASEURL}/code/500"
+ verifyresponsecode = "200"
+/>
+</testcases>

0 comments on commit da35460

Please sign in to comment.