1 | <?php |
||
8 | |||
9 | final class FreeSpace extends \SimpleSAML\Module\monitor\TestCaseFactory |
||
10 | { |
||
11 | /** |
||
12 | * @var string|null |
||
13 | */ |
||
14 | private $path = null; |
||
15 | |||
16 | /** |
||
17 | * @var TestData $testData |
||
18 | * |
||
19 | * @return void |
||
20 | */ |
||
21 | protected function initialize($testData) |
||
22 | { |
||
23 | $this->setPath($testData->getInput('path')); |
||
24 | $this->setCategory($testData->getInput('category')); |
||
25 | parent::initialize($testData); |
||
26 | } |
||
27 | |||
28 | /** |
||
29 | * @return void |
||
30 | */ |
||
31 | private function setPath($path) |
||
32 | { |
||
33 | assert(is_string($path)); |
||
34 | $this->path = $path; |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * @return string |
||
39 | */ |
||
40 | private function getPath() |
||
41 | { |
||
42 | assert(is_string($this->path)); |
||
43 | return $this->path; |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @return void |
||
48 | */ |
||
49 | protected function invokeTest() |
||
50 | { |
||
51 | $path = $this->getPath(); |
||
52 | $testResult = new TestResult($this->getCategory(), $path) |
||
53 | |||
54 | $size = disk_total_space($path); |
||
|
|||
55 | $used = $size - disk_free_space($path); |
||
56 | $free = round(100 - (($used / $size) * 100)); |
||
57 | $testResult->addOutput($free, 'free_percentage'); |
||
58 | |||
59 | if ($free >= 15) { |
||
60 | $testResult->setMessage($free . '% free space'); |
||
61 | $testResult->setState(State::OK); |
||
62 | } else if ($free < 5) { |
||
63 | $testResult->setMessage('Critical: ' . $free . '% free space'); |
||
64 | $testResult->setState(State::ERROR); |
||
65 | } else { |
||
66 | $testResult->setMessage($free . '% free space'); |
||
67 | $testResult->setState(State::WARNING); |
||
68 | } |
||
72 |