1 | <?php |
||
10 | class ListChecksCommand extends ContainerAwareCommand |
||
11 | { |
||
12 | protected function configure() |
||
13 | { |
||
14 | $this |
||
15 | ->setName('monitor:list') |
||
16 | ->setDescription('Lists Health Checks') |
||
17 | ->addOption('all', 'a', InputOption::VALUE_NONE, 'Lists Health Checks of all groups') |
||
18 | ->addOption('reporters', 'r', InputOption::VALUE_NONE, 'List registered additional reporters') |
||
19 | ->addOption('group', 'g', InputOption::VALUE_REQUIRED, 'List checks for given group') |
||
20 | ->addOption('groups', 'G', InputOption::VALUE_NONE, 'List all registered groups') |
||
21 | ; |
||
22 | } |
||
23 | |||
24 | protected function execute(InputInterface $input, OutputInterface $output) |
||
25 | { |
||
26 | switch (true) { |
||
27 | case $input->getOption('reporters'): |
||
28 | $this->listReporters($output); |
||
29 | break; |
||
30 | case $input->getOption('all'): |
||
31 | $this->listAllChecks($output); |
||
32 | break; |
||
33 | case $input->getOption('groups'): |
||
34 | $this->listGroups($output); |
||
35 | break; |
||
36 | default: |
||
37 | $this->listChecks($input, $output); |
||
38 | break; |
||
39 | } |
||
40 | } |
||
41 | |||
42 | protected function listChecks(InputInterface $input, OutputInterface $output) |
||
43 | { |
||
44 | $group = $input->getOption('group'); |
||
45 | |||
46 | if (is_null($group)) { |
||
47 | $group = $this->getContainer()->getParameter('liip_monitor.default_group'); |
||
48 | } |
||
49 | |||
50 | $runnerServiceId = 'liip_monitor.runner_'.$group; |
||
51 | |||
52 | if (!$this->getContainer()->has($runnerServiceId)) { |
||
53 | $output->writeln('<error>No such group.</error>'); |
||
54 | |||
55 | return; |
||
56 | } |
||
57 | |||
58 | $this->doListChecks($output, $runnerServiceId); |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * @param OutputInterface $output |
||
63 | */ |
||
64 | protected function listAllChecks(OutputInterface $output) |
||
65 | { |
||
66 | foreach ($this->getGroups() as $runnerServiceId => $group) { |
||
67 | $output->writeln(sprintf('<fg=yellow;options=bold>%s</>', $group)); |
||
68 | |||
69 | $this->doListChecks($output, $runnerServiceId); |
||
70 | } |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * @param OutputInterface $output |
||
75 | */ |
||
76 | protected function listReporters(OutputInterface $output) |
||
87 | |||
88 | /** |
||
89 | * @param OutputInterface $output |
||
90 | */ |
||
91 | protected function listGroups(OutputInterface $output) |
||
92 | { |
||
93 | foreach ($this->getGroups() as $group) { |
||
94 | $output->writeln($group); |
||
95 | } |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * @param OutputInterface $output |
||
100 | * @param $runnerServiceId |
||
101 | */ |
||
102 | private function doListChecks(OutputInterface $output, $runnerServiceId) |
||
115 | |||
116 | /** |
||
117 | * @return array key/value $serviceId/$group |
||
118 | */ |
||
119 | private function getGroups() |
||
133 | } |
||
134 |