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