|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the `tvi/monitor-bundle` project. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) https://github.com/turnaev/monitor-bundle/graphs/contributors |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE.md |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
namespace Tvi\MonitorBundle\Reporter; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\Console\Output\ConsoleOutput; |
|
15
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
16
|
|
|
use ZendDiagnostics\Check\CheckInterface; |
|
17
|
|
|
use ZendDiagnostics\Result\ResultInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
|
|
|
|
|
20
|
|
|
* @author Kevin Bond <[email protected]>, Vladimir Turnaev <[email protected]> |
|
|
|
|
|
|
21
|
|
|
*/ |
|
|
|
|
|
|
22
|
|
|
class Nagius extends ReporterAbstract |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
|
|
|
|
|
25
|
|
|
* @var OutputInterface |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $output; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
|
|
|
|
|
30
|
|
|
* @param OutputInterface $output |
|
|
|
|
|
|
31
|
|
|
*/ |
|
32
|
100 |
|
public function __construct(OutputInterface $output = null) |
|
33
|
|
|
{ |
|
34
|
100 |
|
if (null === $output) { |
|
35
|
99 |
|
$output = new ConsoleOutput(); |
|
36
|
|
|
} |
|
37
|
100 |
|
$this->output = $output; |
|
38
|
100 |
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
|
|
|
|
|
41
|
|
|
* {@inheritdoc} |
|
42
|
|
|
*/ |
|
|
|
|
|
|
43
|
1 |
|
public function onAfterRun(CheckInterface $check, ResultInterface $result, $checkAlias = null) |
|
44
|
|
|
{ |
|
45
|
1 |
|
list($_, $code) = $this->getStatusByResul($result); |
|
46
|
|
|
|
|
47
|
1 |
|
$statusOut = $this->statusByCode($code); |
|
48
|
1 |
|
$this->output->writeln(sprintf("%-8s\t%-25s\t%s", $statusOut, $check->getId(), $check->getLabel())); |
|
|
|
|
|
|
49
|
1 |
|
} |
|
50
|
|
|
|
|
51
|
1 |
|
protected function statusByCode($code): string |
|
|
|
|
|
|
52
|
|
|
{ |
|
53
|
|
|
$tags = [ |
|
54
|
1 |
|
self::STATUS_CODE_SUCCESS => 'OK', |
|
55
|
1 |
|
self::STATUS_CODE_WARNING => 'WARNING', |
|
56
|
1 |
|
self::STATUS_CODE_SKIP => 'SKIP', |
|
57
|
1 |
|
self::STATUS_CODE_FAILURE => 'FAIL', |
|
58
|
1 |
|
'default' => 'FAIL', |
|
59
|
|
|
]; |
|
60
|
|
|
|
|
61
|
1 |
|
return $tags[$code] ?? $tags['default']; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|