|
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\Manager; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
|
|
|
|
|
21
|
|
|
* @author Vladimir Turnaev <[email protected]> |
|
22
|
|
|
*/ |
|
|
|
|
|
|
23
|
|
|
class CheckInfoCommand extends Command |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
|
|
|
|
|
26
|
|
|
* @var Manager |
|
27
|
|
|
*/ |
|
28
|
|
|
private $manager; |
|
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
/** |
|
|
|
|
|
|
31
|
|
|
* @param Manager $manager |
|
|
|
|
|
|
32
|
|
|
* @param null $name |
|
|
|
|
|
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct(Manager $manager, string $name = null) |
|
35
|
|
|
{ |
|
36
|
|
|
parent::__construct($name); |
|
37
|
|
|
$this->manager = $manager; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
protected function configure() |
|
|
|
|
|
|
41
|
|
|
{ |
|
42
|
|
|
$this |
|
43
|
|
|
->setName('tvi:monitor:check:info') |
|
44
|
|
|
->setDescription('Info Health Checkers') |
|
45
|
|
|
->addOption( |
|
46
|
|
|
'name', |
|
47
|
|
|
'i', |
|
48
|
|
|
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, |
|
49
|
|
|
'Groups filter' |
|
50
|
|
|
) |
|
51
|
|
|
->addOption( |
|
52
|
|
|
'groups', |
|
53
|
|
|
'g', |
|
54
|
|
|
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, |
|
55
|
|
|
'Groups filter' |
|
56
|
|
|
) |
|
57
|
|
|
->addOption( |
|
58
|
|
|
'tags', |
|
59
|
|
|
't', |
|
60
|
|
|
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, |
|
61
|
|
|
'Tags filter' |
|
62
|
|
|
|
|
|
|
|
|
|
63
|
|
|
) |
|
64
|
|
|
->setHelp( |
|
65
|
|
|
<<<EOT |
|
66
|
|
|
The <info>%command.name%</info> get check info |
|
67
|
|
|
|
|
68
|
|
|
* INfo Checks: |
|
69
|
|
|
|
|
70
|
|
|
<info>php %command.full_name% [--alias=... ,] [--groups=... ,] [--tags==... ,] </info> |
|
71
|
|
|
|
|
72
|
|
|
EOT |
|
73
|
|
|
); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
|
|
|
|
|
77
|
|
|
* @param InputInterface $input |
|
|
|
|
|
|
78
|
|
|
* @param OutputInterface $output |
|
|
|
|
|
|
79
|
|
|
* |
|
80
|
|
|
* @return int|null|void |
|
81
|
|
|
*/ |
|
82
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
83
|
|
|
{ |
|
84
|
|
|
$namesFilter = $input->getOption('name'); |
|
85
|
|
|
$namesFilter = ($namesFilter) ? $namesFilter : null; |
|
86
|
|
|
|
|
87
|
|
|
$groupsFilter = $input->getOption('groups'); |
|
88
|
|
|
$groupsFilter = ($groupsFilter) ? $groupsFilter : null; |
|
89
|
|
|
|
|
90
|
|
|
$tagsFilter = $input->getOption('tags'); |
|
91
|
|
|
$tagsFilter = ($tagsFilter) ? $tagsFilter : null; |
|
92
|
|
|
|
|
93
|
|
|
$manager = $this->manager; |
|
94
|
|
|
$checks = $manager->findChecks($namesFilter, $groupsFilter, $tagsFilter); |
|
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
// $output->writeln(''); |
|
97
|
|
|
foreach ($checks as $check) { |
|
98
|
|
|
$tags = $check->getTags(); |
|
99
|
|
|
if ($tags) { |
|
100
|
|
|
$tags = implode(', ',$check->getTags()); |
|
101
|
|
|
$tags = "[$tags]"; |
|
102
|
|
|
} else { |
|
103
|
|
|
$tags = null; |
|
104
|
|
|
} |
|
105
|
|
|
$output->writeln(sprintf('<fg=yellow;options=bold>%-8s</> %-20s <info>%-40s</info> %s', $check->getGroup(), $tags, $check->getId(), $check->getLabel())); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|