Skip to content

Commit 905e726

Browse files
Pingoo31Pingoo-31
andauthored
Add "Under maintenance" status to components and systems (#287)
Co-authored-by: THIPHONET Stephane DGAC/DTI <[email protected]>
1 parent ef270e5 commit 905e726

File tree

10 files changed

+79
-4
lines changed

10 files changed

+79
-4
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "cachethq/core",
2+
"name": "pingoo31/cachet-3-core",
33
"description": "Cachet core package.",
44
"license": "proprietary",
55
"keywords": [

resources/lang/en/component.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
'performance_issues' => 'Performance Issues',
3434
'partial_outage' => 'Partial Outage',
3535
'major_outage' => 'Major Outage',
36+
'under_maintenance' => 'Under maintenance',
3637
'unknown' => 'Unknown',
3738
],
3839

resources/lang/en/system_status.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
'operational' => 'All systems are operational.',
55
'partial_outage' => 'Some systems are experiencing issues.',
66
'major_outage' => 'Some systems are experiencing major issues.',
7+
'under_maintenance' => 'Some systems are under maintenance.',
78
];

resources/lang/fr/component.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
'performance_issues' => 'Problèmes de performance',
3434
'partial_outage' => 'Panne partielle',
3535
'major_outage' => 'Panne majeure',
36+
'under_maintenance' => 'En maintenance',
3637
'unknown' => 'Inconnu',
3738
],
3839
];

resources/lang/fr/system_status.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
'operational' => 'Tous les systèmes sont opérationnels.',
55
'partial_outage' => 'Certains systèmes rencontrent des problèmes.',
66
'major_outage' => 'Certains systèmes rencontrent des problèmes majeurs.',
7+
'under_maintenance' => 'Certains systèmes sont en maintenance.',
78
];
Lines changed: 36 additions & 0 deletions
Loading

src/Enums/ComponentStatusEnum.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ enum ComponentStatusEnum: int implements HasColor, HasIcon, HasLabel
1414
case partial_outage = 3;
1515
case major_outage = 4;
1616
case unknown = 5;
17+
case under_maintenance = 6;
1718

1819
public static function outage(): array
1920
{
@@ -31,6 +32,7 @@ public function getLabel(): string
3132
self::performance_issues => __('cachet::component.status.performance_issues'),
3233
self::partial_outage => __('cachet::component.status.partial_outage'),
3334
self::major_outage => __('cachet::component.status.major_outage'),
35+
self::under_maintenance => __('cachet::component.status.under_maintenance'),
3436
default => __('cachet::component.status.unknown'),
3537
};
3638
}
@@ -42,6 +44,7 @@ public function getIcon(): string
4244
self::performance_issues => 'cachet-component-performance-issues',
4345
self::partial_outage => 'cachet-component-partial-outage',
4446
self::major_outage => 'cachet-component-major-outage',
47+
self::under_maintenance => 'cachet-component-under-maintenance',
4548
default => 'cachet-unknown',
4649
};
4750
}
@@ -53,6 +56,7 @@ public function getColor(): array
5356
self::performance_issues => Color::Purple,
5457
self::partial_outage => Color::Amber,
5558
self::major_outage => Color::Red,
59+
self::under_maintenance => Color::Orange,
5660
default => Color::Blue,
5761
};
5862
}

src/Enums/SystemStatusEnum.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ enum SystemStatusEnum implements HasColor, HasIcon, HasLabel
1212
case operational;
1313
case partial_outage;
1414
case major_outage;
15+
case under_maintenance;
1516

1617
public function getLabel(): string
1718
{
1819
return match ($this) {
1920
self::operational => __('cachet::system_status.operational'),
2021
self::partial_outage => __('cachet::system_status.partial_outage'),
2122
self::major_outage => __('cachet::system_status.major_outage'),
23+
self::under_maintenance => __('cachet::system_status.under_maintenance'),
2224
};
2325
}
2426

@@ -28,6 +30,7 @@ public function getColor(): array
2830
self::operational => Color::Green,
2931
self::partial_outage => Color::Amber,
3032
self::major_outage => Color::Red,
33+
self::under_maintenance => Color::Orange,
3134
};
3235
}
3336

@@ -37,6 +40,7 @@ public function getIcon(): string
3740
self::operational => 'heroicon-m-check-circle',
3841
self::partial_outage => 'cachet-component-partial-outage',
3942
self::major_outage => 'cachet-component-major-outage',
43+
self::under_maintenance => 'cachet-component-under-maintenance',
4044
};
4145
}
4246
}

src/Status.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ public function current(): SystemStatusEnum
2424
{
2525
$components = $this->components();
2626

27+
if ($this->underMaintenance()) {
28+
return SystemStatusEnum::under_maintenance;
29+
}
30+
2731
if ($this->majorOutage()) {
2832
return SystemStatusEnum::major_outage;
2933
}
@@ -39,6 +43,18 @@ public function current(): SystemStatusEnum
3943
return SystemStatusEnum::partial_outage;
4044
}
4145

46+
/**
47+
* Determine if the system is under maintenance.
48+
*/
49+
public function underMaintenance(): bool
50+
{
51+
if ((int) $this->components()->total === 0) {
52+
return false;
53+
}
54+
55+
return (int) $this->components()->under_maintenance >= 1;
56+
}
57+
4258
/**
4359
* Determine if there is a major outage.
4460
*/
@@ -67,6 +83,7 @@ public function components(): object
6783
->selectRaw('sum(case when status = ? then 1 else 0 end) as performance_issues', [ComponentStatusEnum::performance_issues])
6884
->selectRaw('sum(case when status = ? then 1 else 0 end) as partial_outage', [ComponentStatusEnum::partial_outage])
6985
->selectRaw('sum(case when status = ? then 1 else 0 end) as major_outage', [ComponentStatusEnum::major_outage])
86+
->selectRaw('sum(case when status = ? then 1 else 0 end) as under_maintenance', [ComponentStatusEnum::under_maintenance])
7087
->first();
7188
}
7289

tests/Unit/StatusTest.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@
4646
$this->assertEquals((new Status)->current(), SystemStatusEnum::operational);
4747
});
4848

49+
it('can get the current system status as under maintenance', function () {
50+
Component::factory()->create([
51+
'status' => ComponentStatusEnum::under_maintenance->value,
52+
]);
53+
54+
$this->assertEquals((new Status)->current(), SystemStatusEnum::under_maintenance);
55+
});
56+
4957
it('can get the current system status as partial outage', function () {
5058
Component::factory()->create([
5159
'status' => ComponentStatusEnum::operational->value,
@@ -73,16 +81,18 @@
7381
['status' => ComponentStatusEnum::operational->value],
7482
['status' => ComponentStatusEnum::partial_outage->value],
7583
['status' => ComponentStatusEnum::major_outage->value],
84+
['status' => ComponentStatusEnum::under_maintenance->value],
7685
)
77-
->count(4)
86+
->count(5)
7887
->create();
7988

8089
$components = (new Status)->components();
8190

8291
expect($components)
83-
->total->toBe(4)
92+
->total->toBe(5)
8493
->operational->toBe(1)
8594
->performance_issues->toBe(0)
8695
->partial_outage->toBe(1)
87-
->major_outage->toBe(1);
96+
->major_outage->toBe(1)
97+
->under_maintenance->toBe(1);
8898
});

0 commit comments

Comments
 (0)