]>
Commit | Line | Data |
---|---|---|
9f202523 | 1 | { config, myconfig, pkgs, lib, name, hostFQDN, ... }: |
3bc32d9e IB |
2 | let |
3 | myplugins = pkgs.runCommand "buildplugins" { | |
4 | buildInputs = [ pkgs.makeWrapper pkgs.perl ]; | |
5 | } '' | |
6 | mkdir $out | |
7 | cp ${./plugins}/* $out/ | |
8 | patchShebangs $out | |
9 | wrapProgram $out/check_command --prefix PATH : ${config.security.wrapperDir} | |
10 | wrapProgram $out/send_nrdp.sh --prefix PATH : ${lib.makeBinPath [ | |
b11f0e17 | 11 | pkgs.curl pkgs.jq |
3bc32d9e IB |
12 | ]} |
13 | wrapProgram $out/check_mem.sh --prefix PATH : ${lib.makeBinPath [ | |
14 | pkgs.gnugrep pkgs.gawk pkgs.procps-ng | |
15 | ]} | |
9f202523 IB |
16 | wrapProgram $out/check_postgres_replication --prefix PATH : ${lib.makeBinPath [ |
17 | pkgs.postgresql | |
18 | ]} | |
3bc32d9e | 19 | ''; |
eb071dd4 IB |
20 | toObjects = pkgs.callPackage ./to_objects.nix {}; |
21 | commonConfig = { | |
22 | eldiron = { | |
23 | processWarn = "250"; processAlert = "400"; | |
24 | loadWarn = "8.0"; loadAlert = "10.0"; | |
25 | }; | |
26 | backup-2 = { | |
27 | processWarn = "50"; processAlert = "60"; | |
28 | loadWarn = "1.0"; loadAlert = "2.0"; | |
29 | }; | |
30 | }; | |
31 | commonObjects = pkgs.callPackage ./objects_common.nix ({ | |
32 | inherit hostFQDN; | |
33 | sudo = "/run/wrappers/bin/sudo"; | |
34 | } // builtins.getAttr name commonConfig); | |
35 | hostObjects = | |
36 | let | |
37 | specific_file = ./. + "/objects_" + name + ".nix"; | |
9f202523 | 38 | in |
eb071dd4 | 39 | lib.attrsets.optionalAttrs (builtins.pathExists specific_file) (pkgs.callPackage specific_file {}); |
3bc32d9e IB |
40 | in |
41 | { | |
42 | options = { | |
9f202523 IB |
43 | myServices.monitoring = { |
44 | enable = lib.mkOption { | |
45 | type = lib.types.bool; | |
46 | default = false; | |
47 | description = '' | |
48 | Whether to enable monitoring. | |
49 | ''; | |
50 | }; | |
3bc32d9e IB |
51 | }; |
52 | }; | |
53 | ||
54 | config = lib.mkIf config.myServices.monitoring.enable { | |
d2e703c5 | 55 | services.duplyBackup.profiles.monitoring = { |
6a8252b1 IB |
56 | rootDir = config.services.naemon.varDir; |
57 | }; | |
3bc32d9e IB |
58 | security.sudo.extraRules = [ |
59 | { | |
60 | commands = [ | |
61 | { command = "${pkgs.mdadm}/bin/mdadm --monitor --scan -1"; options = [ "NOPASSWD" ]; } | |
62 | { command = "${pkgs.postfix}/bin/mailq"; options = [ "NOPASSWD" ]; } | |
63 | ]; | |
64 | users = [ "naemon" ]; | |
65 | runAs = "root"; | |
66 | } | |
9f202523 IB |
67 | { |
68 | commands = [ | |
69 | { command = "${myplugins}/check_postgres_replication *"; options = [ "NOPASSWD" ]; } | |
70 | { command = "${myplugins}/check_last_file_date /backup2/*"; options = [ "NOPASSWD" ]; } | |
71 | ]; | |
72 | users = [ "naemon" ]; | |
73 | runAs = "postgres"; | |
74 | } | |
75 | { | |
76 | commands = [ | |
77 | { command = "${myplugins}/check_last_file_date /backup2/*"; options = [ "NOPASSWD" ]; } | |
78 | ]; | |
79 | users = [ "naemon" ]; | |
80 | runAs = "backup"; | |
81 | } | |
3bc32d9e IB |
82 | ]; |
83 | environment.etc."mdadm.conf" = { | |
84 | enable = true; | |
85 | mode = "0644"; | |
86 | user = "root"; | |
5ea246ba | 87 | text = "MAILADDR ${myconfig.env.monitoring.email}"; |
3bc32d9e IB |
88 | }; |
89 | ||
90 | # needed since extraResource is not in the closure | |
91 | systemd.services.naemon.path = [ myplugins ]; | |
92 | services.naemon = { | |
93 | enable = true; | |
94 | extraConfig = '' | |
95 | broker_module=${pkgs.naemon-livestatus}/lib/naemon-livestatus/livestatus.so ${config.services.naemon.runDir}/live | |
96 | use_syslog=1 | |
97 | log_initial_states=1 | |
98 | date_format=iso8601 | |
5ea246ba | 99 | admin_email=${myconfig.env.monitoring.email} |
3bc32d9e IB |
100 | |
101 | obsess_over_services=1 | |
102 | ocsp_command=notify-master | |
103 | ''; | |
104 | extraResource = '' | |
105 | $USER2$=${myplugins} | |
106 | $USER200$=${myconfig.env.monitoring.status_url} | |
107 | $USER201$=${myconfig.env.monitoring.status_token} | |
108 | ''; | |
eb071dd4 | 109 | objectDefs = toObjects commonObjects + toObjects hostObjects; |
3bc32d9e IB |
110 | }; |
111 | }; | |
112 | } |