summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGES6
-rwxr-xr-xbin/tSmoke.dist47
-rw-r--r--lib/Smokeping.pm10
-rw-r--r--lib/Smokeping/probes/Curl.pm41
4 files changed, 66 insertions, 38 deletions
diff --git a/CHANGES b/CHANGES
index 725f8b9..4a5079e 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,9 @@
+* really send a test email with 'tSmoke --testmail' -- niko
+* Curl.pm: handle measurement of multiple URLs by adding the results together
+ -- niko, requested by Rob de Jong <rob *dejongnet.net>
+* Curl.pm: new variables 'follow_redirects' and 'include_redirects'
+ -- niko, requested by Rob de Jong <rob *dejongnet.net>
+
2005/12/2 -- released version 20051202_trunk
2005/12/1 -- released version 20051201_trunk
diff --git a/bin/tSmoke.dist b/bin/tSmoke.dist
index b9d4ddb..126017f 100755
--- a/bin/tSmoke.dist
+++ b/bin/tSmoke.dist
@@ -40,7 +40,7 @@
# Many thanks to the following people for their help and guidance:
# Jim Horwath of Agere Systems Inc. for his examples and pointers to Spreadsheet::WriteExcel
# Frank Harper the author of SLAMon, a tool for tracking Service Level Agreements
-# Tobias Oeticker, or course, the author of Smokeping, RRDTool and MRTG
+# Tobias Oetiker, or course, the author of Smokeping, RRDTool and MRTG
#
use strict;
@@ -89,33 +89,17 @@ my $RCS_VERSION = '$id: tSmoke.v 0.4 2004/03 McGinn-Combs';
sub test_mail($) {
my $cfg = shift;
- print "Mail will be sent to $cfg->{Alerts}{to}\n";
- print "Mail will be sent from $cfg->{Alerts}{from}\n";
+ my $mail = <<"EOF";
+Subject: tSmoke test
+To: $cfg->{Alerts}{to}
+
+This is a test mail with 'tSmoke --testmail'.
+EOF
+ print "Sending a test mail to $cfg->{Alerts}{to} from $cfg->{Alerts}{from}...";
+ Smokeping::sendmail($cfg->{Alerts}{from}, $cfg->{Alerts}{to}, $mail);
+ print "done.\n";
};
-sub sendmail ($$$$){
- my $from = shift;
- my $to = shift;
- my $subject = shift;
- my $body = shift;
- if ($cfg->{General}{mailhost}){
- my $smtp = Net::SMTP->new($cfg->{General}{mailhost});
- $smtp->mail($from);
- $smtp->to($to);
- $smtp->data();
- $smtp->datasend("Subject: $subject\n");
- $smtp->datasend("To: $to\n");
- $smtp->datasend($body);
- $smtp->dataend();
- $smtp->quit;
- } elsif ($cfg->{General}{sendmail} or -f "/usr/lib/sendmail"){
- open (M, "|-") || exec (($cfg->{General}{sendmail} || "/usr/lib/sendmail"),"-f",$from,$to);
- print M "Subject: $subject\n";
- print M $body;
- close M;
- }
-}
-
sub morning_update($) {
# Send out a morning summary of devices that are down
my $cfg = shift;
@@ -142,8 +126,11 @@ sub morning_update($) {
$target =~ s/.rrd//;
$TmpBody .= "$target\n" if $Loss == 0;
}
- $Body = "Of $Count Hosts, $Down Down:\n" . $TmpBody;
- sendmail $cfg->{Alerts}{from},$To,"Of $Count Hosts, $Down Down",$Body;
+ $Body = "Subject: Of $Count Hosts, $Down Down\n";
+ $Body .= "To: $To\n\n";
+ $Body = "Of $Count Hosts, $Down Down:\n";
+ $Body .= $TmpBody;
+ Smokeping::sendmail($cfg->{Alerts}{from},$To,$Body);
}
sub weekly_update($) {
@@ -220,6 +207,8 @@ sub weekly_update($) {
}
# Prepare the e-mail message
+ $Body = "Subject: IT System Availability\n";
+ $Body .= "To: $To\n\n";
open tSMOKE, $cfg->{General}{tmail} or die "ERROR: can't read $cfg->{General}{tmail}\n";
while (<tSMOKE>){
my $Summary = Summary_Sheet();
@@ -235,7 +224,7 @@ sub weekly_update($) {
$Body .= $_;
}
close tSMOKE;
- sendmail ( $cfg->{Alerts}{from}, $To, "IT System Availability", $Body );
+ Smokeping::sendmail($cfg->{Alerts}{from}, $To, $Body);
}
sub update_stats($$$$$);
diff --git a/lib/Smokeping.pm b/lib/Smokeping.pm
index f295a42..a483f60 100644
--- a/lib/Smokeping.pm
+++ b/lib/Smokeping.pm
@@ -740,7 +740,7 @@ sub get_detail ($$$$){
my $imghref;
my $max;
my @tasks;
- my %lasthight;
+ my %lastheight;
if ($mode eq 's'){
# in nave mode there is only one graph, so the height calculation
@@ -748,16 +748,16 @@ sub get_detail ($$$$){
$imgbase = $cfg->{General}{imgcache}."/".(join "/", @dirs)."/${file}";
$imghref = $cfg->{General}{imgurl}."/".(join "/", @dirs)."/${file}";
@tasks = @{$cfg->{Presentation}{detail}{_table}};
- if (open (HG,"<${imgbase}.maxhight")){
+ if (open (HG,"<${imgbase}.maxheight")){
while (<HG>){
chomp;
my @l = split / /;
- $lasthight{$l[0]} = $l[1];
+ $lastheight{$l[0]} = $l[1];
}
close HG;
}
$max = findmax $cfg, $rrd;
- if (open (HG,">${imgbase}.maxhight")){
+ if (open (HG,">${imgbase}.maxheight")){
foreach my $s (keys %{$max}){
print HG "$s $max->{$s}\n";
}
@@ -906,7 +906,7 @@ sub get_detail ($$$$){
$cfg->{Presentation}{detail}{logarithmic} eq 'yes';
my @lazy =();
- @lazy = ('--lazy') if $mode eq 's' and $lasthight{$start} and $lasthight{$start} == $max->{$start};
+ @lazy = ('--lazy') if $mode eq 's' and $lastheight{$start} and $lastheight{$start} == $max->{$start};
$desc = "Navigator Graph" if $mode eq 'n';
my $timer_start = time();
my @task =
diff --git a/lib/Smokeping/probes/Curl.pm b/lib/Smokeping/probes/Curl.pm
index 6e4625a..2e2ef01 100644
--- a/lib/Smokeping/probes/Curl.pm
+++ b/lib/Smokeping/probes/Curl.pm
@@ -128,6 +128,26 @@ DOC
return undef;
},
},
+ follow_redirects => {
+ _doc => <<DOC,
+If this variable is set to 'yes', curl will follow any HTTP redirection steps (the '-L' option).
+If set to 'no', HTTP Location: headers will not be followed. See also 'include_redirects'.
+DOC
+ _default => "no",
+ _re => "(yes|no)",
+ _example => "yes",
+ },
+
+ include_redirects => {
+ _doc => <<DOC,
+If this variable is set to 'yes', the measurement result will include the time
+spent on following any HTTP redirection steps. If set to 'no', only the last
+step is measured. See also 'follow_redirects'.
+DOC
+ _default => "no",
+ _re => "(yes|no)",
+ _example => "yes",
+ },
extraargs => {
_doc => <<DOC,
Any extra arguments you might want to hand to curl(1). The arguments
@@ -189,7 +209,9 @@ sub test_usage {
}
}
map { delete $arghashref->{$_} } @unsupported;
-
+ if (`$bin -o /dev/null -w '<%{time_redirect}>\n' 127.0.0.1 2>&1` =~ /^<>/m) {
+ $self->do_log("Note: your curl doesn't support the 'time_redirect' output variable; 'include_redirects' will not function.");
+ }
return;
}
@@ -217,11 +239,13 @@ sub proto_args {
my $target = shift;
# XXX - It would be neat if curl had a "time_transfer". For now,
# we take the total time minus the DNS lookup time.
- my @args = ("-o", "/dev/null", "-w", "Time: %{time_total} DNS time: %{time_namelookup}\\n");
+ my @args = ("-w", "Time: %{time_total} DNS time: %{time_namelookup} Redirect time: %{time_redirect}\\n");
my $ssl2 = $target->{vars}{ssl2};
push (@args, "-2") if $ssl2;
my $insecure_ssl = $target->{vars}{insecure_ssl};
push (@args, '-k') if $insecure_ssl;
+ my $follow = $target->{vars}{follow_redirects};
+ push (@args, '-L') if $follow eq "yes";
return(@args);
}
@@ -245,10 +269,12 @@ sub make_commandline {
my $url = $target->{vars}{urlformat};
my $host = $target->{addr};
$url =~ s/%host%/$host/g;
+ my @urls = split(/\s+/, $url);
+ push @args, ("-o", "/dev/null") for (@urls);
push @args, $self->proto_args($target);
push @args, $self->extra_args($target);
- return ($self->{properties}{binary}, @args, $url);
+ return ($self->{properties}{binary}, @args, @urls);
}
sub pingone {
@@ -268,7 +294,14 @@ sub pingone {
my $val;
while (<P>) {
- /^Time: (\d+\.\d+) DNS time: (\d+\.\d+)/ and $val = $1 - $2;
+ chomp;
+ /^Time: (\d+\.\d+) DNS time: (\d+\.\d+) Redirect time: (\d+\.\d+)?/ and do {
+ $val += $1 - $2;
+ if ($t->{vars}{include_redirects} eq "yes" and defined $3) {
+ $val += $3;
+ }
+ $self->do_debug("curl output: '$_', result: $val");
+ };
}
close P and defined $val and push @times, $val;
}