diff options
-rw-r--r-- | CHANGES | 6 | ||||
-rw-r--r-- | doc/smokeping_upgrade.pod | 7 | ||||
-rw-r--r-- | lib/Smokeping.pm | 138 | ||||
-rw-r--r-- | lib/Smokeping/probes/FTPtransfer.pm | 12 | ||||
-rw-r--r-- | lib/Smokeping/probes/base.pm | 4 |
5 files changed, 128 insertions, 39 deletions
@@ -1,4 +1,8 @@ -* make sure logo images get wrien in binary mode or they will not be usable on windows -- tobi +* configuration option mailtemplate lets you configure the alert message content -- tobi +* added new method ProbeUnit to base.pm in support of FTPtransfer.pm -- tobi +* new probe FTPtransfer.pm added. It measures available bandwidth by + actually sending data over the wire to test (don't try this at home) -- tobi +* make sure logo images get writen in binary mode or they will not be usable on windows -- tobi * make PERL binary configurable in Makefile -- tobi * fixed echoping test call to be compatible with echoping 6 -- tobi * create a log entry when there are zero replies from a device. -- tobi diff --git a/doc/smokeping_upgrade.pod b/doc/smokeping_upgrade.pod index 5f59fdd..ee85be5 100644 --- a/doc/smokeping_upgrade.pod +++ b/doc/smokeping_upgrade.pod @@ -23,6 +23,13 @@ An official list of changes with each release can be found in the CHANGES file in the Smokeping distribution. This document tries to complement that with upgrading instructions etc. +=head1 2.0.9 to 2.1.0 + +=head2 New method in base.pm (if you write your own probes) + +The F<base.pm> module defines the method ProbeUnit. Override this if your +Probe does not return 'Seconds'. See the F<FTPtransfer.pm> for inspiration. + =head1 2.0.8 to 2.0.9 =head2 L<FPing|Smokeping::probes::FPing> diff --git a/lib/Smokeping.pm b/lib/Smokeping.pm index f0fb982..417f10e 100644 --- a/lib/Smokeping.pm +++ b/lib/Smokeping.pm @@ -548,16 +548,18 @@ sub target_menu($$$;$){ }; - -sub fill_template ($$){ +sub fill_template ($$;$){ my $template = shift; my $subst = shift; - my $line = $/; - undef $/; - open I, $template or return "<HTML><BODY>ERROR: Reading page template $template: $!</BODY></HTML>"; - my $data = <I>; - close I; - $/ = $line; + my $data = shift; + if ($template){ + my $line = $/; + undef $/; + open I, $template or return undef; + $data = <I>; + close I; + $/ = $line; + } foreach my $tag (keys %{$subst}) { $data =~ s/<##${tag}##>/$subst->{$tag}/g; } @@ -603,6 +605,7 @@ sub get_overview ($$$$){ my $max = $cfg->{Presentation}{overview}{max_rtt} || "100000"; my $medc = $cfg->{Presentation}{overview}{median_color} || "ff0000"; my $probe = $probes->{$tree->{$prop}{probe}}; + my $ProbeUnit = $probe->ProbeUnit(); my $pings = $probe->_pings($tree->{$prop}); my ($graphret,$xs,$ys) = RRDs::graph ($cfg->{General}{imgcache}.$dir."/${prop}_mini.png", @@ -611,7 +614,7 @@ sub get_overview ($$$$){ '--title',$tree->{$prop}{title}, '--height',$cfg->{Presentation}{overview}{height}, '--width',$cfg->{Presentation}{overview}{width}, - '--vertical-label',"Seconds", + '--vertical-label', $ProbeUnit, '--imgformat','PNG', '--alt-autoscale-max', '--alt-y-grid', @@ -734,6 +737,7 @@ sub get_detail ($$$$){ my $probe = $cfg->{__probes}{$tree->{probe}}; my $ProbeDesc = $probe->ProbeDesc(); + my $ProbeUnit = $probe->ProbeUnit(); my $step = $probe->step(); my $pings = $probe->_pings($tree); my $page; @@ -966,7 +970,7 @@ sub get_detail ($$$$){ '--rigid','--upper-limit', $max->{$start}, @log, '--lower-limit',(@log ? ($max->{$start} > 0.01) ? '0.001' : '0.0001' : '0'), - '--vertical-label',"Seconds", + '--vertical-label',$ProbeUnit, '--imgformat','PNG', '--color', 'SHADEA#ffffff', '--color', 'SHADEB#ffffff', @@ -1022,7 +1026,7 @@ sub get_detail ($$$$){ $page .= "<br/>"; $page .= ( $ERROR || qq{<a href="?displaymode=n;start=$startstr;end=now;}."target=".$q->param('target').'">' - . qq{<IMG BORDER="0" WIDTH="$xs" HEIGHT="$ys" SRC="${imghref}_${end}_${start}.png">}."</a>" ); + . qq{<IMG BORDER="0" WIDTH="$xs" HEIGHT="$ys" SRC="${imghref}_${end}_${start}.png">}."</a>" ); #" $page .= "</div>"; } @@ -1047,7 +1051,7 @@ sub display_webpage($$){ my $readversion = "?"; $VERSION =~ /(\d+)\.(\d{3})(\d{3})/ and $readversion = sprintf("%d.%d.%d",$1,$2,$3); - print fill_template + my $page = fill_template ($cfg->{Presentation}{template}, { menu => target_menu($cfg->{Targets}, @@ -1070,6 +1074,8 @@ sub display_webpage($$){ smokelogo => '<A HREF="http://oss.oetiker.ch/smokeping/counter.cgi/'.$VERSION.'"><img border="0" src="'.$cfg->{General}{imgurl}.'/smokeping.png"></a>', } ); + print $page || "<HTML><BODY>ERROR: Reading page template".$cfg->{Presentation}{template}."</BODY></HTML>"; + } # fetch all data. @@ -1218,33 +1224,47 @@ SNPPALERT } }; if (@to){ - my $rfc2822stamp = strftime("%a, %e %b %Y %H:%M:%S %z", @stamp); - my $to = join ",",@to; - sendmail $cfg->{Alerts}{from},$to, <<ALERT; -To: $to -From: $cfg->{Alerts}{from} -Date: $rfc2822stamp -Subject: [SmokeAlert] $_ $what on $line + my $default_mail = <<DOC; +Subject: [SmokeAlert] <##ALERT##> <##WHAT##> on <##LINE##> -$stamp +<##STAMP##> -Alert "$_" $what for $urlline +Alert "<##ALERT##>" <##WHAT##> for <##URL##> Pattern ------- -$cfg->{Alerts}{$_}{pattern} +<##PAT##> Data (old --> now) ------------------ -$loss -$rtt +<##LOSS##> +<##RTT##> Comment ------- -$cfg->{Alerts}{$_}{comment} - - - +<##COMMENT##> + +DOC + + my $mail = fill_template($cfg->{Alerts}{$_}{mailtemplate}, + { + ALERT => $_, + WHAT => $what, + LINE => $line, + URL => $urlline, + STAMP => $stamp, + PAT => $cfg->{Alerts}{$_}{pattern}, + LOSS => $loss, + RTT => $rtt, + COMMENT => $cfg->{Alerts}{$_}{comment} + },$default_mail) || "Subject: smokeping failed to open mailtemplate '$cfg->{Alerts}{$_}{mailtemplate}'\n\nsee subject\n"; + my $rfc2822stamp = strftime("%a, %e %b %Y %H:%M:%S %z", @stamp); + my $to = join ",",@to; + sendmail $cfg->{Alerts}{from},$to, <<ALERT; +To: $to +From: $cfg->{Alerts}{from} +Date: $rfc2822stamp +$mail ALERT } } else { @@ -1721,7 +1741,7 @@ DOC Instead of using sendmail, you can specify the name of an smtp server and use perl's Net::SMTP module to send mail (for alerts and DYNAMIC client script). Several comma separated mailhosts can be specified. SmokePing will -try one after the other is one does not anwer answer for 5 seconds. +try one after the other if one does not answer for 5 seconds. DOC _sub => sub { require Net::SMTP ||return "ERROR: loading Net::SMTP"; return undef; } }, @@ -2367,7 +2387,7 @@ A complete example DOC _sections => [ '/[^\s,]+/' ], - _vars => [ qw(to from edgetrigger) ], + _vars => [ qw(to from edgetrigger mailtemplate) ], _mandatory => [ qw(to from)], to => { _doc => <<DOC, Either an email address to send alerts to, or the name of a program to @@ -2399,9 +2419,44 @@ DOC _re_error =>"this must either be 'yes' or 'no'", _default => 'no', }, + mailtemplate => { + _doc => <<DOC, +When sending out mails for alerts, smokeping normally uses an internally +generated message. With the mailtemplate you can customize the alert mails +to look they way you like them. The all B<E<lt>##>I<keyword>B<##E<gt>> type +strings will get replaced in the template before it is sent out. the +following keywords are supported: + + <##ALERT##> - target name + <##WHAT##> - status (is active, was raised, was celared) + <##LINE##> - path in the config tree + <##URL##> - webpage for graph + <##STAMP##> - date and time + <##PAT##> - pattern that matched the alert + <##LOSS##> - loss history + <##RTT##> - rtt history + <##COMMENT##> - comment + + +DOC + + _sub => sub { + open (my $tmpl, $_[0]) or + return "mailtemplate '$_[0]' not readable"; + my $subj; + while (<$tmpl>){ + $subj =1 if /^Subject: /; + next if /^\S+: /; + last if /^$/; + return "mailtemplate '$_[0]' should start with mail header lines"; + } + return "mailtemplate '$_[0]' has no Subject: line" unless $subj; + return undef; + }, + }, '/[^\s,]+/' => { - _vars => [ qw(type pattern comment to edgetrigger) ], - _inherited => [ qw(edgetrigger) ], + _vars => [ qw(type pattern comment to edgetrigger mailtemplate) ], + _inherited => [ qw(edgetrigger mailtemplate) ], _mandatory => [ qw(type pattern comment) ], to => { _doc => 'Similar to the "to" parameter on the top-level except that it will only be used IN ADDITION to the value of the toplevel parameter. Same rules apply.', _re => '(\|.+|.+@\S+|snpp:)', @@ -2433,7 +2488,22 @@ DOC _re_error =>"this must either be 'yes' or 'no'", _default => 'no', }, - }, + mailtemplate => { + _sub => sub { + open (my $tmpl, $_[0]) or + return "mailtemplate '$_[0]' not readable"; + my $subj; + while (<$tmpl>){ + $subj =1 if /^Subject: /; + next if /^\S+: /; + last if /^$/; + return "mailtemplate '$_[0]' should start with mail header lines"; + } + return "mailtemplate '$_[0]' has no Subject: line" unless $subj; + return undef; + }, + }, + }, }, Targets => {_doc => <<DOC, The Target Section defines the actual work of SmokePing. It contains a hierarchical list @@ -2837,7 +2907,7 @@ sub gen_page ($$$) { smokelogo => '<A HREF="http://oss.oetiker.ch/smokeping/counter.cgi/'.$VERSION.'"><img border="0" src="'.$cfg->{General}{imgurl}.'/smokeping.png"></a>', }); - print PAGEFILE $page; + print PAGEFILE $page || "<HTML><BODY>ERROR: Reading page template ".$cfg->{Presentation}{template}."</BODY></HTML>"; close PAGEFILE; foreach my $key (keys %$tree) { diff --git a/lib/Smokeping/probes/FTPtransfer.pm b/lib/Smokeping/probes/FTPtransfer.pm index 707129c..c4c39e8 100644 --- a/lib/Smokeping/probes/FTPtransfer.pm +++ b/lib/Smokeping/probes/FTPtransfer.pm @@ -53,7 +53,7 @@ Many variables can be specified either in the probe or in the target definition, the target-specific variable will override the prove-specific variable. DOC authors => <<'DOC', -Tobias Oetiker <tobi@oetiker.ch> +Tobias Oetiker <tobi@oetiker.ch> sponsored by Virtela DOC bugs => <<DOC, This probe has the capability for saturating your links, so don't use it @@ -62,8 +62,12 @@ DOC } } -sub ProbeDesc { - return "FTP transfer"; +sub ProbeDesc ($) { + return "File transfers (FTP)"; +} + +sub ProbeUnit ($) { + return "Bytes/Second"; } sub new { @@ -126,7 +130,7 @@ sub pingone { $ftp->quit; $elapsed = ( $end - $start ); $ok or next; - my $speed = $elapsed / $size; + my $speed = $size / $elapsed; $self->do_debug("$host: ftp $mode $speed Bytes/s"); push @rates, $speed; } diff --git a/lib/Smokeping/probes/base.pm b/lib/Smokeping/probes/base.pm index 4a83b50..e33416f 100644 --- a/lib/Smokeping/probes/base.pm +++ b/lib/Smokeping/probes/base.pm @@ -90,6 +90,10 @@ sub ProbeDesc ($) { return "Probe which does not overrivd the ProbeDesc methode"; } +sub ProbeUnit ($) { + return "Seconds"; +} + sub target2dynfile ($$) { # the targets are stored in the $self->{targets} # hash as filenames pointing to the RRD files |