From f86998b3e0c689ca234245343aa75e7cdc5519d3 Mon Sep 17 00:00:00 2001 From: Tobi Oetiker Date: Tue, 29 Aug 2006 09:08:31 +0000 Subject: merge back to trunk --- lib/Smokeping.pm | 96 ++++++++++++++++++++++++++++++++++++++--------- lib/Smokeping/RRDtools.pm | 5 ++- 2 files changed, 83 insertions(+), 18 deletions(-) (limited to 'lib') diff --git a/lib/Smokeping.pm b/lib/Smokeping.pm index 581158c..2111b0e 100644 --- a/lib/Smokeping.pm +++ b/lib/Smokeping.pm @@ -28,7 +28,7 @@ use Smokeping::RRDtools; # globale persistent variables for speedy use vars qw($cfg $probes $VERSION $havegetaddrinfo $cgimode); -$VERSION="20060829"; +$VERSION="2.001000"; # we want opts everywhere my %opt; @@ -102,12 +102,26 @@ sub snmpget_ident ($) { return $answer; } +sub cgiurl { + my ($q, $cfg) = @_; + my %url_of = ( + absolute => $cfg->{General}{cgiurl}, + relative => q{}, + original => $q->script_name, + ); + my $linkstyle = $cfg->{General}->{linkstyle}; + die('unknown value for $cfg->{General}->{linkstyle}: ' + . $linkstyle + ) unless exists $url_of{$linkstyle}; + return $url_of{$linkstyle}; +} + sub lnk ($$) { my ($q, $path) = @_; if ($q->isa('dummyCGI')) { return $path . ".html"; } else { - return $cfg->{General}->{cgiurl} . "?target=" . $path; + return cgiurl($q, $cfg) . "?target=" . $path; } } @@ -795,6 +809,7 @@ sub get_detail ($$$$){ # one \s doesn't seem to be enough my @upargs; my @upsmoke; + my %lc; my %lcback; if ( defined $cfg->{Presentation}{detail}{loss_colors}{_table} ) { @@ -871,6 +886,7 @@ sub get_detail ($$$$){ ); my @lossargs = (); my @losssmoke = (); + foreach my $loss (sort {$a <=> $b} keys %lc){ next if $loss >= $pings; my $lvar = $loss; $lvar =~ s/\./d/g ; @@ -904,6 +920,7 @@ sub get_detail ($$$$){ ); # if we have uptime draw a colorful background or the graph showing the uptime + my $cdir=dyndir($cfg)."/".(join "/", @dirs)."/"; if ((not defined $cfg->{Presentation}{detail}{loss_background} or $cfg->{Presentation}{detail}{loss_background} ne 'yes') && (-f "$cdir/${file}.adr")) { @@ -974,6 +991,7 @@ sub get_detail ($$$$){ 'COMMENT:\s', "COMMENT:Probe${BS}: $pings $ProbeDesc every $step seconds", 'COMMENT:created on '.$date.'\j' ); + # do_log ("***** begin task *****
"); # do_log (@task); # do_log ("***** end task *****
"); @@ -1026,13 +1044,16 @@ sub display_webpage($$){ $tree = $tree->{$_}; } gen_imgs($cfg); # create logos in imgcache - + my $readversion = "?"; + $VERSION =~ /(\d+)\.(\d{3})(\d{3})/ and $readversion = sprintf("%d.%d.%d",$1,$2,$3); + print fill_template ($cfg->{Presentation}{template}, { menu => target_menu($cfg->{Targets}, [@$open], #copy this because it gets changed - $cfg->{General}->{cgiurl}."?target="), + cgiurl($q, $cfg) ."?target="), + title => $tree->{title}, remark => ($tree->{remark} || ''), overview => get_overview( $cfg,$q,$tree,$open ), @@ -1040,8 +1061,10 @@ sub display_webpage($$){ target_ip => ($tree->{host} || ''), owner => $cfg->{General}{owner}, contact => $cfg->{General}{contact}, + author => 'Tobi Oetiker and Niko Tyni', - smokeping => 'SmokePing-'.$VERSION.'', + smokeping => 'SmokePing-'.$readversion.'', + step => $step, rrdlogo => '', smokelogo => '', @@ -1170,7 +1193,9 @@ sub update_rrds($$$$$) { $urlline = $cfg->{General}{cgiurl}."?target=".$line; my $loss = "loss: ".join ", ",map {defined $_ ? (/^\d/ ? sprintf "%.0f%%", $_ :$_):"U" } @{$x->{loss}}; my $rtt = "rtt: ".join ", ",map {defined $_ ? (/^\d/ ? sprintf "%.0fms", $_*1000 :$_):"U" } @{$x->{rtt}}; - my $stamp = scalar localtime time; + my $time = time; + my @stamp = localtime($time); + my $stamp = localtime($time); my @to; foreach my $addr (map {$_ ? (split /\s*,\s*/,$_) : ()} $cfg->{Alerts}{to},$tree->{alertee},$cfg->{Alerts}{$_}{to}){ next unless $addr; @@ -1193,10 +1218,12 @@ SNPPALERT } }; if (@to){ + my $rfc2822stamp = strftime("%a, %e %b %Y %H:%M:%S %z", @stamp); my $to = join ",",@to; sendmail $cfg->{Alerts}{from},$to, <{Alerts}{from} +Date: $rfc2822stamp Subject: [SmokeAlert] $_ $what on $line $stamp @@ -1275,6 +1302,7 @@ sub get_parser () { my $KEY_RE = '[-_0-9a-zA-Z]+'; my $KEYD_RE = '[-_0-9a-zA-Z.]+'; my $PROBE_RE = '[A-Z][a-zA-Z]+'; + my $e = "="; my %knownprobes; # the probes encountered so far # get a list of available probes for _dyndoc sections @@ -1652,7 +1680,8 @@ DOC [ qw(owner imgcache imgurl datadir dyndir pagedir piddir sendmail offset smokemail cgiurl mailhost contact netsnpp syslogfacility syslogpriority concurrentprobes changeprocessnames tmail - changecgiprogramname) ], + changecgiprogramname linkstyle) ], + _mandatory => [ qw(owner imgcache imgurl datadir piddir smokemail cgiurl contact) ], @@ -1690,9 +1719,9 @@ DOC _doc => < sub { require Net::SMTP ||return "ERROR: loading Net::SMTP"; return undef; } }, @@ -1766,6 +1795,41 @@ Complete URL path of the SmokePing.cgi DOC }, + linkstyle => + { + _re => '(?:absolute|relative|original)', + _default => 'relative', + _re_error => + 'linkstyle must be one of "absolute", "relative" or "original"', + _doc => <> + +${e}item relative + +Only the parameter part is specified + +S<\> + +${e}item original + +The way the links were generated before Smokeping version 2.0.4: +no hostname, only the path + +S<\> + +${e}back + +The default is "relative", which hopefully works for everybody. +DOC + }, syslogfacility => { _re => '\w+', @@ -2600,8 +2664,6 @@ sub daemonize_me ($) { # The Main Program ########################################################################### -my $RCS_VERSION = '$Id: Smokeping.pm,v 1.5 2004/10/21 21:10:51 oetiker Exp $'; - sub load_cfg ($;$) { my $cfgfile = shift; my $noinit = shift; @@ -2753,7 +2815,8 @@ sub gen_page ($$$) { open PAGEFILE, ">$cfg->{General}{pagedir}/$name"; my $step = $probes->{$tree->{probe}}->step(); - + my $readversion = "?"; + $VERSION =~ /(\d+)\.(\d{3})(\d{3})/ and $readversion = sprintf("%d.%d.%d",$1,$2,$3); $page = fill_template ($cfg->{Presentation}{template}, { @@ -2767,8 +2830,8 @@ sub gen_page ($$$) { target_ip => ($tree->{host} || ''), owner => $cfg->{General}{owner}, contact => $cfg->{General}{contact}, - author => 'Tobi Oetiker', - smokeping => 'SmokePing-'.$VERSION.'', + author => 'Tobi Oetiker and Niko Tyni', + smokeping => 'SmokePing-'.$readversion.'', step => $step, rrdlogo => '', smokelogo => '', @@ -2925,8 +2988,7 @@ sub main (;$) { $opt{filter}=[]; GetOptions(\%opt, 'version', 'email', 'man:s','help','logfile=s','static-pages:s', 'debug-daemon', 'nosleep', 'makepod:s','debug','restart', 'filter=s', 'nodaemon|nodemon', - 'config=s', 'check', 'gen-examples', 'reload') or pod2usage(2); - if($opt{version}) { print "$RCS_VERSION\n"; exit(0) }; + if($opt{version}) { print "$VERSION\n"; exit(0) }; if(exists $opt{man}) { if ($opt{man}) { if ($opt{man} eq 'smokeping_config') { diff --git a/lib/Smokeping/RRDtools.pm b/lib/Smokeping/RRDtools.pm index fe6ae4f..6fde06b 100644 --- a/lib/Smokeping/RRDtools.pm +++ b/lib/Smokeping/RRDtools.pm @@ -104,7 +104,10 @@ use RRDs; sub info2create { my $file = shift; my @create; - my $buggy_perl_version = 1 if $^V and $^V eq "v5.8.0"; + # check for Perl version 5.8.0, it's buggy + # no more v-strings + my $buggy_perl_version = 1 if abs($] - 5.008000) < .0000005; + my $info = RRDs::info($file); my $error = RRDs::error; die("RRDs::info $file: ERROR: $error") if $error; -- cgit v1.2.3-24-g4f1b