Updated %dosdrv.

Fixed parsing of repquota for Linux (gracetime).
Added proper MIME headers to warning mail.
The usage graph is now always updated if the user is over quota, even if
no warning mail is sent.
If a user is over quota on several filesystems, he now gets one mail for
each filesystem - previously he only got a mail for the first filesystem.
This commit is contained in:
hjp 2004-10-08 10:35:50 +00:00
parent 9d6f178d2e
commit fd3d3341ca
1 changed files with 35 additions and 25 deletions

View File

@ -10,8 +10,10 @@ my $hostname;
sub warnmsg { sub warnmsg {
my ($mount, $usage, $soft, $hard, $grace, $unit, $user) = @_; my ($mount, $usage, $soft, $hard, $grace, $unit, $user) = @_;
my %dosdrv = ( my %dosdrv = (
'/wsrdb/users' => 'J:', '/common' => 'H:',
'/usr/local/www' => 'W:', '/wsrdb/users' => 'J:',
'/fc4700' => 'K:',
'/usr/local/www' => 'W:',
); );
my $wo; my $wo;
@ -25,10 +27,10 @@ sub warnmsg {
my $msg = "Sie haben auf $wo Ihr in Disk Quotas gesetztes Limit\n" . my $msg = "Sie haben auf $wo Ihr in Disk Quotas gesetztes Limit\n" .
"überschritten. \n"; "überschritten. \n";
if ($grace eq "EXPIRED" or $usage >= $hard-2) { if ($grace eq "EXPIRED" or $grace eq "none" or $usage >= $hard-2) {
$msg .= "Sie können dort KEINE Files mehr anlegen.\n" ; $msg .= "Sie können dort KEINE Files mehr anlegen.\n" ;
} else { } else {
$grace =~ s/days/Tage/g; $grace =~ s/ *days/ Tage/g;
$grace =~ s/hours/Stunden/g; $grace =~ s/hours/Stunden/g;
$msg .= "Sie können noch " . $msg .= "Sie können noch " .
(int (($hard - $usage) * 10 + 0.5) / 10) . " $unit anlegen.\n" ; (int (($hard - $usage) * 10 + 0.5) / 10) . " $unit anlegen.\n" ;
@ -42,9 +44,9 @@ sub warnmsg {
"\n" . "\n" .
"Sie können sich Ihre Verbrauchsgraphen unter\n" . "Sie können sich Ihre Verbrauchsgraphen unter\n" .
"http://sww.wsr.ac.at/intranet/quotas/$user$mount_t.gif ansehen. \n" . "http://sww.wsr.ac.at/intranet/quotas/$user$mount_t.gif ansehen. \n" .
"Der Graph zeigten den verbrauchten Platz ("used") sowie die beiden\n" . "Der Graph zeigten den verbrauchten Platz ('used') sowie die beiden\n" .
"Quotas ("soft" und "hard")\n" . "Quotas ('soft' und 'hard')\n" .
"Die Softquota können Sie kurzfristig (bis zu einer Woche) überschreiten\n" . "Die Softquota können Sie kurzfristig (bis zu einer Woche) überschreiten,\n" .
"die Hardquota nicht.\n" . "die Hardquota nicht.\n" .
"\n" . "\n" .
"Lassen Sie sich bei Gelegenheit auch von einem der zuständigen\n" . "Lassen Sie sich bei Gelegenheit auch von einem der zuständigen\n" .
@ -61,17 +63,6 @@ sub sendmail
{ {
my ($user, $msg, $mount) = @_; my ($user, $msg, $mount) = @_;
my @startgraph=
("/usr/local/dfstat/quotagraph",
"--fs=$mount",
"--user=$user",
"--data=b",
glob("/usr/local/dfstat/quota.stat.????-??")
);
if (system (@startgraph) != 0) {
die "cannot execute @startgraph";
}
if ($opts{'d'}) { if ($opts{'d'}) {
open (SENDMAIL, ">&1"); open (SENDMAIL, ">&1");
} else { } else {
@ -90,6 +81,9 @@ sub sendmail
print SENDMAIL "Content-Type: text/plain; charset=iso-8859-1\r\n"; print SENDMAIL "Content-Type: text/plain; charset=iso-8859-1\r\n";
print SENDMAIL "Content-Encoding: 8bit\r\n"; print SENDMAIL "Content-Encoding: 8bit\r\n";
print SENDMAIL "Reply-To: <system\@wsr.ac.at>\r\n"; print SENDMAIL "Reply-To: <system\@wsr.ac.at>\r\n";
print SENDMAIL "MIME-Version: 1.0\r\n";
print SENDMAIL "Content-Type: text/plain; charset=iso-8859-1\r\n";
print SENDMAIL "Content-Transfer-Encoding: 8bit\r\n";
print SENDMAIL "\r\n"; print SENDMAIL "\r\n";
print SENDMAIL "$msg\r\n"; print SENDMAIL "$msg\r\n";
} }
@ -111,9 +105,13 @@ my @df = split(/\n/, $df);
for my $ln (@df) { for my $ln (@df) {
my ($fs, $total, $used, $free, $pct, $mount) = split(/\s+/, $ln); my ($fs, $total, $used, $free, $pct, $mount) = split(/\s+/, $ln);
if ($fs =~ m|^/dev/|) { if ($fs =~ m|^/dev/|) {
my $mount_t = $mount;
$mount_t =~ s|/|_|g;
open REPQUOTA, "@@@repquota@@@ $mount 2>/dev/null |" or die "cannot call @@@repquota@@@: $!"; open REPQUOTA, "@@@repquota@@@ $mount 2>/dev/null |" or die "cannot call @@@repquota@@@: $!";
my $hpuxtime = '(?:NOT\sSTARTED|EXPIRED|\d+\.\d+\ (?:days|hours))';
my $linuxtime = '(?:none|\d+\:\d+|\d+days)';
while (<REPQUOTA>) { while (<REPQUOTA>) {
next if ($. <= 2); # ignore header lines next unless (/\b\d+\b/); # ignore header lines
my $msg = ""; my $msg = "";
my $user; my $user;
if (/(\w+) \s+ -- \s* if (/(\w+) \s+ -- \s*
@ -123,7 +121,7 @@ for my $ln (@df) {
$user = $1; $user = $1;
#print "ok: $1\n"; #print "ok: $1\n";
} elsif (/(\w+) \s+ \+- \s* } elsif (/(\w+) \s+ \+- \s*
(\d+)\s+(\d+)\s+(\d+)\s+(NOT\sSTARTED|EXPIRED|\d+\.\d+\ (?:days|hours))\s+ (\d+)\s+(\d+)\s+(\d+)\s+($hpuxtime|$linuxtime)\s+
(\d+)\s+(\d+)\s+(\d+) (\d+)\s+(\d+)\s+(\d+)
/x) { /x) {
print "block limit: $1: $2 > ($3 $4) $5\n"; print "block limit: $1: $2 > ($3 $4) $5\n";
@ -132,14 +130,14 @@ for my $ln (@df) {
} elsif (/(\w+) \s+ -\+ \s* } elsif (/(\w+) \s+ -\+ \s*
(\d+)\s+(\d+)\s+(\d+)\s+ (\d+)\s+(\d+)\s+(\d+)\s+
(\d+)\s+(\d+)\s+(\d+)\s+(NOT\sSTARTED|EXPIRED|\d+\.\d+\ (?:days|hours)) (\d+)\s+(\d+)\s+(\d+)\s+(NOT\sSTARTED|EXPIRED|\d+\.\d+\ ?(?:days|hours))
/x) { /x) {
print "file limit: $1: $5 > ($6 $7) $8\n"; print "file limit: $1: $5 > ($6 $7) $8\n";
$user = $1; $user = $1;
$msg = warnmsg($mount, $5, $6, $7, $8, "Files", $user); $msg = warnmsg($mount, $5, $6, $7, $8, "Files", $user);
} elsif (/(\w+) \s+ \+\+ \s* } elsif (/(\w+) \s+ \+\+ \s*
(\d+)\s+(\d+)\s+(\d+)\s+(NOT\sSTARTED|EXPIRED|\d+\.\d+\ (?:days|hours))\s+ (\d+)\s+(\d+)\s+(\d+)\s+($hpuxtime|$linuxtime)\s+
(\d+)\s+(\d+)\s+(\d+)\s+(NOT\sSTARTED|EXPIRED|\d+\.\d+\ (?:days|hours)) (\d+)\s+(\d+)\s+(\d+)\s+($hpuxtime|$linuxtime)
/x) { /x) {
print "block limit: $1: $2 > ($3 $4) $5\n"; print "block limit: $1: $2 > ($3 $4) $5\n";
$user = $1; $user = $1;
@ -151,7 +149,19 @@ for my $ln (@df) {
next; next;
} }
if ($msg) { if ($msg) {
my $timestamp = "/usr/local/dfstat/quotacheck-timestamps/$user"; my $timestamp = "/usr/local/dfstat/quotacheck-timestamps/$user$mount_t";
my @startgraph=
("/usr/local/dfstat/quotagraph",
"--fs=$mount",
"--user=$user",
"--data=b",
glob("/usr/local/dfstat/quota.stat.????-??")
);
if (system (@startgraph) != 0) {
die "cannot execute @startgraph";
}
system("scp", "/usr/local/www/wsr/intranet/quotas/$user$mount_t.gif", "sww.wsr.ac.at:/usr/local/www/wsr/intranet/quotas/$user$mount_t.gif");
if (!-e $timestamp) { if (!-e $timestamp) {
sendmail($user, $msg, $mount); sendmail($user, $msg, $mount);
@ -171,7 +181,7 @@ for my $ln (@df) {
} }
} }
else{ else{
my @deletemsg = ("/usr/local/dfstat/quotacheck-timestamps/$user"); my @deletemsg = ("/usr/local/dfstat/quotacheck-timestamps/$user$mount_t");
unlink (@deletemsg); unlink (@deletemsg);
} }
} }