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\CertificateCheckFailed as InValidCertificateFoundEvent; |
9
|
|
|
use Spatie\UptimeMonitor\Notifications\BaseNotification; |
10
|
|
|
|
11
|
|
|
class CertificateCheckFailed 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
|
|
|
->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
|
|
|
->error() |
40
|
|
|
->content($this->getMessageText()) |
41
|
|
|
->attachment(function (SlackAttachment $attachment) { |
42
|
|
|
$attachment->fields($this->getMonitorProperties()); |
43
|
|
|
}); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function getMonitorProperties($properties = []): array |
47
|
|
|
{ |
48
|
|
|
$extraProperties = ['Failure reason' => $this->event->monitor->certificate_check_failure_reason]; |
49
|
|
|
|
50
|
|
|
return parent::getMonitorProperties($extraProperties); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function setEvent(InValidCertificateFoundEvent $event) |
54
|
|
|
{ |
55
|
|
|
$this->event = $event; |
|
|
|
|
56
|
|
|
|
57
|
|
|
return $this; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function getMessageText(): string |
61
|
|
|
{ |
62
|
|
|
return "{$this->event->monitor->url} hasn't got a valid certificate{$this->getLocationDescription()}."; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.