Skip to content

Commit 37335d8

Browse files
committed
update
1 parent 074c9f9 commit 37335d8

File tree

2 files changed

+123
-3
lines changed

2 files changed

+123
-3
lines changed

web/Modules/Caddy/App/Filament/Pages/CaddyHealthCheck.php

Lines changed: 116 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,17 @@ private function checkServiceStatus(): array
6565
private function checkConfigValidity(): array
6666
{
6767
$output = shell_exec('caddy validate --config /etc/caddy/Caddyfile 2>&1');
68-
$isValid = strpos($output, 'valid') !== false;
68+
69+
// Check if output contains success indicators (case insensitive)
70+
$outputLower = strtolower($output);
71+
$isValid = (strpos($outputLower, 'valid configuration') !== false) ||
72+
(strpos($outputLower, 'configuration is valid') !== false) ||
73+
(strpos($outputLower, 'valid') !== false && strpos($outputLower, 'error') === false);
6974

7075
return [
7176
'status' => $isValid ? 'healthy' : 'unhealthy',
7277
'message' => $isValid ? 'Configuration is valid' : 'Configuration has errors',
73-
'details' => $output,
78+
'details' => $output ?: 'No output from validation command',
7479
];
7580
}
7681

@@ -151,6 +156,115 @@ private function checkLogErrors(): array
151156
];
152157
}
153158

159+
public function refreshHealth(): void
160+
{
161+
$this->runHealthCheck();
162+
}
163+
164+
public function getHealthResults(): array
165+
{
166+
// Calculate overall health status and score
167+
$healthyCount = 0;
168+
$warningCount = 0;
169+
$unhealthyCount = 0;
170+
$totalChecks = count($this->healthData);
171+
172+
foreach ($this->healthData as $check) {
173+
switch ($check['status']) {
174+
case 'healthy':
175+
$healthyCount++;
176+
break;
177+
case 'warning':
178+
$warningCount++;
179+
break;
180+
case 'unhealthy':
181+
$unhealthyCount++;
182+
break;
183+
}
184+
}
185+
186+
// Calculate overall score (healthy = 100%, warning = 50%, unhealthy = 0%)
187+
$score = $totalChecks > 0 ? round(($healthyCount * 100 + $warningCount * 50) / $totalChecks) : 0;
188+
189+
// Determine overall status
190+
$overallStatus = 'healthy';
191+
if ($unhealthyCount > 0) {
192+
$overallStatus = 'unhealthy';
193+
} elseif ($warningCount > 0) {
194+
$overallStatus = 'warning';
195+
}
196+
197+
return [
198+
'timestamp' => now()->format('Y-m-d H:i:s'),
199+
'overall' => [
200+
'status' => $overallStatus,
201+
'score' => $score,
202+
'healthy_count' => $healthyCount,
203+
'warning_count' => $warningCount,
204+
'unhealthy_count' => $unhealthyCount,
205+
'total_checks' => $totalChecks,
206+
],
207+
'summary' => [
208+
'healthy' => $healthyCount,
209+
'warning' => $warningCount,
210+
'critical' => $unhealthyCount,
211+
'total' => $totalChecks,
212+
],
213+
'checks' => [
214+
'service' => [
215+
[
216+
'name' => 'Caddy Service Status',
217+
'status' => $this->healthData['service_status']['status'],
218+
'message' => $this->healthData['service_status']['message'],
219+
'details' => $this->healthData['service_status']['details'],
220+
],
221+
],
222+
'configuration' => [
223+
[
224+
'name' => 'Configuration Validity',
225+
'status' => $this->healthData['config_validity']['status'],
226+
'message' => $this->healthData['config_validity']['message'],
227+
'details' => $this->healthData['config_validity']['details'],
228+
],
229+
],
230+
'network' => [
231+
[
232+
'name' => 'Port Availability',
233+
'status' => $this->healthData['port_availability']['status'],
234+
'message' => $this->healthData['port_availability']['message'],
235+
'details' => $this->healthData['port_availability']['details'],
236+
],
237+
[
238+
'name' => 'Apache Connectivity',
239+
'status' => $this->healthData['apache_connectivity']['status'],
240+
'message' => $this->healthData['apache_connectivity']['message'],
241+
'details' => $this->healthData['apache_connectivity']['details'],
242+
],
243+
],
244+
'system' => [
245+
[
246+
'name' => 'SSL Certificates',
247+
'status' => $this->healthData['ssl_certificates']['status'],
248+
'message' => $this->healthData['ssl_certificates']['message'],
249+
'details' => $this->healthData['ssl_certificates']['details'],
250+
],
251+
[
252+
'name' => 'Disk Space',
253+
'status' => $this->healthData['disk_space']['status'],
254+
'message' => $this->healthData['disk_space']['message'],
255+
'details' => $this->healthData['disk_space']['details'],
256+
],
257+
[
258+
'name' => 'Log Errors',
259+
'status' => $this->healthData['log_errors']['status'],
260+
'message' => $this->healthData['log_errors']['message'],
261+
'details' => $this->healthData['log_errors']['details'],
262+
],
263+
],
264+
],
265+
];
266+
}
267+
154268
public function getTitle(): string
155269
{
156270
return 'Caddy Health Check';

web/Modules/Caddy/resources/views/filament/pages/caddy-health-check.blade.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,13 @@ class="ml-4 px-3 py-2 bg-blue-600 hover:bg-blue-700 text-white text-sm rounded-l
205205
<div class="font-medium text-gray-900 dark:text-white">{{ $check['name'] }}</div>
206206
<div class="text-sm text-gray-600 dark:text-gray-400">{{ $check['message'] }}</div>
207207
@if(isset($check['details']))
208-
<div class="text-xs text-gray-500 dark:text-gray-500 mt-1">{{ $check['details'] }}</div>
208+
<div class="text-xs text-gray-500 dark:text-gray-500 mt-1">
209+
@if(is_array($check['details']))
210+
{{ json_encode($check['details'], JSON_PRETTY_PRINT) }}
211+
@else
212+
{{ $check['details'] }}
213+
@endif
214+
</div>
209215
@endif
210216
</div>
211217
</div>

0 commit comments

Comments
 (0)