1 { sudo, pkgs, lib, config }:
3 cfg = config.myServices.monitoring;
8 USER200 = config.myEnv.monitoring.status_url;
9 USER201 = config.myEnv.monitoring.status_token;
12 notify-master = "$USER2$/send_nrdp.sh -u \"$USER200$\" -t \"$USER201$\" -H \"$HOSTADDRESS$\" -s \"$SERVICEDESC$\" -S \"$SERVICESTATEID$\" -o \"$SERVICEOUTPUT$ | $SERVICEPERFDATA$\"";
15 cp ${./plugins}/send_nrdp.sh $out
16 patchShebangs $out/send_nrdp.sh
17 wrapProgram $out/send_nrdp.sh --prefix PATH : ${lib.makeBinPath [
24 USER210 = config.myEnv.monitoring.apprise_urls;
27 # $OVE is to force naemon to run via shell instead of execve which fails here
28 notify-host-by-email = "ADMINEMAIL=\"$ADMINEMAIL$\" SERVICENOTIFICATIONID=\"$SERVICENOTIFICATIONID$\" HOSTSTATE=\"$HOSTSTATE$\" HOSTOUTPUT=\"$HOSTOUTPUT$\" $USER2$/notify_by_email host \"$NOTIFICATIONTYPE$\" \"$HOSTALIAS$\" \"$LONGDATETIME$\" \"$CONTACTEMAIL$\" $OVE";
29 # $OVE is to force naemon to run via shell instead of execve which fails here
30 notify-service-by-email = "ADMINEMAIL=\"$ADMINEMAIL$\" SERVICENOTIFICATIONID=\"$SERVICENOTIFICATIONID$\" SERVICEDESC=\"$SERVICEDESC$\" SERVICESTATE=\"$SERVICESTATE$\" SERVICEOUTPUT=\"$SERVICEOUTPUT$\" $USER2$/notify_by_email service \"$NOTIFICATIONTYPE$\" \"$HOSTALIAS$\" \"$LONGDATETIME$\" \"$CONTACTEMAIL$\" $OVE";
31 notify-host-by-apprise = "HOST=\"$HOSTALIAS$\" NOTIFICATIONTYPE=\"$NOTIFICATIONTYPE$\" HOSTSTATE=\"$HOSTSTATE$\" HOSTOUTPUT=\"$HOSTOUTPUT$\" $USER2$/notify_by_apprise host \"$ARG1$\"";
32 notify-service-by-apprise = "HOST=\"$HOSTALIAS$\" NOTIFICATIONTYPE=\"$NOTIFICATIONTYPE$\" SERVICESTATE=\"$SERVICESTATE$\" SERVICEDESC=\"$SERVICEDESC$\" SERVICEOUTPUT=\"$SERVICEOUTPUT$\" $USER2$/notify_by_apprise service \"$ARG1$\"";
35 cp ${./plugins}/{notify_by_email,notify_by_apprise} $out
36 patchShebangs $out/{notify_by_email,notify_by_apprise}
37 wrapProgram $out/notify_by_email --prefix PATH : ${lib.makeBinPath [
40 wrapProgram $out/notify_by_apprise --prefix PATH : ${lib.makeBinPath [
47 check_local_bandwidth = "$USER2$/check_bandwidth -i=$ARG1$ -w $ARG2$ -c $ARG3$";
50 cp ${./plugins}/check_bandwidth $out/
51 patchShebangs $out/check_bandwidth
52 wrapProgram $out/check_bandwidth --prefix PATH : ${lib.makeBinPath [
59 check_command_match = "$USER2$/check_command -c \"$ARG1$\" -C \"$ARG2$\" $ARG3$";
60 check_command_output = "$USER2$/check_command -c \"$ARG1$\" -s 0 -o \"$ARG2$\" $ARG3$";
61 check_command_status = "$USER2$/check_command -c \"$ARG1$\" -s \"$ARG2$\" $ARG3$";
64 cp ${./plugins}/check_command $out/
65 patchShebangs $out/check_command
66 wrapProgram $out/check_command --prefix PATH : ${config.security.wrapperDir}
71 check_dns = "$USER1$/check_dns -H $ARG1$ -s $HOSTADDRESS$ $ARG2$";
72 check_dns_soa = "$USER2$/check_dns_soa -H $ARG1$ -z $ARG2$ -M $ARG3$";
73 check_dnssec = "$USER2$/check_dnssec -z $ARG1$";
74 check_external_dns = "$USER1$/check_dns -H $ARG2$ -s $ARG1$ $ARG3$";
77 soa_plugin = pkgs.fetchurl {
78 name = "check_dns_soa";
79 url = "https://exchange.nagios.org/components/com_mtree/attachment.php?link_id=1429&cf_id=24";
80 sha256 = "sha256-Yy4XO19Fb7WdHZZmhUfyyAGBnxJyFWwc7U3HiWyE8wc=";
83 cp ${./plugins}/check_dnssec $out/
84 patchShebangs $out/check_dnssec
85 wrapProgram $out/check_dnssec --prefix PATH : ${lib.makeBinPath [
86 pkgs.bind.dnsutils pkgs.gnugrep pkgs.gawk pkgs.which pkgs.coreutils
89 cp ${soa_plugin} $out/check_dns_soa
90 chmod +xw $out/check_dns_soa
91 patchShebangs $out/check_dns_soa
92 sed -i -e 's/^use utils qw.*$/my %ERRORS = ("OK" => 0, "WARNING" => 1, "CRITICAL" => 2, "UNKNOWN" => 3);my $TIMEOUT = 10;/' -e '/^use lib /d' $out/check_dns_soa
93 wrapProgram $out/check_dns_soa --prefix PERL5LIB : ${pkgs.perlPackages.makePerlPath [
94 pkgs.perlPackages.NetDNS
100 check_mdadm = "$USER2$/check_command -c \"${pkgs.mdadm}/bin/mdadm --monitor --scan -1\" -s 0 -o \"^$\" -r root";
104 { command = "${pkgs.mdadm}/bin/mdadm --monitor --scan -1"; options = [ "NOPASSWD" ]; }
111 check_mailq = "$USER1$/check_mailq -s -w 1 -c 2";
115 { command = "${pkgs.postfix}/bin/mailq"; options = [ "NOPASSWD" ]; }
122 USER203 = config.secrets.fullPaths."naemon/id_rsa";
125 check_emails = "$USER2$/check_emails -H $HOSTADDRESS$ -i $USER203$ -l $ARG1$ -p $ARG2$ -s $ARG3$ -f $ARG4$";
126 check_emails_local = "$USER2$/check_emails -H $HOSTADDRESS$ -n $ARG1$ -r $ADMINEMAIL$ -s $ARG2$ -f $ARG3$";
129 send_mails = pkgs.runCommand "send_mails" {
130 buildInputs = [ pkgs.makeWrapper ];
133 cp ${./send_mails} $out/bin/send_mails
135 wrapProgram $out/bin/send_mails --prefix PATH : ${lib.makeBinPath [
140 cp ${./plugins}/check_emails $out/
141 patchShebangs $out/check_emails
142 wrapProgram $out/check_emails --prefix PATH : ${lib.makeBinPath [
143 pkgs.openssh send_mails
144 ]} --prefix PERL5LIB : ${pkgs.perlPackages.makePerlPath [
145 pkgs.perlPackages.TimeDate
151 USER208 = builtins.concatStringsSep "," (map (builtins.concatStringsSep ":") config.myEnv.monitoring.eriomem_keys);
154 check_backup_eriomem = "$USER2$/check_eriomem $USER208$";
155 check_backup_eriomem_age = "$USER2$/check_backup_eriomem_age $ARG1$";
158 cp ${./plugins}/check_eriomem $out/
159 patchShebangs $out/check_eriomem
160 wrapProgram $out/check_eriomem --prefix PATH : ${lib.makeBinPath [
161 pkgs.s3cmd pkgs.python38
163 cp ${./plugins}/check_backup_age $out/check_backup_eriomem_age
164 patchShebangs $out/check_backup_eriomem_age
165 wrapProgram $out/check_backup_eriomem_age --prefix PATH : ${lib.makeBinPath [
167 ]} --set SECRETS_PATH ${lib.optionalString cfg.master config.secrets.fullPaths."eriomem_access_key"}
172 check_last_file_date = "${sudo} -u \"$ARG3$\" $USER2$/check_last_file_date \"$ARG1$\" \"$ARG2$\"";
175 cp ${./plugins}/check_last_file_date $out/
176 patchShebangs $out/check_last_file_date
180 { command = "${myplugins}/check_last_file_date /backup2/*"; options = [ "NOPASSWD" ]; }
187 check_ftp_database = "$USER2$/check_ftp_database";
190 cp ${./plugins}/check_ftp_database $out/
191 patchShebangs $out/check_ftp_database
192 wrapProgram $out/check_ftp_database --prefix PATH : ${lib.makeBinPath [
199 USER203 = config.secrets.fullPaths."naemon/id_rsa";
202 check_git = "$USER2$/check_git $USER203$";
205 cp ${./plugins}/check_git $out/
206 patchShebangs $out/check_git
207 wrapProgram $out/check_git --prefix PATH : ${lib.makeBinPath [
208 pkgs.git pkgs.openssh
214 USER202 = config.myEnv.monitoring.http_user_password;
217 check_http = "$USER1$/check_http --sni -f stickyport -H \"$ARG1$\" -u \"$ARG2$\" -r \"$ARG3$\"";
218 check_https = "$USER1$/check_http --sni --ssl -f stickyport -H \"$ARG1$\" -u \"$ARG2$\" -r \"$ARG3$\"";
219 check_https_4 = "$USER1$/check_http -4 --sni --ssl -f stickyport -H \"$ARG1$\" -u \"$ARG2$\" -r \"$ARG3$\"";
220 check_https_6 = "$USER1$/check_http -6 --sni --ssl -f stickyport -H \"$ARG1$\" -u \"$ARG2$\" -r \"$ARG3$\"";
221 check_https_auth = "$USER1$/check_http --sni --ssl -a \"$USER202$\" -f stickyport -H \"$ARG1$\" -u \"$ARG2$\" -r \"$ARG3$\"";
222 check_https_certificate = "$USER1$/check_http --sni --ssl -H \"$ARG1$\" -C 21,15";
223 check_https_code = "$USER1$/check_http --sni --ssl -f stickyport -H \"$ARG1$\" -u \"$ARG2$\" -e \"$ARG3$\" -r \"$ARG4$\"";
228 USER204 = config.myEnv.monitoring.imap_login;
229 USER205 = config.myEnv.monitoring.imap_password;
232 check_imap_connection = "$USER2$/check_imap_connection -u \"$USER204$\" -p \"$USER205$\" -H \"imap.immae.eu:143\"";
235 cp ${./plugins}/check_imap_connection $out/
236 patchShebangs $out/check_imap_connection
237 wrapProgram $out/check_imap_connection --prefix PATH : ${lib.makeBinPath [
243 megacli = pkgs.megacli.overrideAttrs(old: { meta = old.meta // { license = null; }; });
246 check_megaraid = "$USER2$/check_megaraid_sas --sudo";
249 megaCliPlugin = pkgs.runCommand "megaCliPlugin" {
250 plugin = pkgs.fetchurl {
251 name = "check_megaraid_sas";
252 url = "https://exchange.nagios.org/components/com_mtree/attachment.php?link_id=6381&cf_id=24";
253 sha256 = "0yf60p4c0hb4q3fng9fc14qc89bqm0f1sijayzygadaqcl44jx4p";
257 cp $plugin $out/check_megaraid_sas
258 chmod +x $out/check_megaraid_sas
260 substituteInPlace $out/check_megaraid_sas --replace /usr/sbin/MegaCli ${megacli}/bin/MegaCli64
261 substituteInPlace $out/check_megaraid_sas --replace 'sudo $megacli' '${sudo} $megacli'
262 sed -i -e "s/use utils qw(%ERRORS);/my %ERRORS = ('OK' => 0, 'WARNING' => 1, 'CRITICAL' => 2, 'UNKNOWN' => 3);/" $out/check_megaraid_sas
265 cp ${megaCliPlugin}/check_megaraid_sas $out/
266 patchShebangs $out/check_megaraid_sas
270 { command = "${megacli}/bin/MegaCli64"; options = [ "NOPASSWD" ]; }
277 check_memory = "$USER2$/check_mem.sh -w $ARG1$ -c $ARG2$";
280 cp ${./plugins}/check_mem.sh $out/
281 patchShebangs $out/check_mem.sh
282 wrapProgram $out/check_mem.sh --prefix PATH : ${lib.makeBinPath [
283 pkgs.gnugrep pkgs.gawk pkgs.procps
289 check_mysql_replication = "${sudo} -u mysql $USER2$/check_mysql_replication \"$ARG1$\" \"$ARG2$\"";
292 cp ${./plugins}/check_mysql_replication $out/
293 patchShebangs $out/check_mysql_replication
294 wrapProgram $out/check_mysql_replication --prefix PATH : ${lib.makeBinPath [
295 pkgs.gnugrep pkgs.gnused pkgs.coreutils pkgs.mariadb
300 { command = "${myplugins}/check_mysql_replication *"; options = [ "NOPASSWD" ]; }
307 check_openldap_replication = "${sudo} -u openldap $USER2$/check_openldap_replication \"$ARG1$\" \"$ARG2$\" \"$ARG3$\" \"$ARG4$\" \"$ARG5$\"";
310 cp ${./plugins}/check_openldap_replication $out/
311 patchShebangs $out/check_openldap_replication
312 wrapProgram $out/check_openldap_replication --prefix PATH : ${lib.makeBinPath [
313 pkgs.gnugrep pkgs.gnused pkgs.coreutils pkgs.openldap
318 { command = "${myplugins}/check_openldap_replication *"; options = [ "NOPASSWD" ]; }
325 USER209 = builtins.concatStringsSep "," [
326 config.myEnv.monitoring.ovh_sms.endpoint
327 config.myEnv.monitoring.ovh_sms.application_key
328 config.myEnv.monitoring.ovh_sms.application_secret
329 config.myEnv.monitoring.ovh_sms.consumer_key
330 config.myEnv.monitoring.ovh_sms.account
334 check_backup_ovh_age = "$USER2$/check_backup_ovh_age $ARG1$";
335 check_ovh_sms = "$USER2$/check_ovh_sms \"$USER209$\"";
338 cp ${./plugins}/check_backup_age $out/check_backup_ovh_age
339 patchShebangs $out/check_backup_ovh_age
340 wrapProgram $out/check_backup_ovh_age --prefix PATH : ${lib.makeBinPath [
342 ]} --set SECRETS_PATH ${lib.optionalString cfg.master config.secrets.fullPaths."ovh_access_key"}
343 cp ${./plugins}/check_ovh_sms $out/
344 patchShebangs $out/check_ovh_sms
345 wrapProgram $out/check_ovh_sms --prefix PATH : ${lib.makeBinPath [
346 (pkgs.python38.withPackages (ps: [ps.ovh]))
350 postgresql = { package }: {
352 check_postgresql_replication = "${sudo} -u postgres $USER2$/check_postgres_replication \"$ARG1$\" \"$ARG2$\" \"$ARG3$\"";
353 check_postgresql_database_count = "$USER2$/check_postgres_database_count \"$ARG1$\" \"$ARG2$\" \"$ARG3$\"";
356 cp ${./plugins}/check_postgres_replication $out/
357 patchShebangs $out/check_postgres_replication
358 wrapProgram $out/check_postgres_replication --prefix PATH : ${lib.makeBinPath [
361 cp ${./plugins}/check_postgres_database_count $out/
362 patchShebangs $out/check_postgres_database_count
363 wrapProgram $out/check_postgres_database_count --prefix PATH : ${lib.makeBinPath [
370 { command = "${myplugins}/check_postgres_replication *"; options = [ "NOPASSWD" ]; }
377 check_redis_replication = "${sudo} -u redis $USER2$/check_redis_replication \"$ARG1$\"";
380 cp ${./plugins}/check_redis_replication $out/
381 patchShebangs $out/check_redis_replication
382 wrapProgram $out/check_redis_replication --prefix PATH : ${lib.makeBinPath [
383 pkgs.gnugrep pkgs.coreutils pkgs.redis
388 { command = "${myplugins}/check_redis_replication *"; options = [ "NOPASSWD" ]; }
395 check_tcp = "$USER1$/check_tcp -H $HOSTADDRESS$ -p $ARG1$ -e \"$ARG2$\" -Mcrit";
396 check_tcp_ssl = "$USER1$/check_tcp -H $HOSTADDRESS$ -p $ARG1$ -S -D 21,15";
401 check_zfs = "$USER2$/check_zpool.sh -p ALL -w 80 -c 90";
402 check_zfs_snapshot = "$USER2$/check_zfs_snapshot -d $ARG1$ -c 18000 -w 14400";
405 zfsPlugin = pkgs.fetchurl {
406 url = "https://www.claudiokuenzler.com/monitoring-plugins/check_zpools.sh";
407 sha256 = "0p9ms9340in80jkds4kfspw62xnzsv5s7ni9m28kxyd0bnzkbzhf";
410 cp ${zfsPlugin} $out/check_zpool.sh
411 chmod +x $out/check_zpool.sh
412 patchShebangs $out/check_zpool.sh
413 wrapProgram $out/check_zpool.sh --prefix PATH : ${lib.makeBinPath [
414 pkgs.which pkgs.zfs pkgs.gawk
416 cp ${./plugins}/check_zfs_snapshot $out
417 patchShebangs $out/check_zfs_snapshot
418 wrapProgram $out/check_zfs_snapshot --prefix PATH : ${lib.makeBinPath [
419 pkgs.zfs pkgs.coreutils pkgs.gawk pkgs.gnugrep