44 lines
869 B
PHP
44 lines
869 B
PHP
|
#!/usr/bin/php
|
||
|
<?php
|
||
|
|
||
|
require __DIR__.'/base/block.php';
|
||
|
|
||
|
$mountPoint = $argv[1] ?? '/';
|
||
|
$range1 = $argv[2] ?? 70;
|
||
|
$range2 = $argv[3] ?? 90;
|
||
|
|
||
|
$command = sprintf(
|
||
|
'df -h %s | tail -n 1',
|
||
|
escapeshellcmd($mountPoint)
|
||
|
);
|
||
|
|
||
|
$result = trim(shell_exec($command));
|
||
|
|
||
|
if (empty($result)) {
|
||
|
die;
|
||
|
}
|
||
|
|
||
|
list($dev, $size, $used, $free, $usedP, $point) = explode(' ', preg_replace('/\s+/', ' ', $result));
|
||
|
|
||
|
$percent = intval($usedP);
|
||
|
|
||
|
if ($percent < $range1) {
|
||
|
$color = color('normal');
|
||
|
} elseif ($percent < $range2) {
|
||
|
$color = color('warning');
|
||
|
} else {
|
||
|
$color = color('critical');
|
||
|
}
|
||
|
|
||
|
$fullText = sprintf('[%s] %s%%', $mountPoint, $percent);
|
||
|
$shortText = sprintf('%s: %s%%', $mountPoint, $percent);
|
||
|
|
||
|
echo block(
|
||
|
'mount_point_space_'.$mountPoint,
|
||
|
[
|
||
|
'full_text' => $fullText,
|
||
|
'short_text' => $shortText,
|
||
|
'color' => $color,
|
||
|
]
|
||
|
);
|