Skip to content

Commit

Permalink
fix: improved task notification info
Browse files Browse the repository at this point in the history
  • Loading branch information
lewislarsen committed Jun 16, 2024
1 parent cdc3cd1 commit 1a90a27
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
57 changes: 47 additions & 10 deletions app/Models/BackupTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,60 +349,97 @@ public function sendEmailNotification($latestLog): void
public function sendDiscordWebhookNotification($latestLog): void
{
$status = $latestLog?->successful_at ? 'success' : 'failure';
$message = $latestLog?->successful_at ? 'Backup task successful' : 'Backup task failed';
$message = $latestLog?->successful_at ? 'The backup task was successful. Please see the details below for more information about this task.' : 'The backup task failed. Please see the details below for more information about this task.';
$color = $latestLog?->successful_at ? 3066993 : 15158332; // Green for success, Red for failure

$embed = [
'title' => $this->label,
'title' => $this->label . ' Backup Task',
'description' => $message,
'color' => $color,
'fields' => [
[
'name' => 'Status',
'name' => __('Backup Type'),
'value' => ucfirst($this->type),
'inline' => true,
],
[
'name' => __('Remote Server'),
'value' => $this->remoteServer?->label,
'inline' => true,
],
[
'name' => __('Backup Destination'),
'value' => $this->backupDestination?->label . ' (' . $this->backupDestination?->type() . ')',
'inline' => true,
],
[
'name' => __('Result'),
'value' => ucfirst($status),
'inline' => true,
],
[
'name' => 'Timestamp',
'value' => $latestLog?->created_at->toDateTimeString(),
'name' => __('Ran at'),
'value' => $latestLog?->created_at->format('jS F Y, H:i:s'),
'inline' => true,
],
],
'footer' => [
'icon_url' => asset('images/logo.png'),
'text' => __('This notification was sent by :app.', ['app' => config('app.name')]),
],
];

$http = Http::withHeaders([
'Content-Type' => 'application/json',
]);

$http->post($this->notify_discord_webhook, [
'username' => __('Vanguard'),
'avatar_url' => asset('images/logo-on-black.png'),
'embeds' => [$embed],
]);
}

public function sendSlackWebhookNotification($latestLog): void
{
$status = $latestLog?->successful_at ? 'success' : 'failure';
$message = $latestLog?->successful_at ? 'Backup task successful' : 'Backup task failed';
$message = $latestLog?->successful_at ? 'The backup task was successful. Please see the details below for more information about this task.' : 'The backup task failed. Please see the details below for more information about this task.';
$color = $latestLog?->successful_at ? 'good' : 'danger'; // Green for success, Red for failure

$payload = [
'attachments' => [
[
'title' => $this->label,
'title' => $this->label . ' Backup Task',
'text' => $message,
'color' => $color,
'fields' => [
[
'title' => 'Status',
'title' => __('Backup Type'),
'value' => ucfirst($this->type),
'short' => true,
],
[
'title' => __('Remote Server'),
'value' => $this->remoteServer?->label,
'short' => true,
],
[
'title' => __('Backup Destination'),
'value' => $this->backupDestination?->label . ' (' . $this->backupDestination?->type() . ')',
'short' => true,
],
[
'title' => __('Result'),
'value' => ucfirst($status),
'short' => true,
],
[
'title' => 'Timestamp',
'value' => $latestLog?->created_at->toDateTimeString(),
'title' => __('Ran at'),
'value' => $latestLog?->created_at->format('jS F Y, H:i:s'),
'short' => true,
],
],
'footer' => __('This notification was sent by :app.', ['app' => config('app.name')]),
],
],
];
Expand Down
Binary file added public/images/logo-on-black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1a90a27

Please sign in to comment.