| @@ 12-63 (lines=52) @@ | ||
| 9 | use Spatie\UptimeMonitor\Models\Enums\UptimeStatus; |
|
| 10 | use Spatie\UptimeMonitor\Notifications\BaseNotification; |
|
| 11 | ||
| 12 | class SiteDown extends BaseNotification |
|
| 13 | { |
|
| 14 | /** @var \Spatie\UptimeMonitor\Events\SiteDown */ |
|
| 15 | protected $event; |
|
| 16 | ||
| 17 | /** |
|
| 18 | * Get the mail representation of the notification. |
|
| 19 | * |
|
| 20 | * @param mixed $notifiable |
|
| 21 | * @return \Illuminate\Notifications\Messages\MailMessage |
|
| 22 | */ |
|
| 23 | public function toMail($notifiable) |
|
| 24 | { |
|
| 25 | $mailMessage = (new MailMessage) |
|
| 26 | ->error() |
|
| 27 | ->subject("Site {$this->event->site->url} is down.") |
|
| 28 | ->line('Site is down'); |
|
| 29 | ||
| 30 | return $mailMessage; |
|
| 31 | } |
|
| 32 | ||
| 33 | public function toSlack($notifiable) |
|
| 34 | { |
|
| 35 | return (new SlackMessage) |
|
| 36 | ->error() |
|
| 37 | ->content("Site {$this->event->site->url} is down") |
|
| 38 | ->attachment(function (SlackAttachment $attachment) { |
|
| 39 | $attachment->fields($this->getSiteProperties()); |
|
| 40 | }); |
|
| 41 | } |
|
| 42 | ||
| 43 | public function getSiteProperties($extraProperties = []): array |
|
| 44 | { |
|
| 45 | $extraProperties = [ |
|
| 46 | 'offline since' => $this->event->site->formattedLastUpdatedStatusChangeDate, |
|
| 47 | ]; |
|
| 48 | ||
| 49 | return parent::getSiteProperties($extraProperties); |
|
| 50 | } |
|
| 51 | ||
| 52 | public function isStillRelevant(): bool |
|
| 53 | { |
|
| 54 | return $this->event->site->uptime_status == UptimeStatus::DOWN; |
|
| 55 | } |
|
| 56 | ||
| 57 | public function setEvent(SiteDownEvent $event) |
|
| 58 | { |
|
| 59 | $this->event = $event; |
|
| 60 | ||
| 61 | return $this; |
|
| 62 | } |
|
| 63 | } |
|
| 64 | ||
| @@ 12-63 (lines=52) @@ | ||
| 9 | use Spatie\UptimeMonitor\Models\Enums\UptimeStatus; |
|
| 10 | use Spatie\UptimeMonitor\Notifications\BaseNotification; |
|
| 11 | ||
| 12 | class SiteRestored extends BaseNotification |
|
| 13 | { |
|
| 14 | /** @var \Spatie\UptimeMonitor\Events\SiteDown */ |
|
| 15 | protected $event; |
|
| 16 | ||
| 17 | /** |
|
| 18 | * Get the mail representation of the notification. |
|
| 19 | * |
|
| 20 | * @param mixed $notifiable |
|
| 21 | * @return \Illuminate\Notifications\Messages\MailMessage |
|
| 22 | */ |
|
| 23 | public function toMail($notifiable) |
|
| 24 | { |
|
| 25 | $mailMessage = (new MailMessage) |
|
| 26 | ->success() |
|
| 27 | ->subject("Site {$this->event->site->url} has been restored.") |
|
| 28 | ->line('Site has been restored'); |
|
| 29 | ||
| 30 | return $mailMessage; |
|
| 31 | } |
|
| 32 | ||
| 33 | public function toSlack($notifiable) |
|
| 34 | { |
|
| 35 | return (new SlackMessage) |
|
| 36 | ->success() |
|
| 37 | ->content("Site {$this->event->site->url} has been restored") |
|
| 38 | ->attachment(function (SlackAttachment $attachment) { |
|
| 39 | $attachment->fields($this->getSiteProperties()); |
|
| 40 | }); |
|
| 41 | } |
|
| 42 | ||
| 43 | public function getSiteProperties($extraProperties = []): array |
|
| 44 | { |
|
| 45 | $extraProperties = [ |
|
| 46 | 'online since' => $this->event->site->formattedLastUpdatedStatusChangeDate, |
|
| 47 | ]; |
|
| 48 | ||
| 49 | return parent::getSiteProperties($extraProperties); |
|
| 50 | } |
|
| 51 | ||
| 52 | public function isStillRelevant(): bool |
|
| 53 | { |
|
| 54 | return $this->event->site->uptime_status == UptimeStatus::UP; |
|
| 55 | } |
|
| 56 | ||
| 57 | public function setEvent(SiteRestoredEvent $event) |
|
| 58 | { |
|
| 59 | $this->event = $event; |
|
| 60 | ||
| 61 | return $this; |
|
| 62 | } |
|
| 63 | } |
|
| 64 | ||