forked from liip/LiipMonitorBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArrayReporter.php
104 lines (89 loc) · 2.54 KB
/
ArrayReporter.php
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
namespace Liip\MonitorBundle\Helper;
use Laminas\Diagnostics\Check\CheckInterface;
use Laminas\Diagnostics\Result\Collection as ResultsCollection;
use Laminas\Diagnostics\Result\ResultInterface;
use Laminas\Diagnostics\Result\SkipInterface;
use Laminas\Diagnostics\Result\SuccessInterface;
use Laminas\Diagnostics\Result\WarningInterface;
use Laminas\Diagnostics\Runner\Reporter\ReporterInterface;
/**
* @author Kevin Bond <[email protected]>
*/
class ArrayReporter implements ReporterInterface
{
public const STATUS_OK = 'OK';
public const STATUS_KO = 'KO';
private $globalStatus = self::STATUS_OK;
private $results = [];
private $checkRunTime = 0;
public function getResults(): array
{
return $this->results;
}
public function getGlobalStatus(): string
{
return $this->globalStatus;
}
/**
* @return bool|void
*/
public function onAfterRun(CheckInterface $check, ResultInterface $result, $checkAlias = null)
{
switch (true) {
case $result instanceof SuccessInterface:
$status = 0;
$statusName = 'check_result_ok';
break;
case $result instanceof WarningInterface:
$status = 1;
$statusName = 'check_result_warning';
$this->globalStatus = self::STATUS_KO;
break;
case $result instanceof SkipInterface:
$status = 2;
$statusName = 'check_result_skip';
break;
default:
$status = 3;
$statusName = 'check_result_critical';
$this->globalStatus = self::STATUS_KO;
}
$this->results[] = [
'checkName' => $check->getLabel(),
'message' => $result->getMessage(),
'status' => $status,
'status_name' => $statusName,
'service_id' => $checkAlias,
'duration' => microtime(true) - $this->checkRunTime,
];
}
/**
* @return void
*/
public function onStart(\ArrayObject $checks, $runnerConfig)
{
return;
}
/**
* @return bool|void
*/
public function onBeforeRun(CheckInterface $check, $checkAlias = null)
{
$this->checkRunTime = microtime(true);
}
/**
* @return void
*/
public function onStop(ResultsCollection $results)
{
return;
}
/**
* @return void
*/
public function onFinish(ResultsCollection $results)
{
return;
}
}