1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
{ lib, pkgs, ... }:
{
name = "nvme-rs";
meta = {
maintainers = with lib.maintainers; [ liberodark ];
};
nodes = {
monitor =
{ config, pkgs, ... }:
{
virtualisation = {
emptyDiskImages = [
512
512
];
};
environment.systemPackages = with pkgs; [
nvme-rs
jq
];
services.nvme-rs = {
enable = true;
package = pkgs.nvme-rs;
settings = {
check_interval_secs = 60;
thresholds = {
temp_warning = 50;
temp_critical = 60;
wear_warning = 15;
wear_critical = 40;
spare_warning = 60;
error_threshold = 100;
};
email = {
smtp_server = "mail";
smtp_port = 25;
smtp_username = "nvme-monitor@example.com";
smtp_password_file = "/run/secrets/smtp-password";
from = "NVMe Monitor <nvme-monitor@example.com>";
to = "admin@example.com";
use_tls = false;
};
};
};
systemd.tmpfiles.rules = [
"f /run/secrets/smtp-password 0600 root root - testpassword"
];
networking.firewall.enable = false;
};
mail =
{ config, pkgs, ... }:
{
services.postfix = {
enable = true;
hostname = "mail";
domain = "example.com";
networks = [ "0.0.0.0/0" ];
relayDomains = [ "example.com" ];
localRecipients = [ "admin" ];
settings = {
main = {
inet_interfaces = "all";
inet_protocols = "ipv4";
smtpd_recipient_restrictions = "permit_mynetworks";
smtpd_relay_restrictions = "permit_mynetworks";
};
};
};
users.users.admin = {
isNormalUser = true;
home = "/home/admin";
};
networking.firewall = {
allowedTCPPorts = [ 25 ];
};
};
client =
{ config, pkgs, ... }:
{
virtualisation = {
emptyDiskImages = [ 256 ];
};
environment.systemPackages = with pkgs; [
nvme-rs
jq
];
environment.etc."nvme-rs/config.toml".text = ''
check_interval_secs = 3600
[thresholds]
temp_warning = 55
temp_critical = 65
wear_warning = 20
wear_critical = 50
spare_warning = 50
error_threshold = 5000
'';
};
};
testScript =
{ nodes, ... }:
''
import json
start_all()
for machine in [monitor, mail, client]:
machine.wait_for_unit("multi-user.target")
mail.wait_for_unit("postfix.service")
mail.wait_for_open_port(25)
client.succeed("nvme-rs check || true")
client.succeed("nvme-rs check --config /etc/nvme-rs/config.toml || true")
output = client.succeed("nvme-rs check --format json || echo '[]'")
data = json.loads(output)
assert isinstance(data, list), "JSON output should be a list"
monitor.wait_for_unit("nvme-rs.service")
monitor.succeed("systemctl is-active nvme-rs.service")
config_path = monitor.succeed(
"systemctl status nvme-rs | grep -oE '/nix/store[^ ]*nvme-rs.toml' | head -1"
).strip()
if config_path:
monitor.succeed(f"grep 'check_interval_secs = 60' {config_path}")
monitor.succeed(f"grep 'temp_warning = 50' {config_path}")
monitor.succeed(f"grep 'smtp_server = \"mail\"' {config_path}")
logs = monitor.succeed("journalctl -u nvme-rs.service -n 20 --no-pager")
assert "Starting NVMe monitor daemon" in logs or "Check interval" in logs
monitor.succeed("test -f /run/secrets/smtp-password")
monitor.succeed("nc -zv mail 25")
monitor.fail("nvme-rs daemon --config /nonexistent.toml 2>&1 | grep -E 'Failed to read'")
'';
}
|