|
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\Command; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\Console\Command\Command; |
|
15
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
16
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
17
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
18
|
|
|
use Tvi\MonitorBundle\Runner\RunnerManager; |
|
19
|
|
|
use Tvi\MonitorBundle\Reporter\ReporterManager; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
|
|
|
|
|
22
|
|
|
* @author Vladimir Turnaev <[email protected]> |
|
23
|
|
|
*/ |
|
|
|
|
|
|
24
|
|
|
class CheckHealthCommand extends Command |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
|
|
|
|
|
27
|
|
|
* @var RunnerManager |
|
28
|
|
|
*/ |
|
29
|
|
|
private $runnerManager; |
|
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
/** |
|
|
|
|
|
|
32
|
|
|
* @var ReporterManager |
|
33
|
|
|
*/ |
|
34
|
|
|
private $reporterManager; |
|
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
/** |
|
|
|
|
|
|
37
|
|
|
* @param ?string $name |
|
|
|
|
|
|
38
|
|
|
*/ |
|
39
|
|
|
public function __construct(ReporterManager $reporterRunnerManager, RunnerManager $runnerManager, string $name = null) |
|
40
|
|
|
{ |
|
41
|
|
|
$this->reporterManager = $reporterRunnerManager; |
|
42
|
|
|
$this->runnerManager = $runnerManager; |
|
43
|
|
|
|
|
44
|
|
|
parent::__construct($name); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
protected function configure() |
|
|
|
|
|
|
48
|
|
|
{ |
|
49
|
|
|
$reporterAliases = $this->reporterManager->getReporterAliases('console'); |
|
50
|
|
|
$reporterAliases = implode(', ', $reporterAliases); |
|
51
|
|
|
$this |
|
52
|
|
|
->setName( |
|
53
|
|
|
'tvi:monitor:check:run' |
|
54
|
|
|
) |
|
55
|
|
|
->setDescription( |
|
56
|
|
|
'Runs health checks' |
|
57
|
|
|
) |
|
58
|
|
|
->addOption( |
|
59
|
|
|
'check', |
|
60
|
|
|
'c', |
|
61
|
|
|
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, |
|
62
|
|
|
'Check filter' |
|
63
|
|
|
) |
|
64
|
|
|
->addOption( |
|
65
|
|
|
'reporter', |
|
66
|
|
|
'r', |
|
67
|
|
|
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
|
68
|
|
|
"Additional reporters to run. Use reporter(s) [{$reporterAliases}].", |
|
69
|
|
|
['console'] |
|
70
|
|
|
) |
|
71
|
|
|
->addOption( |
|
72
|
|
|
'group', |
|
73
|
|
|
'g', |
|
74
|
|
|
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, |
|
75
|
|
|
'Groups filter' |
|
76
|
|
|
) |
|
77
|
|
|
->addOption( |
|
78
|
|
|
'tag', |
|
79
|
|
|
't', |
|
80
|
|
|
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, |
|
81
|
|
|
'Tag(s) filter' |
|
82
|
|
|
) |
|
83
|
|
|
->addOption( |
|
84
|
|
|
'break-on-failure', |
|
85
|
|
|
'b', |
|
86
|
|
|
InputOption::VALUE_NONE, |
|
87
|
|
|
'Break checking on any check failure.' |
|
88
|
|
|
) |
|
89
|
|
|
->setHelp( |
|
90
|
|
|
<<<'EOT' |
|
91
|
|
|
The <info>%command.name%</info> get check info |
|
92
|
|
|
|
|
93
|
|
|
* INfo Checks: |
|
94
|
|
|
|
|
95
|
|
|
<info>php %command.full_name% [--check=... ,] [--group=... ,] [--tag==... ,] [--break-on-failure]</info> |
|
96
|
|
|
|
|
97
|
|
|
EOT |
|
98
|
|
|
); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
|
|
|
|
|
102
|
|
|
* @return int|null|void |
|
103
|
|
|
*/ |
|
104
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
105
|
|
|
{ |
|
106
|
|
|
$checkFilter = $input->getOption('check'); |
|
107
|
|
|
$groupFilter = $input->getOption('group'); |
|
108
|
|
|
$tagFilter = $input->getOption('tag'); |
|
109
|
|
|
$breakOnFailure = $input->getOption('break-on-failure', false); |
|
|
|
|
|
|
110
|
|
|
|
|
111
|
|
|
$runner = $this->runnerManager->getRunner($checkFilter, $groupFilter, $tagFilter); |
|
112
|
|
|
$runner->setBreakOnFailure($breakOnFailure); |
|
113
|
|
|
|
|
114
|
|
|
$reporters = $input->getOption('reporter'); |
|
115
|
|
|
foreach ($reporters as $reporterAlias) { |
|
116
|
|
|
$reporter = $this->reporterManager->getReporter($reporterAlias); |
|
117
|
|
|
if ($reporter) { |
|
118
|
|
|
$runner->addReporter($reporter); |
|
119
|
|
|
} else { |
|
120
|
|
|
$output->writeln(sprintf('Reporter <info>"%s"</info> not found, skip it.', $reporterAlias)); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
$runner->run(); |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|