#!/usr/bin/perl -w
###############################################################################
#
# Webmin Sysstats Module
# Copyright (C) 2002 by Eric Gerbier
# Bug reports to: gerbier@filesopen.sourceforge.net
# $Id$
#
# 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.
#
###############################################################################
use strict;
use warnings;
# to be used alone or from sysstat.pl without warning
# because require verify the path
if ( !exists $ENV{WEBMINSTAT_TEMP} ) {
use FindBin;
use lib "$FindBin::Bin/../..";
require 'sysstats-aquisition-lib.pl';
}
use RRDs;
###############################################################################
# uses open_fic and close_fic to avoid read and parse all log every run
sub read_amavis($$) {
my $log = shift(@_);
my $rh_data = shift(@_);
# extract patterns
# be careful, SPAMMY should be tested before SPAM
# so we sort pattern by size !
my @keys = sort { length $b <=> length $a } keys %{$rh_data};
#if ( open( $fh_info, '<', $log ) ) {
my ( $fh_info, $posname ) = open_fic( $log, 'amavis' );
if ($fh_info) {
LINE: while ( my $line = <$fh_info> ) {
foreach my $key (@keys) {
if ( $line =~ m/$key/ ) {
$rh_data->{$key}++;
next LINE;
}
}
}
#close $fh_info;
close_fic( $fh_info, $posname );
}
return;
}
###############################################################################
my %config;
read_file_cached( 'config', \%config );
my $param = 'vol';
my $vol_num = 1;
# first : get all search patterns
my %patterns;
while ( exists( $config{ $param . $vol_num } ) ) {
my @tab = split( /,/, $config{ $param . $vol_num } );
my $vol = $tab[1];
my $runstop = $tab[3];
# just get running patterns
if ( is_param_runstop($runstop) ) {
$patterns{$vol} = 0;
}
$vol_num++;
}
# populate patterns
read_amavis( $config{'amavislog'}, \%patterns );
# fill databases
$vol_num = 1;
while ( exists( $config{ $param . $vol_num } ) ) {
my @tab = split( /,/, $config{ $param . $vol_num } );
my $real_vol_num = $tab[0];
my $vol = $tab[1];
my $runstop = $tab[3];
#debug( "volume = $vol");
my $total = 'U';
if ( is_param_runstop($runstop) ) {
if ( exists $patterns{$vol} ) {
$total = $patterns{$vol};
}
else {
$total = 0;
}
debug("amavis $vol ($real_vol_num) : total=$total");
my $rrdbase = $real_vol_num . '.rrd';
RRDs::update( $rrdbase, "N:$total" );
my $ERR = RRDs::error();
warning("ERROR while updating $rrdbase: $ERR") if $ERR;
}
else {
debug("aquisition for $vol stopped");
}
$vol_num++;
} # while
# a label to quit
#I can not use return when executing this script standalone,
# so I had to use goto
END: