Skip to content

Add "Under maintenance" status to components and systems #287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "cachethq/core",
"name": "pingoo31/cachet-3-core",
"description": "Cachet core package.",
"license": "proprietary",
"keywords": [
Expand Down
1 change: 1 addition & 0 deletions resources/lang/en/component.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
'performance_issues' => 'Performance Issues',
'partial_outage' => 'Partial Outage',
'major_outage' => 'Major Outage',
'under_maintenance' => 'Under maintenance',
'unknown' => 'Unknown',
],

Expand Down
1 change: 1 addition & 0 deletions resources/lang/en/system_status.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
'operational' => 'All systems are operational.',
'partial_outage' => 'Some systems are experiencing issues.',
'major_outage' => 'Some systems are experiencing major issues.',
'under_maintenance' => 'Some systems are under maintenance.',
];
1 change: 1 addition & 0 deletions resources/lang/fr/component.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
'performance_issues' => 'Problèmes de performance',
'partial_outage' => 'Panne partielle',
'major_outage' => 'Panne majeure',
'under_maintenance' => 'En maintenance',
'unknown' => 'Inconnu',
],
];
1 change: 1 addition & 0 deletions resources/lang/fr/system_status.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
'operational' => 'Tous les systèmes sont opérationnels.',
'partial_outage' => 'Certains systèmes rencontrent des problèmes.',
'major_outage' => 'Certains systèmes rencontrent des problèmes majeurs.',
'under_maintenance' => 'Certains systèmes sont en maintenance.',
];
36 changes: 36 additions & 0 deletions resources/svg/component-under-maintenance.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/Enums/ComponentStatusEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum ComponentStatusEnum: int implements HasColor, HasIcon, HasLabel
case partial_outage = 3;
case major_outage = 4;
case unknown = 5;
case under_maintenance = 6;

public static function outage(): array
{
Expand All @@ -31,6 +32,7 @@ public function getLabel(): string
self::performance_issues => __('cachet::component.status.performance_issues'),
self::partial_outage => __('cachet::component.status.partial_outage'),
self::major_outage => __('cachet::component.status.major_outage'),
self::under_maintenance => __('cachet::component.status.under_maintenance'),
default => __('cachet::component.status.unknown'),
};
}
Expand All @@ -42,6 +44,7 @@ public function getIcon(): string
self::performance_issues => 'cachet-component-performance-issues',
self::partial_outage => 'cachet-component-partial-outage',
self::major_outage => 'cachet-component-major-outage',
self::under_maintenance => 'cachet-component-under-maintenance',
default => 'cachet-unknown',
};
}
Expand All @@ -53,6 +56,7 @@ public function getColor(): array
self::performance_issues => Color::Purple,
self::partial_outage => Color::Amber,
self::major_outage => Color::Red,
self::under_maintenance => Color::Orange,
default => Color::Blue,
};
}
Expand Down
4 changes: 4 additions & 0 deletions src/Enums/SystemStatusEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ enum SystemStatusEnum implements HasColor, HasIcon, HasLabel
case operational;
case partial_outage;
case major_outage;
case under_maintenance;

public function getLabel(): string
{
return match ($this) {
self::operational => __('cachet::system_status.operational'),
self::partial_outage => __('cachet::system_status.partial_outage'),
self::major_outage => __('cachet::system_status.major_outage'),
self::under_maintenance => __('cachet::system_status.under_maintenance'),
};
}

Expand All @@ -28,6 +30,7 @@ public function getColor(): array
self::operational => Color::Green,
self::partial_outage => Color::Amber,
self::major_outage => Color::Red,
self::under_maintenance => Color::Orange,
};
}

Expand All @@ -37,6 +40,7 @@ public function getIcon(): string
self::operational => 'heroicon-m-check-circle',
self::partial_outage => 'cachet-component-partial-outage',
self::major_outage => 'cachet-component-major-outage',
self::under_maintenance => 'cachet-component-under-maintenance',
};
}
}
17 changes: 17 additions & 0 deletions src/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public function current(): SystemStatusEnum
{
$components = $this->components();

if ($this->underMaintenance()) {
return SystemStatusEnum::under_maintenance;
}

if ($this->majorOutage()) {
return SystemStatusEnum::major_outage;
}
Expand All @@ -39,6 +43,18 @@ public function current(): SystemStatusEnum
return SystemStatusEnum::partial_outage;
}

/**
* Determine if the system is under maintenance.
*/
public function underMaintenance(): bool
{
if ((int) $this->components()->total === 0) {
return false;
}

return (int) $this->components()->under_maintenance >= 1;
}

/**
* Determine if there is a major outage.
*/
Expand Down Expand Up @@ -67,6 +83,7 @@ public function components(): object
->selectRaw('sum(case when status = ? then 1 else 0 end) as performance_issues', [ComponentStatusEnum::performance_issues])
->selectRaw('sum(case when status = ? then 1 else 0 end) as partial_outage', [ComponentStatusEnum::partial_outage])
->selectRaw('sum(case when status = ? then 1 else 0 end) as major_outage', [ComponentStatusEnum::major_outage])
->selectRaw('sum(case when status = ? then 1 else 0 end) as under_maintenance', [ComponentStatusEnum::under_maintenance])
->first();
}

Expand Down
16 changes: 13 additions & 3 deletions tests/Unit/StatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
$this->assertEquals((new Status)->current(), SystemStatusEnum::operational);
});

it('can get the current system status as under maintenance', function () {
Component::factory()->create([
'status' => ComponentStatusEnum::under_maintenance->value,
]);

$this->assertEquals((new Status)->current(), SystemStatusEnum::under_maintenance);
});

it('can get the current system status as partial outage', function () {
Component::factory()->create([
'status' => ComponentStatusEnum::operational->value,
Expand Down Expand Up @@ -73,16 +81,18 @@
['status' => ComponentStatusEnum::operational->value],
['status' => ComponentStatusEnum::partial_outage->value],
['status' => ComponentStatusEnum::major_outage->value],
['status' => ComponentStatusEnum::under_maintenance->value],
)
->count(4)
->count(5)
->create();

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

expect($components)
->total->toBe(4)
->total->toBe(5)
->operational->toBe(1)
->performance_issues->toBe(0)
->partial_outage->toBe(1)
->major_outage->toBe(1);
->major_outage->toBe(1)
->under_maintenance->toBe(1);
});