1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spatie\UptimeMonitor\Commands\MonitorLists; |
4
|
|
|
|
5
|
|
|
use Spatie\UptimeMonitor\Helpers\ConsoleOutput; |
6
|
|
|
use Spatie\UptimeMonitor\Models\Monitor; |
7
|
|
|
use Spatie\UptimeMonitor\MonitorRepository; |
8
|
|
|
|
9
|
|
|
class UptimeCheckFailed |
10
|
|
|
{ |
11
|
|
|
public static function display() |
12
|
|
|
{ |
13
|
|
|
$failingMonitors = MonitorRepository::getWithFailingUptimeCheck(); |
14
|
|
|
|
15
|
|
|
if (! $failingMonitors->count()) { |
16
|
|
|
return; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
ConsoleOutput::warn('Uptime check failed'); |
20
|
|
|
ConsoleOutput::warn('==================='); |
21
|
|
|
|
22
|
|
View Code Duplication |
$rows = $failingMonitors->map(function (Monitor $monitor) { |
|
|
|
|
23
|
|
|
$certificateFound = ''; |
24
|
|
|
$certificateExpirationDate = ''; |
25
|
|
|
$certificateIssuer = ''; |
26
|
|
|
|
27
|
|
|
$url = $monitor->url; |
28
|
|
|
|
29
|
|
|
$reachable = $monitor->uptimeStatusAsEmoji; |
30
|
|
|
|
31
|
|
|
$offlineSince = $monitor->formattedLastUpdatedStatusChangeDate('forHumans'); |
32
|
|
|
|
33
|
|
|
$reason = $monitor->chunkedLastFailureReason; |
34
|
|
|
|
35
|
|
|
if ($monitor->certificate_check_enabled) { |
36
|
|
|
$certificateFound = $monitor->certificateStatusAsEmoji; |
37
|
|
|
$certificateExpirationDate = $monitor->formattedCertificateExpirationDate('forHumans'); |
38
|
|
|
$certificateIssuer = $monitor->certificate_issuer; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
return compact('url', 'reachable', 'offlineSince', 'reason', 'certificateFound', 'certificateExpirationDate', 'certificateIssuer'); |
42
|
|
|
}); |
43
|
|
|
|
44
|
|
|
$titles = ['URL', 'Reachable', 'Offline since', 'Reason', 'Certificate', 'Certificate expiration date', 'Certificate issuer']; |
45
|
|
|
|
46
|
|
|
ConsoleOutput::table($titles, $rows); |
47
|
|
|
ConsoleOutput::line(''); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.