File: //ibin/diskcheck.pl
#!/usr/bin/perl
#
# DiskCheck 3.1.1 (11/18/98)
#
# This program was originally written by Kirk Bauer (kirk@kaybee.org).
# Some additions/changes have been made by Benjamin Cabell (q98@besiex.org).
#
# Kirk's disclaimer:
# First of all, I am *NOT* responsible for anything bad that might happen
# because of this program. It doesn't do anything bad on my system, but
# it is not my fault if it does something bad on your system.
#
# Benjamin's Disclaimer:
# (see Kirk's).
# Modified: 10/21/2022 - Enhanced email to html REAL
require '/etc/diskcheck.conf' || die "Config File Not Found";
$hostname = `hostname`;
chomp($hostname);
# Jack
#($hostname, $domain, $extension) = (split /\./, $hostname);
@list=`df -m $ignore`;
($null, $blocksize, $null, $null, $null, $null, $null) = split (/\s+/, shift(@list));
$blocksize =~ s/-blocks$//;
open(MFILE, ">$tempfile.$$");
print MFILE "To: $mailto\n";
print MFILE "From: $mailfrom\n";
print MFILE "Content-type: text/html\n";
print MFILE "Subject: WARNING: Disk usage high on $hostname!!!\n";
$high = 0;
#print MFILE "Disk usage for $hostname:\n\n";
# Table Header
print MFILE "<table border='1' cellpadding='4'>";
print MFILE "<tr bgcolor='#99ccff'><th colspan=\"5\">Innovative Disk Report for $hostname</th></tr>";
print MFILE "<tr bgcolor='#99ccff'><td>Volume</td><td>MountPoint</td><td>Space</td><td>Free</td><td>C</td></tr>";
for (@list) {
($volume, $total, $used, $available, $pct, $mountPoint) = split (/\s+/);
chop($pct);
chomp($mountPoint);
if ( $exclude !~ m=$volume= ) {
if ($Cutoff{$volume} ) {
if ($pct >= $Cutoff{$volume}) {
$high = 1;
# print MFILE "$volume ($mountPoint) is $pct% full -- $used 1of $total $blocksize-blocks used, $available remain\n";
# print MFILE "{$hostname Disk $volume ($mountPoint) is $pct% full - $available MB remain(1)}\n";
&message_print("1");
}
}
elsif ($Cutoff{$mountPoint} ) {
if ($pct >= $Cutoff{$mountPoint}) {
$high = 1;
# print MFILE "$volume ($mountPoint) is $pct% full -- $used 2of $total $blocksize-blocks used, $available remain\n";
# print MFILE "{$hostname Disk $volume ($mountPoint) is $pct% full - $available MB remain(2)}\n";
&message_print("2");
}
}
elsif ($pct >= $DefaultCutoff) {
$high = 1;
# print MFILE "$volume ($mountPoint) is $pct% full -- $used 3of $total $blocksize-blocks used, $available remain\n\n";
# print MFILE "{$hostname Disk $volume ($mountPoint) is $pct% full - $available MB remain(3)}\n\n";
&message_print("3");
}
}
}
print MFILE "</table>";
close (MFILE);
if ($high != 0) {
#mail the message
open(MAIL,"|$mailprog -t");
open(MFILE, "$tempfile.$$") || die "Can't open $tempfile.$$!";
while(<MFILE>) {
print MAIL $_;
}
close (MFILE);
}
sub message_print {
$process=$_[0];
# print MFILE "Vol: $volume \tMP: [$mountPoint] \t\t$pct% full - $available MB ..... Code: $process\n\n";
print MFILE "
<tr><td>$volume</td>
<td>$mountPoint</td>
<td style=\"text-align: right;\">$pct% full</td>
<td style=\"text-align: right;\">$available MB</td>
<td>$process</td>
</tr>";
# print MFILE "$volume ($mountPoint) is $pct% full -- $used 3of $total $blocksize-blocks used, $available remain\n\n";
# print MFILE "{$hostname Disk $volume ($mountPoint) is $pct% full - $available MB remain(3)}\n\n";
}
unlink ("$tempfile.$$");
exit(0);