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\CertificateCheckSucceeded as ValidCertificateFoundEvent; |
10
|
|
|
use Spatie\UptimeMonitor\Notifications\BaseNotification; |
11
|
|
|
|
12
|
|
|
class CertificateCheckSucceeded extends BaseNotification |
13
|
|
|
{ |
14
|
|
|
public ValidCertificateFoundEvent $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
|
|
|
->attachment(function (SlackAttachment $attachment) { |
39
|
|
|
$attachment |
40
|
|
|
->title($this->getMessageText()) |
41
|
|
|
->content("Expires {$this->getMonitor()->formattedCertificateExpirationDate('forHumans')}") |
42
|
|
|
->fallback($this->getMessageText()) |
43
|
|
|
->footer($this->getMonitor()->certificate_issuer) |
44
|
|
|
->timestamp(Carbon::now()); |
45
|
|
|
}); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function setEvent(ValidCertificateFoundEvent $event): self |
49
|
|
|
{ |
50
|
|
|
$this->event = $event; |
51
|
|
|
|
52
|
|
|
return $this; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function getMessageText(): string |
56
|
|
|
{ |
57
|
|
|
return "SSL certificate for {$this->event->monitor->url} is valid"; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|