|
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\Helper\TableCell; |
|
16
|
|
|
use Symfony\Component\Console\Helper\TableSeparator; |
|
17
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
18
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
19
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
20
|
|
|
use Symfony\Component\Console\Helper\Table; |
|
21
|
|
|
use Tvi\MonitorBundle\Reporter\Console; |
|
22
|
|
|
use Tvi\MonitorBundle\Runner\RunnerManager; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
|
|
|
|
|
25
|
|
|
* @author Vladimir Turnaev <[email protected]> |
|
26
|
|
|
*/ |
|
|
|
|
|
|
27
|
|
|
class CheckInfoCommand extends Command |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
|
|
|
|
|
30
|
|
|
* @var Manager |
|
|
|
|
|
|
31
|
|
|
*/ |
|
32
|
|
|
private $runnerManager; |
|
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
/** |
|
|
|
|
|
|
35
|
|
|
* @param ?string $name |
|
|
|
|
|
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct(RunnerManager $runnerManager, string $name = null) |
|
38
|
|
|
{ |
|
39
|
|
|
parent::__construct($name); |
|
40
|
|
|
$this->runnerManager = $runnerManager; |
|
|
|
|
|
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
protected function configure() |
|
|
|
|
|
|
44
|
|
|
{ |
|
45
|
|
|
$this |
|
46
|
|
|
->setName( |
|
47
|
|
|
'tvi:monitor:check:info' |
|
48
|
|
|
) |
|
49
|
|
|
->setDescription( |
|
50
|
|
|
'Info health checks' |
|
51
|
|
|
) |
|
52
|
|
|
->addOption( |
|
53
|
|
|
'check', |
|
54
|
|
|
'c', |
|
55
|
|
|
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, |
|
56
|
|
|
'Check filter' |
|
57
|
|
|
) |
|
58
|
|
|
->addOption( |
|
59
|
|
|
'group', |
|
60
|
|
|
'g', |
|
61
|
|
|
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, |
|
62
|
|
|
'Groups filter' |
|
63
|
|
|
) |
|
64
|
|
|
->addOption( |
|
65
|
|
|
'tag', |
|
66
|
|
|
't', |
|
67
|
|
|
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, |
|
68
|
|
|
'Tag(s) filter' |
|
69
|
|
|
) |
|
70
|
|
|
->setHelp( |
|
71
|
|
|
<<<'EOT' |
|
72
|
|
|
The <info>%command.name%</info> get check info |
|
73
|
|
|
|
|
74
|
|
|
* INfo Checks: |
|
75
|
|
|
|
|
76
|
|
|
<info>php %command.full_name% [--check=... ,] [--group=... ,] [--tag==... ,] </info> |
|
77
|
|
|
|
|
78
|
|
|
EOT |
|
79
|
|
|
); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
|
|
|
|
|
83
|
|
|
* @return int|null|void |
|
84
|
|
|
*/ |
|
85
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
86
|
|
|
{ |
|
87
|
|
|
$checkFilter = $input->getOption('check'); |
|
88
|
|
|
$groupFilter = $input->getOption('group'); |
|
89
|
|
|
$tagFilter = $input->getOption('tag'); |
|
90
|
|
|
|
|
91
|
|
|
$checks = $this->runnerManager->findChecksSorted($checkFilter, $groupFilter, $tagFilter); |
|
92
|
|
|
|
|
93
|
|
|
$table = new Table($output); |
|
94
|
|
|
$table->setHeaders(['Check', 'Tag(s)', 'Label']); |
|
95
|
|
|
|
|
96
|
|
|
$groupOld = null; |
|
97
|
|
|
foreach ($checks as $check) { |
|
98
|
|
|
$tags = $check->getTags(); |
|
99
|
|
|
|
|
100
|
|
|
if ($tags) { |
|
101
|
|
|
$tags = $this->runnerManager->findTags($check->getTags()); |
|
102
|
|
|
$tags = array_map(static function ($t) { |
|
|
|
|
|
|
103
|
|
|
return $t->getLabel(); |
|
104
|
|
|
}, $tags); |
|
|
|
|
|
|
105
|
|
|
|
|
106
|
|
|
$tags = implode(', ', $tags); |
|
107
|
|
|
} else { |
|
108
|
|
|
$tags = null; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
$group = null; |
|
112
|
|
|
$groupNew = sprintf('<fg=default;options=bold>%s</>', $check->getGroup()); |
|
113
|
|
|
|
|
114
|
|
|
if ($groupOld !== $groupNew) { |
|
115
|
|
|
if ($groupOld) { |
|
116
|
|
|
$table->addRow(new TableSeparator()); |
|
117
|
|
|
} |
|
118
|
|
|
$table->addRow([new TableCell($groupNew, ['colspan' => 3])]); |
|
119
|
|
|
$table->addRow(new TableSeparator()); |
|
120
|
|
|
|
|
121
|
|
|
$group = $groupOld = $groupNew; |
|
|
|
|
|
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
$importanceTag = Console::tagByImportance($check->getImportance()); |
|
125
|
|
|
$id = sprintf('%s%s</>', $importanceTag, $check->getId()); |
|
126
|
|
|
$table->addRow([$id, $tags, $check->getLabel()]); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
$table->render(); |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|