]>
Commit | Line | Data |
---|---|---|
1 | { config, myconfig, pkgs, lib, name, hostFQDN, ... }: | |
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 [ | |
11 | pkgs.curl pkgs.jq | |
12 | ]} | |
13 | wrapProgram $out/check_mem.sh --prefix PATH : ${lib.makeBinPath [ | |
14 | pkgs.gnugrep pkgs.gawk pkgs.procps-ng | |
15 | ]} | |
16 | wrapProgram $out/check_postgres_replication --prefix PATH : ${lib.makeBinPath [ | |
17 | pkgs.postgresql | |
18 | ]} | |
19 | ''; | |
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"; | |
38 | in | |
39 | lib.attrsets.optionalAttrs (builtins.pathExists specific_file) (pkgs.callPackage specific_file {}); | |
40 | in | |
41 | { | |
42 | options = { | |
43 | myServices.monitoring = { | |
44 | enable = lib.mkOption { | |
45 | type = lib.types.bool; | |
46 | default = false; | |
47 | description = '' | |
48 | Whether to enable monitoring. | |
49 | ''; | |
50 | }; | |
51 | }; | |
52 | }; | |
53 | ||
54 | config = lib.mkIf config.myServices.monitoring.enable { | |
55 | services.duplyBackup.profiles.monitoring = { | |
56 | rootDir = config.services.naemon.varDir; | |
57 | }; | |
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 | } | |
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 | } | |
82 | ]; | |
83 | environment.etc."mdadm.conf" = { | |
84 | enable = true; | |
85 | mode = "0644"; | |
86 | user = "root"; | |
87 | text = "MAILADDR ${myconfig.env.monitoring.email}"; | |
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 | |
99 | admin_email=${myconfig.env.monitoring.email} | |
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 | ''; | |
109 | objectDefs = toObjects commonObjects + toObjects hostObjects; | |
110 | }; | |
111 | }; | |
112 | } |