Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

remove temporary files also in nagios ePN mode

  • Loading branch information...
commit 2c032543fa403fd3e39876fbce5528698b46c04a 1 parent 0ba2ac5
@sni authored
Showing with 19 additions and 8 deletions.
  1. +3 −0  Webinject/Changes
  2. +16 −8 Webinject/lib/Webinject.pm
View
3  Webinject/Changes
@@ -7,6 +7,9 @@ For information and documentation, visit the website at http://www.webinject.org
---------------------------------
Release History:
+Version 1.82 - Fri Nov 1 11:04:23 CET 2013
+ - remove temporary files also in nagios ePN mode
+
Version 1.80 - Fri Sep 13 11:10:40 CEST 2013
- remove temporary cookie file after test
View
24 Webinject/lib/Webinject.pm
@@ -32,7 +32,7 @@ use Error qw(:try); # for web services verification (you may comment
use Data::Dumper; # dump hashes for debugging
use File::Temp qw/ tempfile /; # create temp files
-our $VERSION = '1.80';
+our $VERSION = '1.82';
=head1 NAME
@@ -298,6 +298,8 @@ sub engine {
my $endruntimer = time();
$self->{'result'}->{'totalruntime'} = ( int( 1000 * ( $endruntimer - $startruntimer ) ) / 1000 ); #elapsed time rounded to thousandths
+ # required to clean up cookie files
+ undef $useragent;
# do return/cleanup tasks
return $self->_finaltasks();
@@ -584,14 +586,13 @@ sub _get_useragent {
my $useragent = LWP::UserAgent->new(keep_alive=>1);
# store cookies in our LWP object
- my $fh;
- our $cookietempfilename;
- ($fh, $cookietempfilename) = tempfile(undef, UNLINK => 1);
+ my($fh, $cookietempfilename) = tempfile(undef, UNLINK => 1);
unlink ($cookietempfilename);
$useragent->cookie_jar(HTTP::Cookies->new(
file => $cookietempfilename,
autosave => 1,
));
+ push @{$self->{'tmpfiles'}}, $cookietempfilename;
# http useragent that will show up in webserver logs
unless(defined $self->{'config'}->{'useragent'}) {
@@ -653,6 +654,7 @@ sub _set_defaults {
'globalhttplog' => 'no',
'proxy' => '',
'timeout' => 180,
+ 'tmpfiles' => [],
};
$self->{'exit_codes'} = {
'UNKNOWN' => 3,
@@ -1456,6 +1458,7 @@ sub _convtestcases {
my @xmltoconvert;
my ( $fh, $tempfilename ) = tempfile();
+ push @{$self->{'tmpfiles'}}, $tempfilename;
my $filename = $currentcasefile;
open( my $xmltoconvert, '<', $filename )
or $self->_usage("ERROR: Failed to read test case file: ".$filename.": ".$!);
@@ -1670,6 +1673,8 @@ plot \"$self->{'config'}->{'output_dir'}plot.log\" using 1:7 title \"Response Ti
sub _finaltasks {
my $self = shift;
+ $self->_clean_tmp_files();
+
if ( $self->{'gui'} ) { $self->_gui_stop(); }
# we suppress most logging when running in a plugin mode
@@ -1914,10 +1919,13 @@ EOB
}
################################################################################
-# make sure we don't keep the cookie temp file
-END {
- our $cookietempfilename;
- unlink($cookietempfilename) if $cookietempfilename;
+# remove any tmp files
+sub _clean_tmp_files {
+ my($self) = @_;
+ for my $tmpfile (@{$self->{'tmpfiles'}}) {
+ unlink($tmpfile);
+ }
+ return;
}
=head1 EXAMPLES
Please sign in to comment.
Something went wrong with that request. Please try again.