#!/usr/bin/perl
use strict;
use Net::SMTP;
use Time::Local;
# Set threshold Values for sendmail
my $full = 90;
my $warn = 95;
my @array=();
#print $hostname,"\n";
open(DF,"df -h -P $ARGV[0] -T | grep ext |");
foreach (<DF>) {
chomp($_);
if ($_ =~ /($ARGV[0]).*\s+(\d+)\%.*$/) {
if ($2 > $full) {
push(@array,$_);
}
}
}
# Used Net::SMTP modules
if (scalar(@array) > 0) {
#my $smtp = Net::SMTP->new(${smtp_server});
$smtp = Net::SMTP->new(${smtp_server}, Timeout => 60);
$smtp->mail(${from_mail});
$smtp->to(${to_mail});
$smtp->data();
$smtp->datasend("To:${to_mail}\n");
$smtp->datasend("From:${from_mail}\n");
$smtp->datasend("Subject:Disk almost full on $hostname ($time)\n");
$smtp->datasend("\n");
foreach (@array) {
$smtp->datasend("$_\n");
}
$smtp->datasend();
$smtp->quit;
}
if ($dmesg =~ /error/i) {
$smtp = Net::SMTP->new(${smtp_server}, Timeout => 60);
$smtp->mail(${from_mail});
$smtp->to(${to_mail});
$smtp->data();
$smtp->datasend("To:${to_mail}\n");
$smtp->datasend("From:${from_mail}\n");
$smtp->datasend("Subject:Hardware error on $hostname ($time)!!!\n");
$smtp->datasend("\n");
$smtp->datasend("$hostname needs to be checked right now!\n");
$smtp->datasend();
$smtp->quit;
}