|
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 Illuminate\Events\Dispatcher; |
|
10
|
|
|
|
|
11
|
|
|
class EventHandler |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var \EricMakesStuff\ServerMonitor\Notifications\Notifier |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $notifier; |
|
17
|
|
|
|
|
18
|
|
|
public function __construct() |
|
19
|
|
|
{ |
|
20
|
|
|
$notifierClass = config('server-monitor.notifications.handler'); |
|
21
|
|
|
|
|
22
|
|
|
$this->notifier = app($notifierClass); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param \EricMakesStuff\ServerMonitor\Events\DiskUsageAlarm $event |
|
27
|
|
|
*/ |
|
28
|
|
|
public function whenDiskUsageAlarm(DiskUsageAlarm $event) |
|
29
|
|
|
{ |
|
30
|
|
|
$this->notifier->diskUsageAlarm($event->diskUsageMonitor); |
|
|
|
|
|
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param \EricMakesStuff\ServerMonitor\Events\DiskUsageHealthy $event |
|
35
|
|
|
*/ |
|
36
|
|
|
public function whenDiskUsageHealthy(DiskUsageHealthy $event) |
|
37
|
|
|
{ |
|
38
|
|
|
$this->notifier->diskUsageHealthy($event->diskUsageMonitor); |
|
|
|
|
|
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param \EricMakesStuff\ServerMonitor\Events\HttpPingDown $event |
|
43
|
|
|
*/ |
|
44
|
|
|
public function whenHttpPingDown(HttpPingDown $event) |
|
45
|
|
|
{ |
|
46
|
|
|
$this->notifier->httpPingDown($event->httpPingMonitor); |
|
|
|
|
|
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param \EricMakesStuff\ServerMonitor\Events\HttpPingUp $event |
|
51
|
|
|
*/ |
|
52
|
|
|
public function whenHttpPingUp(HttpPingUp $event) |
|
53
|
|
|
{ |
|
54
|
|
|
$this->notifier->httpPingUp($event->httpPingMonitor); |
|
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Register the listeners for the subscriber. |
|
59
|
|
|
* |
|
60
|
|
|
* @param \Illuminate\Events\Dispatcher $events |
|
61
|
|
|
* |
|
62
|
|
|
* @return array |
|
63
|
|
|
*/ |
|
64
|
|
|
public function subscribe(Dispatcher $events) |
|
65
|
|
|
{ |
|
66
|
|
|
$events->listen( |
|
67
|
|
|
DiskUsageHealthy::class, |
|
68
|
|
|
static::class.'@whenDiskUsageHealthy' |
|
69
|
|
|
); |
|
70
|
|
|
|
|
71
|
|
|
$events->listen( |
|
72
|
|
|
DiskUsageAlarm::class, |
|
73
|
|
|
static::class.'@whenDiskUsageAlarm' |
|
74
|
|
|
); |
|
75
|
|
|
|
|
76
|
|
|
$events->listen( |
|
77
|
|
|
HttpPingUp::class, |
|
78
|
|
|
static::class.'@whenHttpPingUp' |
|
79
|
|
|
); |
|
80
|
|
|
|
|
81
|
|
|
$events->listen( |
|
82
|
|
|
HttpPingDown::class, |
|
83
|
|
|
static::class.'@whenHttpPingDown' |
|
84
|
|
|
); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
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: