Fwd: This patch adds repquota to logwatch's skillz
"Kirk Bauer" <[email protected]>
| Newsgroups | gmane.comp.log.logwatch.devel |
|---|---|
| Message-ID | <[email protected]> |
---------- Forwarded message ---------- From: Pat Riehecky <[email protected]> Date: Mon, May 12, 2008 at 8:41 AM Subject: This patch adds repquota to logwatch's skillz To: [email protected] This patch lets logwatch check for quotas and report violates as needed. Thanks ever so much for all your logwatch work Pat -- Kirk Bauer <[email protected]> http://linux.kaybee.org | www.logwatch.org Author, Automating UNIX & Linux Administration _______________________________________________ Logwatch-Devel mailing list [email protected] http://www2.list.logwatch.org:81/mailman/listinfo/logwatch-devel
quota.diff
(text/x-patch, 3.6 KB)
--- quota 2008-05-12 10:37:04.000000000 -0500
+++ quota 2008-05-12 10:34:34.000000000 -0500
@@ -0,0 +1,130 @@
+#!/usr/bin/perl -w
+use strict;
+
+$|++;
+
+my $Detail = $ENV{'LOGWATCH_DETAIL_LEVEL'} || 0;
+
+my $quota_search = `mount | grep quota`;
+chomp($quota_search);
+
+if ($quota_search ne '')
+ {
+ my (%over,$count);
+ my $repquota = 'repquota -a';
+ $repquota .= ' -C' if ($^O eq 'linux');
+
+ my @output = split(/\n/,`$repquota | grep '+'`);
+
+ $count = 0;
+ foreach (@output)
+ {
+ if ($_ =~ /([\w\d]+)\s+\+\-\s+([\d\w]+)\s+([\d\w]+)\s+([\d\w]+)\s+([\d\w]+)/)
+ {
+ $count++;
+
+ $over{'disk'}{$1}{'used'}=$2;
+ $over{'disk'}{$1}{'soft'}=$3;
+ $over{'disk'}{$1}{'hard'}=$4;
+ $over{'disk'}{$1}{'grace'}=$5;
+ }
+ elsif ($_ =~ /([\w\d]+)\s+\-\+\s+[\d\w]+\s+[\d\w]+\s+[\d\w]+\s+([\d\w]+)\s+([\d\w]+)\s+([\d\w]+)\s+([\d\w]+)/)
+ {
+ $count++;
+
+ $over{'inode'}{$1}{'used'}=$2;
+ $over{'inode'}{$1}{'soft'}=$3;
+ $over{'inode'}{$1}{'hard'}=$4;
+ $over{'inode'}{$1}{'grace'}=$5;
+ }
+ elsif ($_ =~ /([\w\d]+)\s+\+\+\s+([\d\w]+)\s+([\d\w]+)\s+([\d\w]+)\s+([\d\w]+)\s+([\d\w]+)\s+([\d\w]+)\s+([\d\w]+)\s+([\d\w]+)/)
+ {
+ $count++;
+
+ $over{'disk'}{$1}{'used'}=$2;
+ $over{'disk'}{$1}{'soft'}=$3;
+ $over{'disk'}{$1}{'hard'}=$4;
+ $over{'disk'}{$1}{'grace'}=$5;
+
+ $over{'inode'}{$1}{'used'}=$6;
+ $over{'inode'}{$1}{'soft'}=$7;
+ $over{'inode'}{$1}{'hard'}=$8;
+ $over{'inode'}{$1}{'grace'}=$9;
+ }
+ }
+
+ if ($Detail <= 4)
+ {
+ my @usernames = sort {$a cmp $b} unique((keys(%{$over{'disk'}}),keys(%{$over{'inode'}})));
+ print "Users Over Quota : $count\n";
+ foreach (@usernames)
+ {
+ print " $_";
+ my $len = length($_);
+ while ($len < 10)
+ {
+ print ' ';
+ $len++;
+ }
+ print ' ';
+
+ if ((defined($over{'disk'}{$_}{'grace'})) and (defined($over{'inode'}{$_}{'grace'})))
+ {
+ print $over{'disk'}{$_}{'grace'} . '/' . $over{'inode'}{$_}{'grace'};
+ }
+ elsif(defined($over{'disk'}{$_}{'grace'}))
+ {
+ print $over{'disk'}{$_}{'grace'};
+ }
+ elsif(defined($over{'inode'}{$_}{'grace'}))
+ {
+ print $over{'inode'}{$_}{'grace'};
+ }
+ print "\n";
+ }
+ }
+ else
+ {
+ print "Users Over Quota : $count\n";
+ my @usernames = sort {$a cmp $b} (keys(%{$over{'disk'}}));
+ $count = @usernames;
+ print " Disk: $count\n";
+ foreach (@usernames)
+ {
+ print " $_";
+ my $len = length($_);
+ while ($len < 10)
+ {
+ print ' ';
+ $len++;
+ }
+ print " $over{'disk'}{$_}{'grace'}\n";
+ }
+ @usernames= sort {$a cmp $b} (keys(%{$over{'inode'}}));
+ $count = @usernames;
+ print " Inode: $count\n";
+ foreach (@usernames)
+ {
+ print " $_";
+ my $len = length($_);
+ while ($len < 10)
+ {
+ print ' ';
+ $len++;
+ }
+ print " $over{'inode'}{$_}{'grace'}\n";
+ }
+
+ }
+
+ }
+
+
+sub unique
+ {
+ my %hash;
+ @hash{@_}=();
+
+ return keys(%hash);
+ }
+
--- quota.conf 2008-05-12 10:37:04.000000000 -0500
+++ quota.conf 2008-05-12 10:36:35.000000000 -0500
@@ -0,0 +1,15 @@
+# You can put comments anywhere you want to. They are effective for the
+# rest of the line.
+
+# this is in the format of <name> = <value>. Whitespace at the beginning
+# and end of the lines is removed. Whitespace before and after the = sign
+# is removed. Everything is case *insensitive*.
+
+# Yes = True = On = 1
+# No = False = Off = 0
+
+Title = "repquota"
+
+# Which logfile group...
+LogFile = NONE
+