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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
|
{ sudo, pkgs, lib, config }:
let
cfg = config.myServices.monitoring;
in
{
notify-secondary = {
resources = {
USER200 = config.myEnv.monitoring.status_url;
USER201 = config.myEnv.monitoring.status_token;
};
commands = {
notify-master = "$USER2$/send_nrdp.sh -u \"$USER200$\" -t \"$USER201$\" -H \"$HOSTADDRESS$\" -s \"$SERVICEDESC$\" -S \"$SERVICESTATEID$\" -o \"$SERVICEOUTPUT$ | $SERVICEPERFDATA$\"";
};
chunk = ''
cp ${./plugins}/send_nrdp.sh $out
patchShebangs $out/send_nrdp.sh
wrapProgram $out/send_nrdp.sh --prefix PATH : ${lib.makeBinPath [
pkgs.curl pkgs.jq
]}
'';
};
notify-primary = {
resources = {
USER206 = config.myEnv.monitoring.slack_channel;
USER207 = config.myEnv.monitoring.slack_url;
USER210 = config.myEnv.monitoring.eban.user;
USER211 = config.myEnv.monitoring.eban.password;
};
commands = {
# $OVE is to force naemon to run via shell instead of execve which fails here
notify-host-by-email = "ADMINEMAIL=\"$ADMINEMAIL$\" SERVICENOTIFICATIONID=\"$SERVICENOTIFICATIONID$\" HOSTSTATE=\"$HOSTSTATE$\" HOSTOUTPUT=\"$HOSTOUTPUT$\" $USER2$/notify_by_email host \"$NOTIFICATIONTYPE$\" \"$HOSTALIAS$\" \"$LONGDATETIME$\" \"$CONTACTEMAIL$\" $OVE";
# $OVE is to force naemon to run via shell instead of execve which fails here
notify-service-by-email = "ADMINEMAIL=\"$ADMINEMAIL$\" SERVICENOTIFICATIONID=\"$SERVICENOTIFICATIONID$\" SERVICEDESC=\"$SERVICEDESC$\" SERVICESTATE=\"$SERVICESTATE$\" SERVICEOUTPUT=\"$SERVICEOUTPUT$\" $USER2$/notify_by_email service \"$NOTIFICATIONTYPE$\" \"$HOSTALIAS$\" \"$LONGDATETIME$\" \"$CONTACTEMAIL$\" $OVE";
notify-by-slack = "HOST=\"$HOSTALIAS$\" SERVICESTATE=\"$SERVICESTATE$\" SERVICEDESC=\"$SERVICEDESC$\" SERVICEOUTPUT=\"$SERVICEOUTPUT$\" $USER2$/notify_by_slack \"$ARG1$\" \"$ARG2$\"";
notify-host-eban-url = "STATUS_NAME=\"Server\" USER=\"$USER210$\" PASSWORD=\"$USER211$\" HOSTSTATE=\"$HOSTSTATE$\" $USER2$/notify_eban_url";
notify-service-eban-url = "STATUS_NAME=\"$_SERVICEWEBSTATUS_NAME$\" USER=\"$USER210$\" PASSWORD=\"$USER211$\" SERVICESTATE=\"$SERVICESTATE$\" $USER2$/notify_eban_url";
};
chunk = ''
cp ${./plugins}/{notify_by_email,notify_by_slack,notify_eban_url} $out
patchShebangs $out/{notify_by_email,notify_by_slack,notify_eban_url}
wrapProgram $out/notify_by_email --prefix PATH : ${lib.makeBinPath [
pkgs.mailutils
]}
wrapProgram $out/notify_by_slack --prefix PATH : ${lib.makeBinPath [
pkgs.curl pkgs.jq
]}
wrapProgram $out/notify_eban_url --prefix PATH : ${lib.makeBinPath [
pkgs.curl
]}
'';
};
bandwidth = {
commands = {
check_local_bandwidth = "$USER2$/check_bandwidth -i=$ARG1$ -w $ARG2$ -c $ARG3$";
};
chunk = ''
cp ${./plugins}/check_bandwidth $out/
patchShebangs $out/check_bandwidth
wrapProgram $out/check_bandwidth --prefix PATH : ${lib.makeBinPath [
pkgs.iproute pkgs.bc
]}
'';
};
command = {
commands = {
check_command_match = "$USER2$/check_command -c \"$ARG1$\" -C \"$ARG2$\" $ARG3$";
check_command_output = "$USER2$/check_command -c \"$ARG1$\" -s 0 -o \"$ARG2$\" $ARG3$";
check_command_status = "$USER2$/check_command -c \"$ARG1$\" -s \"$ARG2$\" $ARG3$";
};
chunk = ''
cp ${./plugins}/check_command $out/
patchShebangs $out/check_command
wrapProgram $out/check_command --prefix PATH : ${config.security.wrapperDir}
'';
};
dns = {
commands = {
check_dns = "$USER1$/check_dns -H $ARG1$ -s $HOSTADDRESS$ $ARG2$";
check_external_dns = "$USER1$/check_dns -H $ARG2$ -s $ARG1$ $ARG3$";
};
};
emails = {
resources = {
USER203 = config.secrets.fullPaths."naemon/id_rsa";
};
commands = {
check_emails = "$USER2$/check_emails -H $HOSTADDRESS$ -i $USER203$ -l $ARG1$ -p $ARG2$ -s $ARG3$ -f $ARG4$";
check_emails_local = "$USER2$/check_emails -H $HOSTADDRESS$ -n $ARG1$ -r $ADMINEMAIL$ -s $ARG2$ -f $ARG3$";
};
chunk = let
send_mails = pkgs.runCommand "send_mails" {
buildInputs = [ pkgs.makeWrapper ];
} ''
mkdir -p $out/bin
cp ${./send_mails} $out/bin/send_mails
patchShebangs $out
wrapProgram $out/bin/send_mails --prefix PATH : ${lib.makeBinPath [
pkgs.mailutils
]}
'';
in ''
cp ${./plugins}/check_emails $out/
patchShebangs $out/check_emails
wrapProgram $out/check_emails --prefix PATH : ${lib.makeBinPath [
pkgs.openssh send_mails
]} --prefix PERL5LIB : ${pkgs.perlPackages.makePerlPath [
pkgs.perlPackages.TimeDate
]}
'';
};
eriomem = {
resources = {
USER208 = builtins.concatStringsSep "," (map (builtins.concatStringsSep ":") config.myEnv.monitoring.eriomem_keys);
};
commands = {
check_backup_eriomem = "$USER2$/check_eriomem $USER208$";
check_backup_eriomem_age = "$USER2$/check_backup_eriomem_age $ARG1$";
};
chunk = ''
cp ${./plugins}/check_eriomem $out/
patchShebangs $out/check_eriomem
wrapProgram $out/check_eriomem --prefix PATH : ${lib.makeBinPath [
pkgs.s3cmd pkgs.python3
]}
cp ${./plugins}/check_backup_age $out/check_backup_eriomem_age
patchShebangs $out/check_backup_eriomem_age
wrapProgram $out/check_backup_eriomem_age --prefix PATH : ${lib.makeBinPath [
pkgs.duplicity
]} --set SECRETS_PATH ${lib.optionalString cfg.master config.secrets.fullPaths."eriomem_access_key"}
'';
};
file_date = {
commands = {
check_last_file_date = "${sudo} -u \"$ARG3$\" $USER2$/check_last_file_date \"$ARG1$\" \"$ARG2$\"";
};
chunk = ''
cp ${./plugins}/check_last_file_date $out/
patchShebangs $out/check_last_file_date
'';
sudo = myplugins: {
commands = [
{ command = "${myplugins}/check_last_file_date /backup2/*"; options = [ "NOPASSWD" ]; }
];
runAs = "ALL";
};
};
ftp = {
commands = {
check_ftp_database = "$USER2$/check_ftp_database";
};
chunk = ''
cp ${./plugins}/check_ftp_database $out/
patchShebangs $out/check_ftp_database
wrapProgram $out/check_ftp_database --prefix PATH : ${lib.makeBinPath [
pkgs.lftp
]}
'';
};
git = {
resources = {
USER203 = config.secrets.fullPaths."naemon/id_rsa";
};
commands = {
check_git = "$USER2$/check_git $USER203$";
};
chunk = ''
cp ${./plugins}/check_git $out/
patchShebangs $out/check_git
wrapProgram $out/check_git --prefix PATH : ${lib.makeBinPath [
pkgs.git pkgs.openssh
]}
'';
};
http = {
resources = {
USER202 = config.myEnv.monitoring.http_user_password;
};
commands = {
check_http = "$USER1$/check_http --sni -f stickyport -H \"$ARG1$\" -u \"$ARG2$\" -r \"$ARG3$\"";
check_https = "$USER1$/check_http --sni --ssl -f stickyport -H \"$ARG1$\" -u \"$ARG2$\" -r \"$ARG3$\"";
check_https_auth = "$USER1$/check_http --sni --ssl -a \"$USER202$\" -f stickyport -H \"$ARG1$\" -u \"$ARG2$\" -r \"$ARG3$\"";
check_https_certificate = "$USER1$/check_http --sni --ssl -H \"$ARG1$\" -C 21,15";
check_https_code = "$USER1$/check_http --sni --ssl -f stickyport -H \"$ARG1$\" -u \"$ARG2$\" -e \"$ARG3$\" -r \"$ARG4$\"";
};
};
imap = {
resources = {
USER204 = config.myEnv.monitoring.imap_login;
USER205 = config.myEnv.monitoring.imap_password;
};
commands = {
check_imap_connection = "$USER2$/check_imap_connection -u \"$USER204$\" -p \"$USER205$\" -H \"imap.immae.eu:143\"";
};
chunk = ''
cp ${./plugins}/check_imap_connection $out/
patchShebangs $out/check_imap_connection
wrapProgram $out/check_imap_connection --prefix PATH : ${lib.makeBinPath [
pkgs.openssl
]}
'';
};
megaraid = let
megacli = pkgs.megacli.overrideAttrs(old: { meta = old.meta // { license = null; }; });
in {
commands = {
check_megaraid = "$USER2$/check_megaraid_sas --sudo";
};
chunk = let
megaCliPlugin = pkgs.runCommand "megaCliPlugin" {
plugin = pkgs.fetchurl {
name = "check_megaraid_sas";
url = "https://exchange.nagios.org/components/com_mtree/attachment.php?link_id=6381&cf_id=24";
sha256 = "0yf60p4c0hb4q3fng9fc14qc89bqm0f1sijayzygadaqcl44jx4p";
};
} ''
mkdir $out
cp $plugin $out/check_megaraid_sas
chmod +x $out/check_megaraid_sas
patchShebangs $out
substituteInPlace $out/check_megaraid_sas --replace /usr/sbin/MegaCli ${megacli}/bin/MegaCli64
substituteInPlace $out/check_megaraid_sas --replace 'sudo $megacli' '${sudo} $megacli'
sed -i -e "s/use utils qw(%ERRORS);/my %ERRORS = ('OK' => 0, 'WARNING' => 1, 'CRITICAL' => 2, 'UNKNOWN' => 3);/" $out/check_megaraid_sas
'';
in ''
cp ${megaCliPlugin}/check_megaraid_sas $out/
patchShebangs $out/check_megaraid_sas
'';
sudo = _: {
commands = [
{ command = "${megacli}/bin/MegaCli64"; options = [ "NOPASSWD" ]; }
];
runAs = "root";
};
};
memory = {
commands = {
check_memory = "$USER2$/check_mem.sh -w $ARG1$ -c $ARG2$";
};
chunk = ''
cp ${./plugins}/check_mem.sh $out/
patchShebangs $out/check_mem.sh
wrapProgram $out/check_mem.sh --prefix PATH : ${lib.makeBinPath [
pkgs.gnugrep pkgs.gawk pkgs.procps-ng
]}
'';
};
mysql = {
commands = {
check_mysql_replication = "${sudo} -u mysql $USER2$/check_mysql_replication \"$ARG1$\" \"$ARG2$\"";
};
chunk = ''
cp ${./plugins}/check_mysql_replication $out/
patchShebangs $out/check_mysql_replication
wrapProgram $out/check_mysql_replication --prefix PATH : ${lib.makeBinPath [
pkgs.gnugrep pkgs.gnused pkgs.coreutils pkgs.mariadb
]}
'';
sudo = myplugins: {
commands = [
{ command = "${myplugins}/check_mysql_replication *"; options = [ "NOPASSWD" ]; }
];
runAs = "mysql";
};
};
openldap = {
commands = {
check_openldap_replication = "${sudo} -u openldap $USER2$/check_openldap_replication \"$ARG1$\" \"$ARG2$\" \"$ARG3$\" \"$ARG4$\" \"$ARG5$\"";
};
chunk = ''
cp ${./plugins}/check_openldap_replication $out/
patchShebangs $out/check_openldap_replication
wrapProgram $out/check_openldap_replication --prefix PATH : ${lib.makeBinPath [
pkgs.gnugrep pkgs.gnused pkgs.coreutils pkgs.openldap
]}
'';
sudo = myplugins: {
commands = [
{ command = "${myplugins}/check_openldap_replication *"; options = [ "NOPASSWD" ]; }
];
runAs = "openldap";
};
};
ovh = {
resources = {
USER209 = builtins.concatStringsSep "," [
config.myEnv.monitoring.ovh_sms.endpoint
config.myEnv.monitoring.ovh_sms.application_key
config.myEnv.monitoring.ovh_sms.application_secret
config.myEnv.monitoring.ovh_sms.consumer_key
config.myEnv.monitoring.ovh_sms.account
];
};
commands = {
check_backup_ovh_age = "$USER2$/check_backup_ovh_age $ARG1$";
check_ovh_sms = "$USER2$/check_ovh_sms \"$USER209$\"";
};
chunk = ''
cp ${./plugins}/check_backup_age $out/check_backup_ovh_age
patchShebangs $out/check_backup_ovh_age
wrapProgram $out/check_backup_ovh_age --prefix PATH : ${lib.makeBinPath [
pkgs.duplicity
]} --set SECRETS_PATH ${lib.optionalString cfg.master config.secrets.fullPaths."ovh_access_key"}
cp ${./plugins}/check_ovh_sms $out/
patchShebangs $out/check_ovh_sms
wrapProgram $out/check_ovh_sms --prefix PATH : ${lib.makeBinPath [
(pkgs.python3.withPackages (ps: [ps.ovh]))
]}
'';
};
postgresql = {
commands = {
check_postgresql_replication = "${sudo} -u postgres $USER2$/check_postgres_replication \"$ARG1$\" \"$ARG2$\" \"$ARG3$\"";
check_postgresql_database_count = "$USER2$/check_postgres_database_count \"$ARG1$\" \"$ARG2$\" \"$ARG3$\"";
};
chunk = let
postgresqlBinary = if config.myServices.databasesReplication.postgresql.enable
then config.myServices.databasesReplication.postgresql.mainPackage
else if config.myServices.databases.enable
then config.myServices.databases.postgresql.package
else pkgs.postgresql;
in ''
cp ${./plugins}/check_postgres_replication $out/
patchShebangs $out/check_postgres_replication
wrapProgram $out/check_postgres_replication --prefix PATH : ${lib.makeBinPath [
postgresqlBinary
]}
cp ${./plugins}/check_postgres_database_count $out/
patchShebangs $out/check_postgres_database_count
wrapProgram $out/check_postgres_database_count --prefix PATH : ${lib.makeBinPath [
postgresqlBinary
]}
'';
sudo = myplugins: {
commands = [
{ command = "${myplugins}/check_postgres_replication *"; options = [ "NOPASSWD" ]; }
];
runAs = "postgres";
};
};
redis = {
commands = {
check_redis_replication = "${sudo} -u redis $USER2$/check_redis_replication \"$ARG1$\"";
};
chunk = ''
cp ${./plugins}/check_redis_replication $out/
patchShebangs $out/check_redis_replication
wrapProgram $out/check_redis_replication --prefix PATH : ${lib.makeBinPath [
pkgs.gnugrep pkgs.coreutils pkgs.redis
]}
'';
sudo = myplugins: {
commands = [
{ command = "${myplugins}/check_redis_replication *"; options = [ "NOPASSWD" ]; }
];
runAs = "redis";
};
};
tcp = {
commands = {
check_tcp = "$USER1$/check_tcp -H $HOSTADDRESS$ -p $ARG1$ -e \"$ARG2$\" -Mcrit";
check_tcp_ssl = "$USER1$/check_tcp -H $HOSTADDRESS$ -p $ARG1$ -S -D 21,15";
};
};
zfs = {
commands = {
check_zfs = "$USER2$/check_zpool.sh -p ALL -w 80 -c 90";
check_zfs_snapshot = "$USER2$/check_zfs_snapshot -d $ARG1$ -c 18000 -w 14400";
};
chunk = let
zfsPlugin = pkgs.fetchurl {
url = "https://www.claudiokuenzler.com/monitoring-plugins/check_zpools.sh";
sha256 = "0p9ms9340in80jkds4kfspw62xnzsv5s7ni9m28kxyd0bnzkbzhf";
};
in ''
cp ${zfsPlugin} $out/check_zpool.sh
chmod +x $out/check_zpool.sh
patchShebangs $out/check_zpool.sh
wrapProgram $out/check_zpool.sh --prefix PATH : ${lib.makeBinPath [
pkgs.which pkgs.zfs pkgs.gawk
]}
cp ${./plugins}/check_zfs_snapshot $out
patchShebangs $out/check_zfs_snapshot
wrapProgram $out/check_zfs_snapshot --prefix PATH : ${lib.makeBinPath [
pkgs.zfs pkgs.coreutils pkgs.gawk pkgs.gnugrep
]}
'';
};
}
|