|
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\Controller; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
15
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
16
|
|
|
use Tvi\MonitorBundle\Reporter\Api; |
|
17
|
|
|
use Tvi\MonitorBundle\Reporter\ReporterManager; |
|
18
|
|
|
use Tvi\MonitorBundle\Runner\RunnerManager; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
|
|
|
|
|
21
|
|
|
* @author Vladimir Turnaev <[email protected]> |
|
22
|
|
|
*/ |
|
|
|
|
|
|
23
|
|
|
class ApiController |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
|
|
|
|
|
26
|
|
|
* @var RunnerManager |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $runnerManager; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
|
|
|
|
|
31
|
|
|
* @var ReporterManager |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $reporterManager; |
|
34
|
|
|
|
|
35
|
|
|
public function __construct(RunnerManager $runnerManager, ReporterManager $reporterManager) |
|
|
|
|
|
|
36
|
|
|
{ |
|
37
|
|
|
$this->runnerManager = $runnerManager; |
|
38
|
|
|
$this->reporterManager = $reporterManager; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function testAction(Request $request) |
|
|
|
|
|
|
42
|
|
|
{ |
|
43
|
|
|
$check = $request->get('check', []); |
|
44
|
|
|
if (\is_string($check)) { |
|
45
|
|
|
$check = $check ? [$check] : []; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
$groups = $request->get('group', []); |
|
49
|
|
|
if (\is_string($groups)) { |
|
50
|
|
|
$groups = $groups ? [$groups] : []; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
$tags = $request->get('tag', []); |
|
54
|
|
|
if (\is_string($tags)) { |
|
55
|
|
|
$tags = $tags ? [$tags] : []; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
$runner = $this->runnerManager->getRunner($check, $groups, $tags); |
|
59
|
|
|
/** @var $reporter Api */ |
|
|
|
|
|
|
60
|
|
|
$reporter = $this->reporterManager->getReporter('api'); |
|
61
|
|
|
|
|
62
|
|
|
$runner->addReporter($reporter); |
|
63
|
|
|
$runner->run(); |
|
64
|
|
|
|
|
65
|
|
|
return new JsonResponse([ |
|
|
|
|
|
|
66
|
|
|
'statusCode' => $reporter->getStatusCode(), |
|
67
|
|
|
'statusName' => $reporter->getStatusName(), |
|
68
|
|
|
|
|
69
|
|
|
'successes' => $reporter->getSuccessCount(), |
|
70
|
|
|
'warnings' => $reporter->getWarningCount(), |
|
71
|
|
|
'failures' => $reporter->getFailureCount(), |
|
72
|
|
|
'unknowns' => $reporter->getUnknownCount(), |
|
73
|
|
|
'total' => $reporter->getTotalCount(), |
|
74
|
|
|
|
|
75
|
|
|
'checks' => $reporter->getCheckResults(), |
|
76
|
|
|
]); |
|
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
// v($reporter->getResults()); |
|
|
|
|
|
|
79
|
|
|
// exit; |
|
|
|
|
|
|
80
|
|
|
// $number = random_int(0, 100); |
|
|
|
|
|
|
81
|
|
|
// |
|
|
|
|
|
|
82
|
|
|
// return new Response( |
|
|
|
|
|
|
83
|
|
|
// '<html><body>Lucky number: '.$number.'</body></html>' |
|
|
|
|
|
|
84
|
|
|
// ); |
|
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|