|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the hogosha-monitor package |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (c) 2016 Guillaume Cavana |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
* |
|
11
|
|
|
* Feel free to edit as you please, and have fun. |
|
12
|
|
|
* |
|
13
|
|
|
* @author Guillaume Cavana <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
namespace Hogosha\Monitor\Pusher; |
|
17
|
|
|
|
|
18
|
|
|
use Concat\Http\Middleware\Logger; |
|
19
|
|
|
use GuzzleHttp\HandlerStack; |
|
20
|
|
|
use GuzzleHttp\MessageFormatter; |
|
21
|
|
|
use Hogosha\Monitor\Model\Result; |
|
22
|
|
|
use Hogosha\Sdk\Api\Client as SdkClient; |
|
23
|
|
|
use Symfony\Component\Console\Logger\ConsoleLogger; |
|
24
|
|
|
use Webmozart\Console\Adapter\IOOutput; |
|
25
|
|
|
use Webmozart\Console\Api\IO\IO; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Class AbstractPusher. |
|
29
|
|
|
*/ |
|
30
|
|
|
abstract class AbstractPusher implements PusherInterface |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* $client. |
|
34
|
|
|
* |
|
35
|
|
|
* @var SdkClient |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $client; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* $options. |
|
41
|
|
|
* |
|
42
|
|
|
* @var array |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $options; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* $io. |
|
48
|
|
|
* |
|
49
|
|
|
* @var IO |
|
50
|
|
|
*/ |
|
51
|
|
|
protected $io; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Constructor. |
|
55
|
|
|
* |
|
56
|
|
|
* @param array $options |
|
57
|
|
|
* @param IO $io |
|
58
|
|
|
* @param Client $client |
|
59
|
|
|
*/ |
|
60
|
|
|
public function __construct(array $options, IO $io, SdkClient $client = null) |
|
61
|
|
|
{ |
|
62
|
|
|
$this->io = $io; |
|
63
|
|
|
$this->options = $options; |
|
64
|
|
|
$this->client = null !== $client ? $client : $this->createClient(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* getDefaultFailedIncidentMessage. |
|
69
|
|
|
* |
|
70
|
|
|
* @return string Default message used to create a incident when a failure as occured |
|
71
|
|
|
*/ |
|
72
|
|
|
public function getDefaultFailedIncidentMessage() |
|
73
|
|
|
{ |
|
74
|
|
|
return $this->options['default_failed_incident_message']; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* getDefaultResolvedIncidentMessage. |
|
79
|
|
|
* |
|
80
|
|
|
* @return string Default message used to create a incident when a service is resolved as occured |
|
81
|
|
|
*/ |
|
82
|
|
|
public function getDefaultResolvedIncidentMessage() |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->options['default_resolved_incident_message']; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* getClient. |
|
89
|
|
|
* |
|
90
|
|
|
* @return SdkClient |
|
91
|
|
|
*/ |
|
92
|
|
|
protected function createClient() |
|
93
|
|
|
{ |
|
94
|
|
|
$stack = HandlerStack::create(); |
|
95
|
|
|
|
|
96
|
|
|
$middleware = (new Logger((new ConsoleLogger(new IOOutput($this->io))))); |
|
|
|
|
|
|
97
|
|
|
$middleware->setRequestLoggingEnabled(true); |
|
98
|
|
|
$format = "<fg=white;bg=blue>Request:</>\n <fg=white;bg=default>{host} {req_headers} \nBody: {req_body} </>\n <fg=white;bg=blue>Reponse:</>\n<fg=white;bg=default>{res_body} {res_headers}</>\n"; |
|
99
|
|
|
$middleware->setFormatter((new MessageFormatter($format))); |
|
|
|
|
|
|
100
|
|
|
|
|
101
|
|
|
$stack->push($middleware, 'logger'); |
|
102
|
|
|
|
|
103
|
|
|
return new SdkClient( |
|
104
|
|
|
[ |
|
105
|
|
|
'username' => $this->options['username'], |
|
106
|
|
|
'password' => $this->options['password'], |
|
107
|
|
|
'base_uri' => $this->options['base_uri'], |
|
108
|
|
|
'handler' => $stack, |
|
109
|
|
|
] |
|
110
|
|
|
); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* push. |
|
115
|
|
|
* |
|
116
|
|
|
* @param Result $result |
|
117
|
|
|
* |
|
118
|
|
|
* @throws \Exception |
|
119
|
|
|
* |
|
120
|
|
|
* @return mixed |
|
121
|
|
|
*/ |
|
122
|
|
|
abstract public function push(Result $result); |
|
123
|
|
|
} |
|
124
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: