1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spatie\UptimeMonitor\Notifications\Notifications; |
4
|
|
|
|
5
|
|
|
use Illuminate\Notifications\Messages\MailMessage; |
6
|
|
|
use Illuminate\Notifications\Messages\SlackAttachment; |
7
|
|
|
use Illuminate\Notifications\Messages\SlackMessage; |
8
|
|
|
use Spatie\UptimeMonitor\Events\MonitorFailed as MonitorFailedEvent; |
9
|
|
|
use Spatie\UptimeMonitor\Models\Enums\UptimeStatus; |
10
|
|
|
use Spatie\UptimeMonitor\Notifications\BaseNotification; |
11
|
|
|
|
12
|
|
|
class MonitorFailed extends BaseNotification |
13
|
|
|
{ |
14
|
|
|
/** @var \Spatie\UptimeMonitor\Events\MonitorFailed */ |
15
|
|
|
public $event; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Get the mail representation of the notification. |
19
|
|
|
* |
20
|
|
|
* @param mixed $notifiable |
21
|
|
|
* @return \Illuminate\Notifications\Messages\MailMessage |
22
|
|
|
*/ |
23
|
|
|
public function toMail($notifiable) |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
$mailMessage = (new MailMessage) |
26
|
|
|
->error() |
27
|
|
|
->subject("The uptime check for monitor {$this->event->monitor->url} failed.") |
28
|
|
|
->line("The uptime check for monitor {$this->event->monitor->url} failed."); |
29
|
|
|
|
30
|
|
|
return $mailMessage; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
View Code Duplication |
public function toSlack($notifiable) |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
return (new SlackMessage) |
36
|
|
|
->error() |
37
|
|
|
->content("The uptime check for monitor {$this->event->monitor->url} failed.") |
38
|
|
|
->attachment(function (SlackAttachment $attachment) { |
39
|
|
|
$attachment->fields($this->getMonitorProperties()); |
40
|
|
|
}); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function getMonitorProperties($extraProperties = []): array |
44
|
|
|
{ |
45
|
|
|
$extraProperties = [ |
46
|
|
|
'failing since' => $this->event->monitor->formattedLastUpdatedStatusChangeDate, |
47
|
|
|
]; |
48
|
|
|
|
49
|
|
|
return parent::getMonitorProperties($extraProperties); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function isStillRelevant(): bool |
53
|
|
|
{ |
54
|
|
|
return $this->event->monitor->uptime_status == UptimeStatus::DOWN; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function setEvent(MonitorFailedEvent $event) |
58
|
|
|
{ |
59
|
|
|
$this->event = $event; |
60
|
|
|
|
61
|
|
|
return $this; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.