feat(server): pure Status.compute/2 for ok/warning/critical/offline
This commit is contained in:
parent
9c457c1f68
commit
f3e7fab4d2
2 changed files with 102 additions and 0 deletions
61
server/test/server/status_test.exs
Normal file
61
server/test/server/status_test.exs
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
defmodule Server.StatusTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
alias Server.Status
|
||||
|
||||
describe "compute/2" do
|
||||
test "returns :offline when host status is offline, regardless of payload" do
|
||||
assert Status.compute("offline", %{"zfs_pools" => %{"pools" => [healthy_pool()]}}) ==
|
||||
:offline
|
||||
end
|
||||
|
||||
test "returns :ok with all-healthy payload" do
|
||||
payload = %{
|
||||
"zfs_pools" => %{"pools" => [healthy_pool()]},
|
||||
"system_info" => %{"pending_updates" => 0}
|
||||
}
|
||||
|
||||
assert Status.compute("online", payload) == :ok
|
||||
end
|
||||
|
||||
test "returns :critical for degraded pool" do
|
||||
payload = %{"zfs_pools" => %{"pools" => [Map.put(healthy_pool(), "health", "DEGRADED")]}}
|
||||
assert Status.compute("online", payload) == :critical
|
||||
end
|
||||
|
||||
test "returns :critical for pool capacity > 90" do
|
||||
payload = %{"zfs_pools" => %{"pools" => [Map.put(healthy_pool(), "capacity_percent", 95)]}}
|
||||
assert Status.compute("online", payload) == :critical
|
||||
end
|
||||
|
||||
test "returns :warning for pool capacity 80..90" do
|
||||
payload = %{"zfs_pools" => %{"pools" => [Map.put(healthy_pool(), "capacity_percent", 85)]}}
|
||||
assert Status.compute("online", payload) == :warning
|
||||
end
|
||||
|
||||
test "returns :warning for pending OS updates > 0" do
|
||||
payload = %{
|
||||
"zfs_pools" => %{"pools" => [healthy_pool()]},
|
||||
"system_info" => %{"pending_updates" => 3}
|
||||
}
|
||||
|
||||
assert Status.compute("online", payload) == :warning
|
||||
end
|
||||
|
||||
test "returns :ok when payload is nil (never-seen host) but host is online" do
|
||||
assert Status.compute("online", nil) == :ok
|
||||
end
|
||||
|
||||
test "treats never_connected like offline" do
|
||||
assert Status.compute("never_connected", nil) == :offline
|
||||
end
|
||||
end
|
||||
|
||||
defp healthy_pool do
|
||||
%{
|
||||
"name" => "rpool",
|
||||
"health" => "ONLINE",
|
||||
"capacity_percent" => 40
|
||||
}
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue