feat: DB 백업 시스템 구축 (Phase 1,2,4)
- Phase 1: backup.conf.example + sam-db-backup.sh 백업 스크립트 - Phase 2: BackupCheckCommand + StatMonitorService.recordBackupFailure() - Phase 2: routes/console.php에 db:backup-check 05:00 스케줄 등록 - Phase 4: SlackNotificationService 생성 (웹훅 알림) - Phase 4: BackupCheckCommand/StatMonitorService에 Slack 알림 연동 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Services\Stats;
|
||||
|
||||
use App\Models\Stats\StatAlert;
|
||||
use App\Services\SlackNotificationService;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class StatMonitorService
|
||||
@@ -26,6 +27,13 @@ public function recordAggregationFailure(int $tenantId, string $domain, string $
|
||||
'is_resolved' => false,
|
||||
'created_at' => now(),
|
||||
]);
|
||||
|
||||
// critical 알림 Slack 전송
|
||||
app(SlackNotificationService::class)->sendStatAlert(
|
||||
"[{$jobType}] 집계 실패",
|
||||
mb_substr($errorMessage, 0, 300),
|
||||
$domain
|
||||
);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('stat_alert 기록 실패', [
|
||||
'tenant_id' => $tenantId,
|
||||
@@ -94,6 +102,13 @@ public function recordMismatch(int $tenantId, string $domain, string $label, flo
|
||||
'is_resolved' => false,
|
||||
'created_at' => now(),
|
||||
]);
|
||||
|
||||
// critical 알림 Slack 전송
|
||||
app(SlackNotificationService::class)->sendStatAlert(
|
||||
"[{$label}] 정합성 불일치",
|
||||
"원본={$expected}, 통계={$actual}, 차이=" . ($actual - $expected),
|
||||
$domain
|
||||
);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('stat_alert 기록 실패 (mismatch)', [
|
||||
'tenant_id' => $tenantId,
|
||||
@@ -103,6 +118,33 @@ public function recordMismatch(int $tenantId, string $domain, string $label, flo
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 백업 실패 알림 기록 (시스템 레벨, tenantId=0)
|
||||
*/
|
||||
public function recordBackupFailure(string $title, string $message): void
|
||||
{
|
||||
try {
|
||||
StatAlert::create([
|
||||
'tenant_id' => 0,
|
||||
'alert_type' => 'backup_failure',
|
||||
'domain' => 'backup',
|
||||
'severity' => 'critical',
|
||||
'title' => $title,
|
||||
'message' => mb_substr($message, 0, 500),
|
||||
'current_value' => 0,
|
||||
'threshold_value' => 0,
|
||||
'is_read' => false,
|
||||
'is_resolved' => false,
|
||||
'created_at' => now(),
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('stat_alert 기록 실패 (backup_failure)', [
|
||||
'title' => $title,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 알림 해결 처리
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user