1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EricMakesStuff\ServerMonitor\Notifications; |
4
|
|
|
|
5
|
|
|
use EricMakesStuff\ServerMonitor\Events\HttpPingDown; |
6
|
|
|
use EricMakesStuff\ServerMonitor\Events\HttpPingUp; |
7
|
|
|
use EricMakesStuff\ServerMonitor\Events\DiskUsageAlarm; |
8
|
|
|
use EricMakesStuff\ServerMonitor\Events\DiskUsageHealthy; |
9
|
|
|
use EricMakesStuff\ServerMonitor\Events\SSLCertificateExpiring; |
10
|
|
|
use EricMakesStuff\ServerMonitor\Events\SSLCertificateInvalid; |
11
|
|
|
use EricMakesStuff\ServerMonitor\Events\SSLCertificateValid; |
12
|
|
|
use Illuminate\Events\Dispatcher; |
13
|
|
|
|
14
|
|
|
class EventHandler |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var \EricMakesStuff\ServerMonitor\Notifications\Notifier |
18
|
|
|
*/ |
19
|
|
|
protected $notifier; |
20
|
|
|
|
21
|
|
|
public function __construct() |
22
|
|
|
{ |
23
|
|
|
$notifierClass = config('server-monitor.notifications.handler'); |
24
|
|
|
|
25
|
|
|
$this->notifier = app($notifierClass); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param \EricMakesStuff\ServerMonitor\Events\DiskUsageAlarm $event |
30
|
|
|
*/ |
31
|
|
|
public function whenDiskUsageAlarm(DiskUsageAlarm $event) |
32
|
|
|
{ |
33
|
|
|
$this->notifier->diskUsageAlarm($event->diskUsageMonitor); |
|
|
|
|
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param \EricMakesStuff\ServerMonitor\Events\DiskUsageHealthy $event |
38
|
|
|
*/ |
39
|
|
|
public function whenDiskUsageHealthy(DiskUsageHealthy $event) |
40
|
|
|
{ |
41
|
|
|
$this->notifier->diskUsageHealthy($event->diskUsageMonitor); |
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param \EricMakesStuff\ServerMonitor\Events\HttpPingDown $event |
46
|
|
|
*/ |
47
|
|
|
public function whenHttpPingDown(HttpPingDown $event) |
48
|
|
|
{ |
49
|
|
|
$this->notifier->httpPingDown($event->httpPingMonitor); |
|
|
|
|
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param \EricMakesStuff\ServerMonitor\Events\HttpPingUp $event |
54
|
|
|
*/ |
55
|
|
|
public function whenHttpPingUp(HttpPingUp $event) |
56
|
|
|
{ |
57
|
|
|
$this->notifier->httpPingUp($event->httpPingMonitor); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param \EricMakesStuff\ServerMonitor\Events\SSLCertificateValid $event |
62
|
|
|
*/ |
63
|
|
|
public function whenSSLCertificateValid(SSLCertificateValid $event) |
64
|
|
|
{ |
65
|
|
|
$this->notifier->sslCertificateValid($event->sslCertificateMonitor); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param \EricMakesStuff\ServerMonitor\Events\SSLCertificateInvalid $event |
70
|
|
|
*/ |
71
|
|
|
public function whenSSLCertificateInvalid(SSLCertificateInvalid $event) |
72
|
|
|
{ |
73
|
|
|
$this->notifier->sslCertificateInvalid($event->sslCertificateMonitor); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param \EricMakesStuff\ServerMonitor\Events\SSLCertificateExpiring $event |
78
|
|
|
*/ |
79
|
|
|
public function whenSSLCertificateExpiring(SSLCertificateExpiring $event) |
80
|
|
|
{ |
81
|
|
|
$this->notifier->sslCertificateExpiring($event->sslCertificateMonitor); |
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Register the listeners for the subscriber. |
86
|
|
|
* |
87
|
|
|
* @param \Illuminate\Events\Dispatcher $events |
88
|
|
|
* |
89
|
|
|
* @return array |
90
|
|
|
*/ |
91
|
|
|
public function subscribe(Dispatcher $events) |
92
|
|
|
{ |
93
|
|
|
$events->listen( |
94
|
|
|
DiskUsageHealthy::class, |
95
|
|
|
static::class.'@whenDiskUsageHealthy' |
96
|
|
|
); |
97
|
|
|
|
98
|
|
|
$events->listen( |
99
|
|
|
DiskUsageAlarm::class, |
100
|
|
|
static::class.'@whenDiskUsageAlarm' |
101
|
|
|
); |
102
|
|
|
|
103
|
|
|
$events->listen( |
104
|
|
|
HttpPingUp::class, |
105
|
|
|
static::class.'@whenHttpPingUp' |
106
|
|
|
); |
107
|
|
|
|
108
|
|
|
$events->listen( |
109
|
|
|
HttpPingDown::class, |
110
|
|
|
static::class.'@whenHttpPingDown' |
111
|
|
|
); |
112
|
|
|
|
113
|
|
|
$events->listen( |
114
|
|
|
SSLCertificateValid::class, |
115
|
|
|
static::class.'@whenSSLCertificateValid' |
116
|
|
|
); |
117
|
|
|
|
118
|
|
|
$events->listen( |
119
|
|
|
SSLCertificateInvalid::class, |
120
|
|
|
static::class.'@whenSSLCertificateInvalid' |
121
|
|
|
); |
122
|
|
|
|
123
|
|
|
$events->listen( |
124
|
|
|
SSLCertificateExpiring::class, |
125
|
|
|
static::class.'@whenSSLCertificateExpiring' |
126
|
|
|
); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: