@@ 11-57 (lines=47) @@ | ||
8 | use Spatie\UptimeMonitor\Events\CertificateCheckSucceeded as ValidCertificateFoundEvent; |
|
9 | use Spatie\UptimeMonitor\Notifications\BaseNotification; |
|
10 | ||
11 | class CertificateCheckSucceeded extends BaseNotification |
|
12 | { |
|
13 | /** @var \Spatie\UptimeMonitor\Events\CertificateCheckSucceeded */ |
|
14 | public $event; |
|
15 | ||
16 | /** |
|
17 | * Get the mail representation of the notification. |
|
18 | * |
|
19 | * @param mixed $notifiable |
|
20 | * @return \Illuminate\Notifications\Messages\MailMessage |
|
21 | */ |
|
22 | public function toMail($notifiable) |
|
23 | { |
|
24 | $mailMessage = (new MailMessage) |
|
25 | ->success() |
|
26 | ->subject($this->getMessageText()) |
|
27 | ->line($this->getMessageText()); |
|
28 | ||
29 | foreach ($this->getMonitorProperties() as $name => $value) { |
|
30 | $mailMessage->line($name.': '.$value); |
|
31 | } |
|
32 | ||
33 | return $mailMessage; |
|
34 | } |
|
35 | ||
36 | public function toSlack($notifiable) |
|
37 | { |
|
38 | return (new SlackMessage) |
|
39 | ->success() |
|
40 | ->content("The certificate check for {$this->event->monitor->url} succeeded.") |
|
41 | ->attachment(function (SlackAttachment $attachment) { |
|
42 | $attachment->fields($this->getMonitorProperties()); |
|
43 | }); |
|
44 | } |
|
45 | ||
46 | public function setEvent(ValidCertificateFoundEvent $event) |
|
47 | { |
|
48 | $this->event = $event; |
|
49 | ||
50 | return $this; |
|
51 | } |
|
52 | ||
53 | public function getMessageText(): string |
|
54 | { |
|
55 | return "{$this->event->monitor->url} has a valid certificate{$this->getLocationDescription()}."; |
|
56 | } |
|
57 | } |
|
58 |
@@ 11-55 (lines=45) @@ | ||
8 | use Spatie\UptimeMonitor\Events\CertificateExpiresSoon as SoonExpiringSslCertificateFoundEvent; |
|
9 | use Spatie\UptimeMonitor\Notifications\BaseNotification; |
|
10 | ||
11 | class CertificateExpiresSoon extends BaseNotification |
|
12 | { |
|
13 | /** @var \Spatie\UptimeMonitor\Events\CertificateExpiresSoon */ |
|
14 | public $event; |
|
15 | ||
16 | /** |
|
17 | * Get the mail representation of the notification. |
|
18 | * |
|
19 | * @param mixed $notifiable |
|
20 | * @return \Illuminate\Notifications\Messages\MailMessage |
|
21 | */ |
|
22 | public function toMail($notifiable) |
|
23 | { |
|
24 | $mailMessage = (new MailMessage) |
|
25 | ->subject($this->getMessageText()) |
|
26 | ->line($this->getMessageText()); |
|
27 | ||
28 | foreach ($this->getMonitorProperties() as $name => $value) { |
|
29 | $mailMessage->line($name.': '.$value); |
|
30 | } |
|
31 | ||
32 | return $mailMessage; |
|
33 | } |
|
34 | ||
35 | public function toSlack($notifiable) |
|
36 | { |
|
37 | return (new SlackMessage) |
|
38 | ->content($this->getMessageText()) |
|
39 | ->attachment(function (SlackAttachment $attachment) { |
|
40 | $attachment->fields($this->getMonitorProperties()); |
|
41 | }); |
|
42 | } |
|
43 | ||
44 | public function setEvent(SoonExpiringSslCertificateFoundEvent $event) |
|
45 | { |
|
46 | $this->event = $event; |
|
47 | ||
48 | return $this; |
|
49 | } |
|
50 | ||
51 | protected function getMessageText(): string |
|
52 | { |
|
53 | return "{$this->event->monitor->url} has a certificate that will expire in {$this->event->monitor->certificate_expiration_date->diffInDays()} days{$this->getLocationDescription()}."; |
|
54 | } |
|
55 | } |
|
56 |
@@ 12-63 (lines=52) @@ | ||
9 | use Spatie\UptimeMonitor\Models\Enums\UptimeStatus; |
|
10 | use Spatie\UptimeMonitor\Notifications\BaseNotification; |
|
11 | ||
12 | class UptimeCheckSucceeded extends BaseNotification |
|
13 | { |
|
14 | /** @var \Spatie\UptimeMonitor\Events\UptimeCheckSucceeded */ |
|
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 | ->success() |
|
27 | ->subject($this->getMessageText()) |
|
28 | ->line($this->getMessageText()); |
|
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 | ->success() |
|
41 | ->content($this->getMessageText()) |
|
42 | ->attachment(function (SlackAttachment $attachment) { |
|
43 | $attachment->fields($this->getMonitorProperties()); |
|
44 | }); |
|
45 | } |
|
46 | ||
47 | public function isStillRelevant(): bool |
|
48 | { |
|
49 | return $this->event->monitor->uptime_status != UptimeStatus::DOWN; |
|
50 | } |
|
51 | ||
52 | public function setEvent(MonitorSucceededEvent $event) |
|
53 | { |
|
54 | $this->event = $event; |
|
55 | ||
56 | return $this; |
|
57 | } |
|
58 | ||
59 | public function getMessageText(): string |
|
60 | { |
|
61 | return "{$this->event->monitor->url} is up{$this->getLocationDescription()}."; |
|
62 | } |
|
63 | } |
|
64 |