- Add comprehensive health check system with multiple endpoints - Add Prometheus metrics endpoint - Add production logging configurations (5 strategies) - Add complete deployment documentation suite: * QUICKSTART.md - 30-minute deployment guide * DEPLOYMENT_CHECKLIST.md - Printable verification checklist * DEPLOYMENT_WORKFLOW.md - Complete deployment lifecycle * PRODUCTION_DEPLOYMENT.md - Comprehensive technical reference * production-logging.md - Logging configuration guide * ANSIBLE_DEPLOYMENT.md - Infrastructure as Code automation * README.md - Navigation hub * DEPLOYMENT_SUMMARY.md - Executive summary - Add deployment scripts and automation - Add DEPLOYMENT_PLAN.md - Concrete plan for immediate deployment - Update README with production-ready features All production infrastructure is now complete and ready for deployment.
102 lines
3.0 KiB
PHP
102 lines
3.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Framework\Health\Checks;
|
|
|
|
use App\Framework\Core\ValueObjects\Duration;
|
|
use App\Framework\Deployment\Ssl\SslCertificateManager;
|
|
use App\Framework\Health\HealthCheckCategory;
|
|
use App\Framework\Health\HealthCheckInterface;
|
|
use App\Framework\Health\HealthCheckResult;
|
|
|
|
final readonly class SslHealthCheck implements HealthCheckInterface
|
|
{
|
|
public function __construct(
|
|
private SslCertificateManager $sslManager
|
|
) {
|
|
}
|
|
|
|
public function check(): HealthCheckResult
|
|
{
|
|
$startTime = microtime(true);
|
|
|
|
try {
|
|
$status = $this->sslManager->getCertificateStatus();
|
|
$responseTime = Duration::fromSeconds(microtime(true) - $startTime);
|
|
|
|
$data = [
|
|
'valid' => $status->isValid(),
|
|
'days_until_expiry' => $status->getDaysUntilExpiry(),
|
|
'issuer' => $status->getIssuer(),
|
|
'subject' => $status->getSubject(),
|
|
'response_time_ms' => $responseTime->toMilliseconds(),
|
|
];
|
|
|
|
// Certificate expired or expiring soon
|
|
if (!$status->isValid()) {
|
|
return HealthCheckResult::unhealthy(
|
|
'SSL Certificate',
|
|
'Certificate is invalid or expired',
|
|
$data,
|
|
$responseTime->toMilliseconds()
|
|
);
|
|
}
|
|
|
|
// Warning if expiring within 7 days
|
|
if ($status->getDaysUntilExpiry() <= 7) {
|
|
return HealthCheckResult::warning(
|
|
'SSL Certificate',
|
|
"Certificate expiring in {$status->getDaysUntilExpiry()} days",
|
|
$data,
|
|
$responseTime->toMilliseconds()
|
|
);
|
|
}
|
|
|
|
// Warning if expiring within 30 days
|
|
if ($status->getDaysUntilExpiry() <= 30) {
|
|
return HealthCheckResult::warning(
|
|
'SSL Certificate',
|
|
"Certificate expiring in {$status->getDaysUntilExpiry()} days (renewal recommended)",
|
|
$data,
|
|
$responseTime->toMilliseconds()
|
|
);
|
|
}
|
|
|
|
return HealthCheckResult::healthy(
|
|
'SSL Certificate',
|
|
$data,
|
|
$responseTime->toMilliseconds()
|
|
);
|
|
|
|
} catch (\Throwable $e) {
|
|
$responseTime = Duration::fromSeconds(microtime(true) - $startTime);
|
|
|
|
return HealthCheckResult::unhealthy(
|
|
'SSL Certificate',
|
|
'SSL check failed: ' . $e->getMessage(),
|
|
[
|
|
'error_type' => get_class($e),
|
|
],
|
|
$responseTime->toMilliseconds(),
|
|
$e
|
|
);
|
|
}
|
|
}
|
|
|
|
public function getName(): string
|
|
{
|
|
return 'SSL Certificate';
|
|
}
|
|
|
|
public function getCategory(): HealthCheckCategory
|
|
{
|
|
return HealthCheckCategory::SECURITY;
|
|
}
|
|
|
|
public function getTimeout(): int
|
|
{
|
|
return 5000; // 5 seconds
|
|
}
|
|
}
|