[Devel] [PATCH] monbean v0.5

Steven Schubiger schubiger at gmail.com
Sun Aug 26 14:46:29 PDT 2007


--- 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
-# steven.schubiger at xwave.ch
-# -------------------------
-# Last modified: 2007/01/30
-#------------------------------
+# monbean - monitor /proc/user_beancounters
+# Copyright (C) 2007 Steven Schubiger <schubiger at gmail.com.remove>
+
+# 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 at mydomain.com';
-
-my @to      = qw(
-                  myemail at mydomain.com
-                  myemail2 at mydomain.com
-		 );
-		  
-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 at mydomain.com',
+        to      => [ qw(
+	                myemail at mydomain.com
+			myemail2 at mydomain.com
+		       ) 
+                   ],
+        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}}) {




More information about the Devel mailing list