-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdf.php
More file actions
59 lines (48 loc) · 2.03 KB
/
Copy pathdf.php
File metadata and controls
59 lines (48 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/* licence */
/*
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 3 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, see <http://www.gnu.org/licenses/>.
*/
/* ***************************************************************** */
/* configuration */
$critical = 90; // use thresold for turning on reports
$to = 'your@email.com'; // report destination email address
$from = 'your@email.com'; // report sender email address
/* ***************************************************************** */
$report = ''; // text report, to be displayed or sent over e-mail
$hostname = exec('hostname'); // reads host name from system
$res = exec('df -h', $output); // gets human readable disk use for all partitions
foreach($output as $k => $line){
// if partition matches a filesystem mount point
if (preg_match('/(\/[a-z0-9\/\-]+).+ ([0-9]+)\%/msi', $line, $use)){
// if use is greater than critical thresold
if ($use[2]>=$critical){
$report .= $use[1]; // device
$report .= ': use is now ';
$report .= $use[2]; // use %
$report .= "%\n";
}
}
}
// if report features at least one critical partition
if ($report != ''){
$subject = $hostname.' df alert';
$report = $subject."\n".$report;
echo $report;
// turn on email reporting if $to is set
if (!empty($to)){
$headers = 'From: '.$from . "\r\n" .
'Reply-To: ' . $from ."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $report, $headers);
}
}