1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spatie\UptimeMonitor\Notifications\Notifications; |
4
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
6
|
|
|
use Illuminate\Notifications\Messages\MailMessage; |
7
|
|
|
use Illuminate\Notifications\Messages\SlackAttachment; |
8
|
|
|
use Illuminate\Notifications\Messages\SlackMessage; |
9
|
|
|
use Spatie\UptimeMonitor\Events\UptimeCheckSucceeded as MonitorSucceededEvent; |
10
|
|
|
use Spatie\UptimeMonitor\Models\Enums\UptimeStatus; |
11
|
|
|
use Spatie\UptimeMonitor\Notifications\BaseNotification; |
12
|
|
|
|
13
|
|
|
class UptimeCheckSucceeded extends BaseNotification |
14
|
|
|
{ |
15
|
|
|
public MonitorSucceededEvent $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
|
|
|
->subject($this->getMessageText()) |
27
|
|
|
->line($this->getMessageText()) |
28
|
|
|
->line($this->getLocationDescription()); |
29
|
|
|
|
30
|
|
|
foreach ($this->getMonitorProperties() as $name => $value) { |
31
|
|
|
$mailMessage->line($name.': '.$value); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
return $mailMessage; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function toSlack($notifiable) |
38
|
|
|
{ |
39
|
|
|
return (new SlackMessage) |
40
|
|
|
->attachment(function (SlackAttachment $attachment) { |
41
|
|
|
$attachment |
42
|
|
|
->title($this->getMessageText()) |
43
|
|
|
->fallback($this->getMessageText()) |
44
|
|
|
->footer($this->getLocationDescription()) |
45
|
|
|
->timestamp(Carbon::now()); |
46
|
|
|
}); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function isStillRelevant(): bool |
50
|
|
|
{ |
51
|
|
|
return $this->getMonitor()->uptime_status != UptimeStatus::DOWN; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function setEvent(MonitorSucceededEvent $event): self |
55
|
|
|
{ |
56
|
|
|
$this->event = $event; |
57
|
|
|
|
58
|
|
|
return $this; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function getMessageText(): string |
62
|
|
|
{ |
63
|
|
|
return "{$this->getMonitor()->url} is up"; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|