]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - modules/private/monitoring/objects_common.nix
Refactor monitoring to avoid useless resources in each machine
[perso/Immae/Config/Nix.git] / modules / private / monitoring / objects_common.nix
CommitLineData
eb071dd4 1{ hostFQDN
e820134d 2, hostName
2d7caffb 3, interface ? "eth0"
eb071dd4
IB
4, processWarn ? "250"
5, processAlert ? "400"
c41d0de8 6, loadWarn ? "0.9"
7ad4966f
IB
7, load5Warn ? loadWarn
8, load15Warn ? load5Warn
c41d0de8 9, loadAlert ? "1.0"
7ad4966f
IB
10, load5Alert ? loadAlert
11, load15Alert ? load5Alert
eb071dd4 12, mdadm
e820134d
IB
13, master
14, lib
acab8301 15, mypluginsConfig
eb071dd4
IB
16, ...
17}:
e820134d
IB
18let
19 defaultPassiveInfo = {
20 filter = lib.attrsets.filterAttrs
21 (k: v: builtins.elem k ["service_description"] || builtins.substring 0 1 k == "_");
22 use = "external-passive-service";
23 freshness_threshold = "450";
24 retry_interval = "1";
25 servicegroups = "webstatus-resources";
26 host_name = hostFQDN;
27 };
28in
eb071dd4
IB
29{
30 host = {
31 "${hostFQDN}" = {
32 alias = hostFQDN;
33 address = hostFQDN;
34 use = "linux-server";
e820134d
IB
35 hostgroups = "webstatus-hosts";
36 _webstatus_name = hostName;
2edbb2d8 37 _webstatus_vhost = "status.immae.eu";
eb071dd4
IB
38 };
39 };
40 service = [
41 {
e820134d 42 passiveInfo = defaultPassiveInfo;
eb071dd4
IB
43 service_description = "Size on root partition";
44 use = "local-service";
45 check_command = ["check_local_disk" "20%" "10%" "/"];
46 }
47 {
e820134d 48 passiveInfo = defaultPassiveInfo;
eb071dd4
IB
49 service_description = "Total number of process";
50 use = "local-service";
51 check_command = [
52 "check_local_procs"
53 processWarn
54 processAlert
55 "RSZDT"
56 ];
57 }
2d7caffb
IB
58 {
59 passiveInfo = defaultPassiveInfo;
60 service_description = "Network bandwidth";
61 use = "local-service";
62 check_interval = "2";
63 max_check_attempts = "20";
64 retry_interval = "2";
65 check_command = [
66 "check_local_bandwidth"
67 interface
68 "20480" # kb/s
69 "51200" # kb/s
70 ];
71 }
eb071dd4 72 {
e820134d 73 passiveInfo = defaultPassiveInfo;
eb071dd4
IB
74 service_description = "Average load";
75 use = "local-service";
76 check_command = [
77 "check_local_load"
7ad4966f
IB
78 "${loadWarn},${load5Warn},${load15Warn}"
79 "${loadAlert},${load5Alert},${load15Alert}"
eb071dd4
IB
80 ];
81 }
82 {
e820134d 83 passiveInfo = defaultPassiveInfo;
eb071dd4
IB
84 service_description = "Swap usage";
85 use = "local-service";
86 check_command = ["check_local_swap" "20" "10"];
87 }
88 {
e820134d 89 passiveInfo = defaultPassiveInfo;
eb071dd4
IB
90 service_description = "Memory usage";
91 use = "local-service";
92 check_command = ["check_memory" "80" "90"];
93 }
94 {
e820134d 95 passiveInfo = defaultPassiveInfo;
eb071dd4
IB
96 service_description = "NTP is activated and working";
97 use = "local-service";
98 check_command = ["check_ntp"];
99 }
100 {
e820134d 101 passiveInfo = defaultPassiveInfo;
eb071dd4
IB
102 service_description = "No mdadm array is degraded";
103 use = "local-service";
104 check_command = [
105 "check_command_output"
106 "${mdadm}/bin/mdadm --monitor --scan -1"
107 "^$"
108 "-s 0 -r root"
109 ];
110 }
111 ];
acab8301 112 command = lib.foldr (v: o: o // (v.commands or {})) {} (builtins.attrValues mypluginsConfig) // {
eb071dd4
IB
113 check_local_disk = "$USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$";
114 check_local_procs = "$USER1$/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$";
c41d0de8 115 check_local_load = "$USER1$/check_load -r -w $ARG1$ -c $ARG2$";
eb071dd4 116 check_local_swap = "$USER1$/check_swap -n ok -w $ARG1$ -c $ARG2$";
eb071dd4 117 check_ntp = "$USER1$/check_ntp_time -t 30 -q -H 0.arch.pool.ntp.org";
e820134d 118 check_mailq = "$USER1$/check_mailq -s -w 1 -c 2";
e820134d 119 check_smtp = "$USER1$/check_smtp -H $HOSTADDRESS$ -p 25 -S -D 21,15";
eb071dd4
IB
120
121 check_host_alive = "$USER1$/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5";
e820134d
IB
122 check_ok = "$USER1$/check_dummy 0 \"Dummy OK\"";
123 check_critical = "$USER1$/check_dummy 2 \"Dummy CRITICAL\"";
eb071dd4
IB
124 };
125 timeperiod = {
126 "24x7" = {
127 alias = "24 Hours A Day, 7 Days A Week";
128 monday = "00:00-24:00";
129 tuesday = "00:00-24:00";
130 wednesday = "00:00-24:00";
131 thursday = "00:00-24:00";
132 friday = "00:00-24:00";
133 saturday = "00:00-24:00";
134 sunday = "00:00-24:00";
135 };
136 };
e820134d
IB
137 servicegroup = {
138 webstatus-webapps = { alias = "Web applications"; };
139 webstatus-websites = { alias = "Personal websites"; };
140 webstatus-ssl = { alias = "SSL certificates"; };
141 webstatus-dns = { alias = "DNS resolution"; };
142 webstatus-remote-services = { alias = "Other remote services"; };
143 webstatus-local-services = { alias = "Other local services"; };
144 webstatus-email = { alias = "E-mail services"; };
145 webstatus-resources = { alias = "Local resources"; };
146 webstatus-databases = { alias = "Databases resources"; };
147 webstatus-backup = { alias = "Backup resources"; };
148 };
149 hostgroup = {
c41d0de8 150 webstatus-hosts = { alias = "Hosts"; };
e820134d 151 };
eb071dd4
IB
152 contactgroup = {
153 admins = { alias = "Naemon Administrators"; };
154 };
eb071dd4
IB
155 templates = {
156 service = {
157 generic-service = {
158 active_checks_enabled = "1";
159 check_freshness = "0";
160 check_interval = "10";
161 check_period = "24x7";
162 contact_groups = "admins";
163 event_handler_enabled = "1";
164 flap_detection_enabled = "1";
165 is_volatile = "0";
166 max_check_attempts = "3";
167 notification_interval = "60";
168 notification_options = "w,u,c,r,f,s";
169 notification_period = "24x7";
e820134d 170 notifications_enabled = if master then "1" else "0";
eb071dd4
IB
171 obsess_over_service = "1";
172 passive_checks_enabled = "1";
173 process_perf_data = "1";
174 retain_nonstatus_information = "1";
175 retain_status_information = "1";
176 retry_interval = "2";
c41d0de8 177 _webstatus_namespace = "immae";
eb071dd4
IB
178 };
179 local-service = {
180 use = "generic-service";
181 host_name = hostFQDN;
182 check_interval = "5";
183 max_check_attempts = "4";
184 retry_interval = "1";
e820134d
IB
185 servicegroups = "webstatus-resources";
186 };
187 external-service = {
188 use = "generic-service";
189 check_interval = "5";
190 max_check_attempts = "4";
191 retry_interval = "1";
192 };
193 web-service = {
194 use = "generic-service";
195 check_interval = "20";
196 max_check_attempts = "2";
197 retry_interval = "1";
198 };
199 external-web-service = {
200 use = "generic-service";
201 check_interval = "20";
202 max_check_attempts = "2";
203 retry_interval = "1";
204 };
205 mail-service = {
206 use = "generic-service";
207 check_interval = "15";
208 max_check_attempts = "1";
209 retry_interval = "1";
210 };
211 dns-service = {
212 use = "generic-service";
213 check_interval = "120";
214 notification_interval = "120";
215 max_check_attempts = "5";
216 retry_interval = "5";
eb071dd4
IB
217 };
218 };
219 # No contact, we go through master
e820134d
IB
220 contact = {
221 generic-contact = {
222 host_notification_commands = "notify-host-by-email";
223 host_notification_options = "d,u,r,f,s";
224 host_notification_period = "24x7";
225 service_notification_commands = "notify-service-by-email";
226 service_notification_options = "w,u,c,r,f,s";
227 service_notification_period = "24x7";
228 };
229 };
eb071dd4
IB
230 host = {
231 generic-host = {
232 event_handler_enabled = "1";
233 flap_detection_enabled = "1";
234 notification_period = "24x7";
235 notifications_enabled = "1";
236 process_perf_data = "1";
237 retain_nonstatus_information = "1";
238 retain_status_information = "1";
239 };
240 linux-server = {
241 check_command = "check_host_alive";
242 check_interval = "5";
243 check_period = "24x7";
244 contact_groups = "admins";
245 max_check_attempts = "10";
246 notification_interval = "120";
247 notification_options = "d,u,r,f";
248 retry_interval = "1";
c41d0de8 249 _webstatus_namespace = "immae";
eb071dd4
IB
250 };
251 };
252 };
253}