50 lines
1 KiB
PHP
Executable file
50 lines
1 KiB
PHP
Executable file
#!/usr/bin/env php
|
|
<?php
|
|
|
|
require __DIR__.'/base/block.php';
|
|
|
|
$name = $argv[1] ?? 'root';
|
|
$mountPoint = $argv[2] ?? '/';
|
|
$range1 = $argv[3] ?? 70;
|
|
$range2 = $argv[4] ?? 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');
|
|
}
|
|
|
|
if (getenv('BLOCK_BUTTON') === '1') {
|
|
$command = 'export DISPLAY=:0; xdg-open '.escapeshellarg('file://'.$mountPoint).'&';
|
|
pclose(popen($command, 'r'));
|
|
}
|
|
|
|
$fullText = pspan($mountPoint, '#ccc', '#222').pspan($percent.'%', $color, '#000');
|
|
|
|
echo block(
|
|
'mount_point_space_'.$name,
|
|
[
|
|
'full_text' => $fullText,
|
|
'color' => $color,
|
|
'separator' => false,
|
|
'separator_block_width' => 0,
|
|
]
|
|
);
|