added suppor for the 'traffacct' (network traffic accounting) graph

This commit is contained in:
Jordi Sanfeliu 2013-01-08 17:22:05 +01:00
parent 63ca849be1
commit e79cd3c49f
4 changed files with 605 additions and 16 deletions

View File

@ -206,6 +206,27 @@ sub flush_accounting_rules {
system("iptables -X $_");
}
}
if(open(IN, "iptables -nxvL FORWARD --line-numbers |")) {
my @rules;
my @names;
while(<IN>) {
my ($rule, undef, undef, $name) = split(' ', $_);
if($name =~ /monitorix_daily_/ || /monitorix_total_/) {
push(@rules, $rule);
push(@names, $name);
}
}
close(IN);
@rules = reverse(@rules);
foreach(@rules) {
system("iptables -D FORWARD $_");
$num++;
}
foreach(@names) {
system("iptables -F $_");
system("iptables -X $_");
}
}
logger("$num iptables rules have been flushed.") if $debug;
}
if(grep {$_ eq $config->{os}} ("FreeBSD", "OpenBSD", "NetBSD")) {

551
lib/traffacct.pm Normal file
View File

@ -0,0 +1,551 @@
#
# Monitorix - A lightweight system monitoring tool.
#
# Copyright (C) 2005-2013 by Jordi Sanfeliu <jordi@fibranet.cat>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
package traffacct;
use strict;
use warnings;
use Monitorix;
use RRDs;
use Exporter 'import';
our @EXPORT = qw(traffacct_init traffacct_update traffacct_cgi traffacct_getcounters traffacct_sendreports);
sub traffacct_init {
my $myself = (caller(0))[3];
my ($package, $config, $debug) = @_;
my $rrd = $config->{base_lib} . $package . ".rrd";
my $traffacct = $config->{traffacct};
my $info;
my @ds;
my @tmp;
my $n;
if(!grep {$_ eq $config->{os}} ("Linux")) {
logger("$myself is not supported yet by your operating system ($config->{os}.");
return;
}
if(-e $rrd) {
$info = RRDs::info($rrd);
for my $key (keys %$info) {
if(index($key, 'ds[') == 0) {
if(index($key, '.type') != -1) {
push(@ds, substr($key, 3, index($key, ']') - 3));
}
}
}
if(scalar(@ds) / 2 != $traffacct->{max}) {
logger("Detected size mismatch between 'max = $traffacct->{max}' and $rrd (" . scalar(@ds) / 2 . "). Resizing it accordingly. All historic data will be lost. Backup file created.");
rename($rrd, "$rrd.bak");
}
}
if(!(-e $rrd)) {
logger("Creating '$rrd' file.");
for($n = 0; $n < $traffacct->{max}; $n++) {
push(@tmp, "DS:traffacct" . $n . "_in:GAUGE:120:0:U");
push(@tmp, "DS:traffacct" . $n . "_out:GAUGE:120:0:U");
}
eval {
RRDs::create($rrd,
"--step=60",
@tmp,
"RRA:AVERAGE:0.5:1:1440",
"RRA:AVERAGE:0.5:30:336",
"RRA:AVERAGE:0.5:60:744",
"RRA:AVERAGE:0.5:1440:365",
"RRA:MIN:0.5:1:1440",
"RRA:MIN:0.5:30:336",
"RRA:MIN:0.5:60:744",
"RRA:MIN:0.5:1440:365",
"RRA:MAX:0.5:1:1440",
"RRA:MAX:0.5:30:336",
"RRA:MAX:0.5:60:744",
"RRA:MAX:0.5:1440:365",
"RRA:LAST:0.5:1:1440",
"RRA:LAST:0.5:30:336",
"RRA:LAST:0.5:60:744",
"RRA:LAST:0.5:1440:365",
);
};
my $err = RRDs::error;
if($@ || $err) {
logger("$@") unless !$@;
if($err) {
logger("ERROR: while creating $rrd: $err");
if($err eq "RRDs::error") {
logger("... is the RRDtool Perl package installed?");
}
}
return;
}
}
if($config->{os} eq "Linux") {
if(!$config->{net}->{gateway}) {
logger("ERROR: You must assign a valid ethernet interface in 'net->gateway'");
return;
}
# set the iptables rules for each defined host/network
my @tal = split(',', $traffacct->{list});
for($n = 0; $n < $traffacct->{max}; $n++) {
my $name = trim($tal[$n]);
if($name) {
my $ip = trim((split(',', $traffacct->{desc}->{$n}))[0]);
if(!$ip) {
if(!gethostbyname($name)) {
logger("WARNING: Unable to resolve '" . $name . "'. Check your DNS.");
}
$ip = inet_ntoa((gethostbyname($name))[4]);
$ip = $ip . "/32";
}
open(IN, "iptables -nxvL monitorix_daily_$name 2>/dev/null |");
my @data = <IN>;
close(IN);
if(!scalar(@data)) {
system("iptables -N monitorix_daily_$name");
system("iptables -I FORWARD -j monitorix_daily_$name");
system("iptables -A monitorix_daily_$name -s $ip -d 0/0 -o $config->{net}->{gateway}");
system("iptables -A monitorix_daily_$name -s 0/0 -d $ip -i $config->{net}->{gateway}");
}
}
}
}
# Since 3.0.0 PC_LAN values were renamed to TRAFFACCT.
for($n = 0; $n < $traffacct->{max}; $n++) {
RRDs::tune($rrd,
"--data-source-rename=pc" . $n . "_in:traffacct" . $n . "_in",
"--data-source-rename=pc" . $n . "_out:traffacct" . $n . "_out",
);
}
$config->{traffacct_hist_in} = ();
$config->{traffacct_hist_out} = ();
push(@{$config->{func_update}}, $package);
logger("$myself: Ok") if $debug;
}
sub traffacct_update {
my $myself = (caller(0))[3];
my ($package, $config, $debug) = @_;
my $rrd = $config->{base_lib} . $package . ".rrd";
my $traffacct = $config->{traffacct};
my @in;
my @out;
my $n;
my $rrdata = "N";
my @tal = split(',', $traffacct->{list});
for($n = 0; $n < $traffacct->{max}; $n++) {
my $name = trim($tal[$n]);
if($name) {
my $ip = trim((split(',', $traffacct->{desc}->{$n}))[0]);
if(!$ip) {
if(!gethostbyname($name)) {
logger("WARNING: Unable to resolve '" . $name . "'. Check your DNS.");
}
$ip = inet_ntoa((gethostbyname($name))[4]);
}
$ip =~ s/\/\d+//;
open(IN, "iptables -nxvL monitorix_daily_$name |");
$in[$n] = 0 unless $in[$n];
$out[$n] = 0 unless $out[$n];
while(<IN>) {
my (undef, $bytes, undef, undef, undef, undef, $source) = split(' ', $_);
if($source) {
if($source =~ /0.0.0.0/) {
$in[$n] = $bytes - ($config->{traffacct_hist_in}[$n] || 0);
$in[$n] = 0 unless $in[$n] != $bytes;
$config->{traffacct_hist_in}[$n] = $bytes;
$in[$n] /= 60;
}
if($source eq $ip) {
$out[$n] = $bytes - ($config->{traffacct_hist_out}[$n] || 0);
$out[$n] = 0 unless $out[$n] != $bytes;
$config->{traffacct_hist_out}[$n] = $bytes;
$out[$n] /= 60;
}
}
}
close(IN);
}
}
for($n = 0; $n < $traffacct->{max}; $n++) {
my $i = $in[$n] || 0;
my $o = $out[$n] || 0;
$rrdata .= ":$i:$o";
}
RRDs::update($rrd, $rrdata);
logger("$myself: $rrdata") if $debug;
my $err = RRDs::error;
logger("ERROR: while updating $rrd: $err") if $err;
}
sub traffacct_getcounters {
my $myself = (caller(0))[3];
my ($config, $debug) = @_;
my $traffacct = $config->{traffacct};
my $in;
my $out;
my $n;
my $day = (localtime(time - 60))[3];
my @tal = split(',', $traffacct->{list});
for($n = 0; $n < $traffacct->{max}; $n++) {
my $name = trim($tal[$n]);
if($name) {
my $ip = trim((split(',', $traffacct->{desc}->{$n}))[0]);
if(!$ip) {
if(!gethostbyname($name)) {
logger("WARNING: Unable to resolve '" . $name . "'. Check your DNS.");
}
$ip = inet_ntoa((gethostbyname($name))[4]);
}
$ip =~ s/\/\d+//;
open(IN, "iptables -nxvL monitorix_daily_$name |");
while(<IN>) {
my (undef, $bytes, undef, undef, undef, undef, $source) = split(' ', $_);
if($source) {
if($source eq $ip) {
$out = $bytes;
}
if($source =~ /0.0.0.0/) {
$in = $bytes;
}
}
}
close(IN);
my $usage_dir = $config->{base_lib} . $config->{usage_dir};
if(! -w $usage_dir) {
logger("WARNING: directory '" . $usage_dir ."' doesn't exists or is not writable.");
last;
} else {
open(OUT, ">> " . $usage_dir . $name);
print(OUT "$day $in $out\n");
close(OUT);
logger("Saved daily traffic counter for '$name'.") if $debug;
}
system("iptables -Z monitorix_daily_$name >/dev/null 2>/dev/null");
}
}
}
sub traffacct_sendreports {
my $myself = (caller(0))[3];
my ($config, $debug) = @_;
my $traffacct = $config->{traffacct};
my $n;
my $to;
# my $report_dir = $config->{base_lib} . $config->{report_dir};
# if(! -x $report_dir . "send_reports") {
# logger("$myself: unable to find the script '" . $REPORT_DIR . "send_reports" . "'.");
# return;
# }
# logger("Sending monthly traffic reports.");
# for($n = 0; $n < $PC_MAX; $n++) {
# if($PC_LIST[$n]) {
# $to = $PC_REPORT_MAIL[$n];
# $to = $PC_DEFAULT_MAIL unless $PC_REPORT_MAIL[$n];
# logger("$myself: $PC_LIST[$n] -> $to [$PC_REPORT_LANG]");
# system("cd $REPORT_DIR ; " . $REPORT_DIR . "send_reports -h $PC_LIST[$n] -c $opt_c &");
# }
# }
}
sub traffacct_cgi {
my ($package, $config, $cgi) = @_;
my $traffacct = $config->{traffacct};
my @rigid = split(',', $traffacct->{rigid});
my @limit = split(',', $traffacct->{limit});
my $tf = $cgi->{tf};
my $colors = $cgi->{colors};
my $graph = $cgi->{graph};
my $silent = $cgi->{silent};
my $u = "";
my $width;
my $height;
my @riglim;
my @PNG;
my @PNGz;
my @tmp;
my @tmpz;
my @CDEF;
my $T = "B";
my $vlabel = "bytes/s";
my $n;
my $n2;
my $str;
my $err;
my $rrd = $config->{base_lib} . $package . ".rrd";
my $title = $config->{graph_title}->{$package};
my $PNG_DIR = $config->{base_dir} . "/" . $config->{imgs_dir};
if(lc($config->{netstats_in_bps}) eq "y") {
$T = "b";
$vlabel = "bits/s";
}
# graph mode
#
if($silent eq "yes" || $silent eq "imagetag") {
$colors->{fg_color} = "#000000"; # visible color for text mode
$u = "_";
}
if($silent eq "imagetagbig") {
$colors->{fg_color} = "#000000"; # visible color for text mode
$u = "";
}
for($n = 0; $n < $traffacct->{max}; $n++) {
$str = $u . "traffacct" . $n . ".$tf->{when}" . ".png";
push(@PNG, $str);
unlink("$PNG_DIR" . $str);
if(lc($config->{enable_zoom}) eq "y") {
$str = $u . "traffacct" . $n . "z.$tf->{when}" . ".png";
push(@PNGz, $str);
unlink("$PNG_DIR" . $str);
}
}
if(trim($rigid[0]) eq 1) {
push(@riglim, "--upper-limit=" . trim($limit[0]));
} else {
if(trim($rigid[0]) eq 2) {
push(@riglim, "--upper-limit=" . trim($limit[0]));
push(@riglim, "--rigid");
}
}
$traffacct->{graphs_per_row} = 1 unless $traffacct->{graphs_per_row} > 1;
my @tal = split(',', $traffacct->{list});
if($cgi->{val} eq "all") {
print(" <table cellspacing='5' cellpadding='0' width='1' bgcolor='$colors->{graph_bg_color}' border='1'>\n");
print(" <tr>\n");
print(" <td bgcolor='$colors->{title_bg_color}' colspan='" . $traffacct->{graphs_per_row} . "'>\n");
print(" <font face='Verdana, sans-serif' color='$colors->{title_fg_color}'>\n");
print(" <b>&nbsp;&nbsp;Network traffic<b>\n");
print(" </font>\n");
print(" </td>\n");
print(" </tr>\n");
$n = 0;
while($n < $traffacct->{max}) {
my $name = trim($tal[$n]);
last unless $name;
print(" <tr>\n");
for($n2 = 0; $n2 < $traffacct->{graphs_per_row}; $n2++) {
last unless ($n < $traffacct->{max} && $n < scalar(@tal));
print(" <td bgcolor='$colors->{title_bg_color}'>\n");
undef(@tmp);
undef(@tmpz);
undef(@CDEF);
push(@tmp, "AREA:B_in#44EE44:Input");
push(@tmp, "AREA:B_out#4444EE:Output");
push(@tmp, "AREA:B_out#4444EE:");
push(@tmp, "AREA:B_in#44EE44:");
push(@tmp, "LINE1:B_out#0000EE");
push(@tmp, "LINE1:B_in#00EE00");
push(@tmpz, "AREA:B_in#44EE44:Input");
push(@tmpz, "AREA:B_out#4444EE:Output");
push(@tmpz, "AREA:B_out#4444EE:");
push(@tmpz, "AREA:B_in#44EE44:");
push(@tmpz, "LINE1:B_out#0000EE");
push(@tmpz, "LINE1:B_in#00EE00");
if(lc($config->{netstats_in_bps}) eq "y") {
push(@CDEF, "CDEF:B_in=in,8,*");
push(@CDEF, "CDEF:B_out=out,8,*");
} else {
push(@CDEF, "CDEF:B_in=in");
push(@CDEF, "CDEF:B_out=out");
}
($width, $height) = split('x', $config->{graph_size}->{remote});
RRDs::graph("$PNG_DIR" . "$PNG[$n]",
"--title=$name traffic ($tf->{nwhen}$tf->{twhen})",
"--start=-$tf->{nwhen}$tf->{twhen}",
"--imgformat=PNG",
"--vertical-label=$vlabel",
"--width=$width",
"--height=$height",
@riglim,
"--lower-limit=0",
@{$cgi->{version12}},
@{$cgi->{version12_small}},
@{$colors->{graph_colors}},
"DEF:in=$rrd:traffacct" . $n . "_in:AVERAGE",
"DEF:out=$rrd:traffacct" . $n . "_out:AVERAGE",
@CDEF,
@tmp);
$err = RRDs::error;
print("ERROR: while graphing $PNG_DIR" . "$PNG[$n]: $err\n") if $err;
if(lc($config->{enable_zoom}) eq "y") {
($width, $height) = split('x', $config->{graph_size}->{zoom});
RRDs::graph("$PNG_DIR" . "$PNGz[$n]",
"--title=$name traffic ($tf->{nwhen}$tf->{twhen})",
"--start=-$tf->{nwhen}$tf->{twhen}",
"--imgformat=PNG",
"--vertical-label=$vlabel",
"--width=$width",
"--height=$height",
@riglim,
"--lower-limit=0",
@{$cgi->{version12}},
@{$cgi->{version12_small}},
@{$colors->{graph_colors}},
"DEF:in=$rrd:traffacct" . $n . "_in:AVERAGE",
"DEF:out=$rrd:traffacct" . $n . "_out:AVERAGE",
@CDEF,
@tmpz);
$err = RRDs::error;
print("ERROR: while graphing $PNG_DIR" . "$PNGz[$n]: $err\n") if $err;
}
if(lc($config->{enable_zoom}) eq "y") {
if(lc($config->{disable_javascript_void}) eq "y") {
print(" <a href=\"" . $config->{url} . $config->{imgs_dir} . $PNGz[$n] . "\"><img src='" . $config->{url} . $config->{imgs_dir} . $PNG[$n] . "' border='0'></a>\n");
}
else {
print(" <a href=\"javascript:void(window.open('" . $config->{url} . $config->{imgs_dir} . $PNGz[$n] . "','','width=" . ($width + 115) . ",height=" . ($height + 100) . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . $config->{imgs_dir} . $PNG[$n] . "' border='0'></a>\n");
}
} else {
print(" <img src='" . $config->{url} . $config->{imgs_dir} . $PNG[$n] . "'>\n");
}
print(" </td>\n");
$n++;
}
print(" </tr>\n");
}
print " </table>\n";
} else {
return unless $tal[$cgi->{val}];
if(!$silent) {
print(" <table cellspacing='5' cellpadding='0' width='1' bgcolor='$colors->{graph_bg_color}' border='1'>\n");
print(" <tr>\n");
print(" <td bgcolor='$colors->{title_bg_color}' colspan='1'>\n");
print(" <font face='Verdana, sans-serif' color='$colors->{title_fg_color}'>\n");
print(" <b>&nbsp;&nbsp;Network traffic<b>\n");
print(" </font>\n");
print(" </td>\n");
print(" </tr>\n");
print(" <tr>\n");
print(" <td bgcolor='$colors->{title_bg_color}'>\n");
}
undef(@tmp);
undef(@tmpz);
undef(@CDEF);
push(@tmp, "AREA:B_in#44EE44:K$T/s Input");
push(@tmp, "GPRINT:K_in:LAST: Current\\: %5.0lf");
push(@tmp, "GPRINT:K_in:AVERAGE: Average\\: %5.0lf");
push(@tmp, "GPRINT:K_in:MIN: Min\\: %5.0lf");
push(@tmp, "GPRINT:K_in:MAX: Max\\: %5.0lf\\n");
push(@tmp, "AREA:B_out#4444EE:K$T/s Output");
push(@tmp, "GPRINT:K_out:LAST: Current\\: %5.0lf");
push(@tmp, "GPRINT:K_out:AVERAGE: Average\\: %5.0lf");
push(@tmp, "GPRINT:K_out:MIN: Min\\: %5.0lf");
push(@tmp, "GPRINT:K_out:MAX: Max\\: %5.0lf\\n");
push(@tmp, "AREA:B_out#4444EE:");
push(@tmp, "AREA:B_in#44EE44:");
push(@tmp, "LINE1:B_out#0000EE");
push(@tmp, "LINE1:B_in#00EE00");
push(@tmpz, "AREA:B_in#44EE44:Input");
push(@tmpz, "AREA:B_out#4444EE:Output");
push(@tmpz, "AREA:B_out#4444EE:");
push(@tmpz, "AREA:B_in#44EE44:");
push(@tmpz, "LINE1:B_out#0000EE");
push(@tmpz, "LINE1:B_in#00EE00");
if(lc($config->{netstats_in_bps}) eq "y") {
push(@CDEF, "CDEF:B_in=in,8,*");
push(@CDEF, "CDEF:B_out=out,8,*");
} else {
push(@CDEF, "CDEF:B_in=in");
push(@CDEF, "CDEF:B_out=out");
}
($width, $height) = split('x', $config->{graph_size}->{main});
RRDs::graph("$PNG_DIR" . "$PNG[$cgi->{val}]",
"--title=$tal[$cgi->{val}] traffic ($tf->{nwhen}$tf->{twhen})",
"--start=-$tf->{nwhen}$tf->{twhen}",
"--imgformat=PNG",
"--vertical-label=$vlabel",
"--width=$width",
"--height=$height",
@riglim,
"--lower-limit=0",
@{$cgi->{version12}},
@{$colors->{graph_colors}},
"DEF:in=$rrd:traffacct" . $cgi->{val} . "_in:AVERAGE",
"DEF:out=$rrd:traffacct" . $cgi->{val} . "_out:AVERAGE",
@CDEF,
"CDEF:K_in=B_in,1024,/",
"CDEF:K_out=B_out,1024,/",
@tmp);
$err = RRDs::error;
print("ERROR: while graphing $PNG_DIR" . "$PNG[$cgi->{val}]: $err\n") if $err;
if(lc($config->{enable_zoom}) eq "y") {
($width, $height) = split('x', $config->{graph_size}->{zoom});
RRDs::graph("$PNG_DIR" . "$PNGz[$cgi->{val}]",
"--title=$tal[$cgi->{val}] traffic ($tf->{nwhen}$tf->{twhen})",
"--start=-$tf->{nwhen}$tf->{twhen}",
"--imgformat=PNG",
"--vertical-label=$vlabel",
"--width=$width",
"--height=$height",
@riglim,
"--lower-limit=0",
@{$cgi->{version12}},
@{$colors->{graph_colors}},
"DEF:in=$rrd:traffacct" . $cgi->{val} . "_in:AVERAGE",
"DEF:out=$rrd:traffacct" . $cgi->{val} . "_out:AVERAGE",
@CDEF,
"CDEF:K_in=B_in,1024,/",
"CDEF:K_out=B_out,1024,/",
@tmpz);
$err = RRDs::error;
print("ERROR: while graphing $PNG_DIR" . "$PNGz[$cgi->{val}]: $err\n") if $err;
}
if(lc($config->{enable_zoom}) eq "y") {
if(lc($config->{disable_javascript_void}) eq "y") {
print(" <a href=\"" . $config->{url} . $config->{imgs_dir} . $PNGz[$cgi->{val}] . "\"><img src='" . $config->{url} . $config->{imgs_dir} . $PNG[$cgi->{val}] . "' border='0'></a>\n");
}
else {
print(" <a href=\"javascript:void(window.open('" . $config->{url} . $config->{imgs_dir} . $PNGz[$cgi->{val}] . "','','width=" . ($width + 115) . ",height=" . ($height + 100) . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . $config->{imgs_dir} . $PNG[$cgi->{val}] . "' border='0'></a>\n");
}
} else {
print(" <img src='" . $config->{url} . $config->{imgs_dir} . $PNG[$cgi->{val}] . "'>\n");
}
if(!$silent) {
print(" </td>\n");
print " </td>\n";
print " </tr>\n";
print " </table>\n";
}
}
}

View File

@ -32,8 +32,6 @@ use Config::General;
use Getopt::Std;
use Cwd 'abs_path';
use Data::Dumper;
# Force a standard locale
$ENV{LANG} = "";
setlocale(LC_TIME, "C");
@ -106,18 +104,29 @@ sub ALRM_handler {
no strict "refs";
eval { &$update($f, \%config, $d); };
if($@) {
logger("$update(): $@");
logger("$myself: $update(): $@");
}
}
}
if(lc($config{graph_enable}->{pc}) eq "y" && lc($config{pc_enable_monthly_reports}) eq "y") {
# collect traffic accounting every day at 00:00h
if($min == 0 && $hour == 0) {
get_counters();
if(lc($config{traffacct}->{enabled}) eq "y" && lc($config{traffacct}->{enable_monthly_reports}) eq "y") {
my $d = "traffacct";
undef($d) if(!grep {trim($_) eq $d} (@{$config{debug}}));
# send reports every first day of a month at 00:00h
# at 00:00h
if($min == 0 && $hour == 0) {
# collect traffic accounting every day
eval { traffacct::traffacct_getcounters(\%config, $d); };
if($@) {
logger("$myself: traffacct::traffacct_getcounters(): $@");
}
# send reports every first day of a month
if($mday == 1) {
send_reports();
eval { traffacct_sendreports(\%config, $d); };
if($@) {
logger("$myself: traffacct_sendreports(): $@");
}
}
}
}
@ -254,11 +263,11 @@ EOF
}
}
if(scalar(my @tfl = split(',', $config{traffacct}->{list})) && lc($config{traffacct}->{enabled}) eq "y") {
if(scalar(my @tal = split(',', $config{traffacct}->{list})) && lc($config{traffacct}->{enabled}) eq "y") {
print(OUT " <optgroup label='Traffic Accounting'>\n");
print(OUT " <option value='traffacct.all'>All</option>\n");
for($n = 0; $n < scalar(@tfl); $n++) {
print(OUT " <option value='traffacct.$n'>" . trim($tfl[$n]) . "</option>\n");
for($n = 0; $n < scalar(@tal); $n++) {
print(OUT " <option value='traffacct.$n'>" . trim($tal[$n]) . "</option>\n");
}
print(OUT " </optgroup>\n");
}
@ -432,7 +441,7 @@ if($options{d}) {
if($options{d} ne "none" && $options{d} ne "all") {
@{$config{debug}} = split(',', $options{d});
foreach my $t (@{$config{debug}}) {
if(!grep {trim($_) eq $t} (split(',', $config{graph_name}))) {
if(!grep {trim($_) eq $t} (split(',', $config{graph_name} . ", traffacct"))) {
die("Invalid debug key '$t'");
}
}
@ -484,6 +493,9 @@ foreach (split(',', $config{graph_name} . ", traffacct")) {
}
}
use Data::Dumper;
print Dumper($config{func_update});
if(!scalar($config{func_update})) {
logger("nothing to do, exiting.");
exit(0);

View File

@ -349,7 +349,7 @@ if(!$silent) {
print(" <td bgcolor='" . $colors{bg_color} . "'>\n");
print(" <font face='Verdana, sans-serif' color='" . $colors{fg_color} . "'>\n");
if($mode eq "localhost" || $mode eq "pc") {
if($mode eq "localhost" || $mode eq "traffacct") {
$title = $config{hostname};
} elsif($mode eq "multihost") {
$graph = $graph eq "all" ? "_system1" : $graph;
@ -414,8 +414,13 @@ if($mode eq "localhost") {
}
} elsif($mode eq "multihost") {
multihost(\%config, \%colors, \%cgi);
} elsif($mode eq "pc") {
pc();
} elsif($mode eq "traffacct") {
eval "use $mode qw(traffacct_cgi)";
if($@) {
print(STDERR "WARNING: unable to find module '$mode'\n");
exit;
}
traffacct_cgi($mode, \%config, \%cgi);
}
if(!$silent) {