@@ 13-60 (lines=48) @@ | ||
10 | use Spatie\ServerMonitor\Notifications\BaseNotification; |
|
11 | use Spatie\ServerMonitor\Events\CheckFailed as CheckFailedEvent; |
|
12 | ||
13 | class CheckFailed extends BaseNotification |
|
14 | { |
|
15 | /** @var \Spatie\ServerMonitor\Events\CheckWarning */ |
|
16 | public $event; |
|
17 | ||
18 | /** |
|
19 | * Get the mail representation of the notification. |
|
20 | * |
|
21 | * @param mixed $notifiable |
|
22 | * @return \Illuminate\Notifications\Messages\MailMessage |
|
23 | */ |
|
24 | public function toMail($notifiable) |
|
25 | { |
|
26 | return (new MailMessage) |
|
27 | ->error() |
|
28 | ->subject($this->getSubject()) |
|
29 | ->line($this->getMessageText()); |
|
30 | } |
|
31 | ||
32 | public function toSlack($notifiable) |
|
33 | { |
|
34 | return (new SlackMessage) |
|
35 | ->warning() |
|
36 | ->attachment(function (SlackAttachment $attachment) { |
|
37 | $attachment |
|
38 | ->title($this->getSubject()) |
|
39 | ->content($this->getMessageText()) |
|
40 | ->fallback($this->getMessageText()) |
|
41 | ->timestamp(Carbon::now()); |
|
42 | }); |
|
43 | } |
|
44 | ||
45 | public function setEvent(CheckFailedEvent $event) |
|
46 | { |
|
47 | $this->event = $event; |
|
48 | ||
49 | return $this; |
|
50 | } |
|
51 | ||
52 | public function shouldSend(): bool |
|
53 | { |
|
54 | if (! $this->getCheck()->hasStatus(CheckStatus::FAILED)) { |
|
55 | return false; |
|
56 | }; |
|
57 | ||
58 | return ! $this->getCheck()->isThrottlingFailedNotifications(); |
|
59 | } |
|
60 | } |
|
61 |
@@ 13-60 (lines=48) @@ | ||
10 | use Spatie\ServerMonitor\Notifications\BaseNotification; |
|
11 | use Spatie\ServerMonitor\Events\CheckWarning as CheckWarningEvent; |
|
12 | ||
13 | class CheckWarning extends BaseNotification |
|
14 | { |
|
15 | /** @var \Spatie\ServerMonitor\Events\CheckWarning */ |
|
16 | public $event; |
|
17 | ||
18 | /** |
|
19 | * Get the mail representation of the notification. |
|
20 | * |
|
21 | * @param mixed $notifiable |
|
22 | * @return \Illuminate\Notifications\Messages\MailMessage |
|
23 | */ |
|
24 | public function toMail($notifiable) |
|
25 | { |
|
26 | return (new MailMessage) |
|
27 | ->error() |
|
28 | ->subject($this->getSubject()) |
|
29 | ->line($this->getMessageText()); |
|
30 | } |
|
31 | ||
32 | public function toSlack($notifiable) |
|
33 | { |
|
34 | return (new SlackMessage) |
|
35 | ->warning() |
|
36 | ->attachment(function (SlackAttachment $attachment) { |
|
37 | $attachment |
|
38 | ->title($this->getSubject()) |
|
39 | ->content($this->getMessageText()) |
|
40 | ->fallback($this->getMessageText()) |
|
41 | ->timestamp(Carbon::now()); |
|
42 | }); |
|
43 | } |
|
44 | ||
45 | public function setEvent(CheckWarningEvent $event) |
|
46 | { |
|
47 | $this->event = $event; |
|
48 | ||
49 | return $this; |
|
50 | } |
|
51 | ||
52 | public function shouldSend(): bool |
|
53 | { |
|
54 | if (! $this->getCheck()->hasStatus(CheckStatus::WARNING)) { |
|
55 | return false; |
|
56 | } |
|
57 | ||
58 | return ! $this->getCheck()->isThrottlingFailedNotifications(); |
|
59 | } |
|
60 | } |
|
61 |