[mrtg] attached script got ripped

Dominic Irrcher dirrcher at colosseum.com
Fri Feb 8 18:11:22 MET 2002


and here is the script in question:

#!/perl/bin/perl
#

$archive_dir = "c:/public_html/";
$threshold = "95";

$conf = "configfile_95.conf";
@months =
("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");

print "Content-type: text/html\n\n<pre>";

if (-e $conf) {
	open(CONF,"$conf");
	while(<CONF>) {
		chomp;
		push(@elements,$_);
    	}
}

@elements = @ARGV if (@ARGV);

die "Need a list of parameters to monitor!\n" unless (@elements);

for ($a=0; $a<=$#elements; $a++) {	# Each logfile as an argument.
    	($path,$comment) = split(/:/,$elements[$a]);
    	open(LOG,"$archive_dir/$path");
	while (<LOG>) {
		(@data) = split(/ /);
		@date_info = localtime($data[0]); # Get the date info
		$date_info[5] = $date_info[5] + 1900; # Calendar Year
		if ($date_info[4] < 10) {
	    		$date_info[4] = "0" . $date_info[4];
		}
		$date_info[4] = "00" unless ($date_info[4]);
		$datestamp = "$date_info[5]$date_info[4]";
		$record{$datestamp} = 1;	# Know which months our data covers
		$data{$datestamp}{$data[0]} = "$data[1]:$data[2]";
	}

    	@dates = keys ( %record );
	@sorted_dates = sort {$a <=> $b} @dates;

    	for ($b=0; $b<=$#sorted_dates; $b++) { # Loop through each month
		@in = undef;
		@out = undef;

		$year = substr($sorted_dates[$b],0,4);
		$month = substr($sorted_dates[$b],4,2);
		$month_name = $months[$month];


		@values = values %{ $data{$sorted_dates[$b]}};

		$entries = scalar (@values);
		$index = -1 + int($entries * $threshold / 100);

	for ($c=0; $c<=$#values; $c++) {
		($in,$out) = split(/:/,$values[$c]);
	    	push(@in,$in);
		push(@out,$out);
	}

	@sort_in = sort {$a <=> $b} @in;
	@sort_out = sort {$a <=> $b} @out;

	$high_in = $sort_in[$index];
	$high_out = $sort_out[$index];

	$level = $high_in;
	$level = $high_out if ($high_out > $level);

	$level = $level * 8;
	print "$comment usage for $month_name $ year is $level\n";
    }
}



and the contents of the .conf file


customer/customer.log:Customer Name

sorry, seems as though the attachments got ripped off,


Dominic Irrcher
Web Administrator
Colosseum Online Inc.
Phone: 416-739-7873
Fax: 416-739-1732
---------------------------
If you choke a Smurf, what color does it turn ?





--
Unsubscribe mailto:mrtg-request at list.ee.ethz.ch?subject=unsubscribe
Archive     http://www.ee.ethz.ch/~slist/mrtg
FAQ         http://faq.mrtg.org    Homepage     http://www.mrtg.org
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi



More information about the mrtg mailing list