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\Backup\Events\BackupHasFailed as BackupHasFailedEvent; |
9
|
|
|
use Spatie\Backup\Notifications\BaseNotification; |
10
|
|
|
|
11
|
|
|
class BackupHasFailed extends BaseNotification |
12
|
|
|
{ |
13
|
|
|
/** @var \Spatie\Backup\Events\BackupHasFailed */ |
14
|
|
|
protected $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("Failed back up of `{$this->getApplicationName()}`") |
27
|
|
|
->line("Important: An error occurred while backing up `{$this->getApplicationName()}`") |
28
|
|
|
->line("Exception message: `{$this->event->exception->getMessage()}`") |
29
|
|
|
->line("Exception trace: `{$this->event->exception->getTraceAsString()}`"); |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
$this->getBackupDestinationProperties()->each(function ($value, $name) use ($mailMessage) { |
33
|
|
|
$mailMessage->line("{$name}: $value"); |
34
|
|
|
}); |
35
|
|
|
|
36
|
|
|
return $mailMessage; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function toSlack($notifiable) |
40
|
|
|
{ |
41
|
|
|
return (new SlackMessage) |
42
|
|
|
->error() |
43
|
|
|
->content("Failed back up of `{$this->getApplicationName()}`") |
44
|
|
|
->attachment(function (SlackAttachment $attachment) { |
45
|
|
|
$attachment |
46
|
|
|
->title('Exception message') |
47
|
|
|
->content($this->event->exception->getMessage()); |
48
|
|
|
}) |
49
|
|
|
->attachment(function (SlackAttachment $attachment) { |
50
|
|
|
$attachment |
51
|
|
|
->title('Exception trace') |
52
|
|
|
->content($this->event->exception->getTraceAsString()); |
53
|
|
|
}) |
54
|
|
|
->attachment(function (SlackAttachment $attachment) { |
55
|
|
|
$attachment->fields($this->getBackupDestinationProperties()->toArray()); |
56
|
|
|
}); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function setEvent(BackupHasFailedEvent $event) |
60
|
|
|
{ |
61
|
|
|
$this->event = $event; |
62
|
|
|
|
63
|
|
|
return $this; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|