initial commit
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Hosting\Notifications;
|
||||
|
||||
use App\Models\Customer;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class HostingNotificationService
|
||||
{
|
||||
public function provisioningCompleted(Customer $vm, User $user): void
|
||||
{
|
||||
$this->send($user, 'VM bereit: '.$vm->name, "Ihre VM {$vm->name} wurde erfolgreich provisioniert.", [
|
||||
'event' => 'provisioning.completed',
|
||||
'customer_id' => $vm->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function provisioningFailed(Customer $vm, User $user, string $error): void
|
||||
{
|
||||
$this->send($user, 'Provisioning fehlgeschlagen: '.$vm->name, $error, [
|
||||
'event' => 'provisioning.failed',
|
||||
'customer_id' => $vm->id,
|
||||
'error' => $error,
|
||||
]);
|
||||
}
|
||||
|
||||
public function vmDown(Customer $vm, User $user): void
|
||||
{
|
||||
$this->send($user, 'VM offline: '.$vm->name, "Ihre VM {$vm->name} ist nicht mehr erreichbar (Proxmox).", [
|
||||
'event' => 'vm.down',
|
||||
]);
|
||||
}
|
||||
|
||||
private function send(User $user, string $subject, string $body, array $webhookPayload): void
|
||||
{
|
||||
if (config('hosting.plesk.mail_enabled', true)) {
|
||||
try {
|
||||
Mail::raw($body, fn ($m) => $m->to($user->email)->subject($subject));
|
||||
} catch (\Throwable $e) {
|
||||
Log::warning('Mail send failed', ['error' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
$url = config('hosting.notifications.webhook_url');
|
||||
if ($url) {
|
||||
try {
|
||||
Http::timeout(10)->post($url, array_merge($webhookPayload, [
|
||||
'email' => $user->email,
|
||||
'subject' => $subject,
|
||||
'body' => $body,
|
||||
]));
|
||||
} catch (\Throwable $e) {
|
||||
Log::warning('Webhook failed', ['error' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user