--- old/monbean.pl 2007-08-26 23:30:16.000000000 +0200 +++ new/monbean.pl 2007-08-26 23:39:28.000000000 +0200 @@ -1,76 +1,79 @@ #!/usr/bin/perl -#------------------------------ -# Copyright (C) 2007 XWave GmbH -# http://www.xwave.ch -# ------------------- -# Steven Schubiger -# [EMAIL PROTECTED] -# ------------------------- -# Last modified: 2007/01/30 -#------------------------------ +# monbean - monitor /proc/user_beancounters +# Copyright (C) 2007 Steven Schubiger <[EMAIL PROTECTED]> + +# 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. use strict; use warnings; use FindBin qw($Bin); +use File::Spec (); use Getopt::Long qw(:config no_ignore_case); use IO::File (); use Mail::Sendmail; -my $VERSION = '0.4'; +my $VERSION = '0.5'; my ($DEBUG, $DUMP, $NOMAIL); my %data; -#**************** -# start of config -#---------------- - -#-------------- -# system config -#-------------- - -# XXX - use filename only -my $file_track = 'monbean.dat'; - -my $input_source = '/proc/user_beancounters'; - -#------------ -# mail config -#------------ - -my $from = '[EMAIL PROTECTED]'; - -my @to = qw( - [EMAIL PROTECTED] - [EMAIL PROTECTED] - ); - -my $subject = 'User Beancounters - Notice'; - -#-------------- -# end of config -#************** +#----------------------- +# Start of configuration +#----------------------- + +my $Config = { + file_track => 'monbean.dat', + input_source => '/proc/user_beancounters', + mail => { + from => '[EMAIL PROTECTED]', + to => [ qw( + [EMAIL PROTECTED] + [EMAIL PROTECTED] + ) + ], + subject => 'User Beancounters - Notice', + }, +}; + +#--------------------- +# End of configuration +#--------------------- #---------- # INTERNALS #---------- -$file_track = "$Bin/$file_track"; -my $output = `cat $input_source`; +$Config->{file_track} = File::Spec->catfile($Bin, $Config->{file_track}); -my $to = join q{,}, @to; +my $fh = IO::File->new($Config->{input_source}, '<') or die "Can't open $Config->{input_source}: $!\n"; +my $output = do { local $/; <$fh> }; +$fh->close; my %mail = ( - From => $from, - To => $to, - Subject => $subject, + From => $Config->{mail}->{from}, + To => do { join q{,}, @{$Config->{mail}->{to}} }, + Subject => $Config->{mail}->{subject}, ); -getopts(); -run(); +{ + getopts(); + run(); +} sub getopts { my %opts; @@ -144,7 +147,7 @@ } sub _get_stats_file { - my $fh = IO::File->new($file_track, '<') or die "Can't open $file_track: $!\n"; + my $fh = IO::File->new($Config->{file_track}, '<') or die "Can't open $Config->{file_track}: $!\n"; my @members = <$fh>; $fh->close; @@ -249,7 +252,7 @@ } sub _put_stats_file { - my $fh = IO::File->new($file_track, '>') or die "Can't open $file_track: $!\n"; + my $fh = IO::File->new($Config->{file_track}, '>') or die "Can't open $Config->{file_track}: $!\n"; foreach my $uid (keys %data) { foreach my $res (keys %{$data{$uid}}) {
_______________________________________________ Devel mailing list [email protected] https://openvz.org/mailman/listinfo/devel
