Skip to content

Commit

Permalink
set the data properly
Browse files Browse the repository at this point in the history
  • Loading branch information
edalzell committed Sep 1, 2021
1 parent 1d6d1a9 commit 6f2541d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/Notifications/AbstractAlert.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ public function via($notifiable)
* @param mixed $notifiable
* @return array
*/
public function toArray()
public function toArray(): array
{
return [
'event' => $this->event,
'date' => Arr::get($this->alert, 'date'),
'is_up' => Arr::get($this->alert, 'alert.is_up'),
'locations' =>Arr::get($this->alert, 'locations'),
'output' => Arr::get($this->alert, 'alert.short_output'),
'subject' => $this->subject,
'test' => Arr::get($this->alert, 'service.name'),
Expand Down
16 changes: 16 additions & 0 deletions src/Notifications/AlertCleared.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,24 @@

namespace TransformStudios\Uptime\Notifications;

use Illuminate\Support\Carbon;
use Statamic\Support\Arr;

class AlertCleared extends AbstractAlert
{
protected string $event = 'alert_cleared';
protected string $subject = 'Monitor Alert: Alert Cleared';

public function toArray(): array
{
$startedAt = Carbon::parse(Arr::get($this->alert, 'downtime.started_at'));
$endedAt = Carbon::parse(Arr::get($this->alert, 'downtime.ended_at'));

return array_merge(
parent::toArray(),
[
'duration' => $endedAt->diffForHumans($startedAt, Carbon::DIFF_ABSOLUTE, false, 3),
]
);
}
}
12 changes: 12 additions & 0 deletions src/Notifications/AlertRaised.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,20 @@

namespace TransformStudios\Uptime\Notifications;

use Statamic\Support\Arr;

class AlertRaised extends AbstractAlert
{
protected string $event = 'alert_raised';
protected string $subject = 'Monitor Alert: Error Detected';

public function toArray(): array
{
return array_merge(
parent::toArray(),
[
'locations' => implode(',', Arr::get($this->alert, 'locations')),
]
);
}
}

0 comments on commit 6f2541d

Please sign in to comment.