]>
Commit | Line | Data |
---|---|---|
1 | { config, pkgs, lib, name, ... }: | |
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 | wrapProgram $out/check_redis_replication --prefix PATH : ${lib.makeBinPath [ | |
20 | pkgs.gnugrep pkgs.coreutils pkgs.redis | |
21 | ]} | |
22 | wrapProgram $out/check_mysql_replication --prefix PATH : ${lib.makeBinPath [ | |
23 | pkgs.gnugrep pkgs.gnused pkgs.coreutils pkgs.mariadb | |
24 | ]} | |
25 | wrapProgram $out/check_openldap_replication --prefix PATH : ${lib.makeBinPath [ | |
26 | pkgs.gnugrep pkgs.gnused pkgs.coreutils pkgs.openldap | |
27 | ]} | |
28 | ''; | |
29 | toObjects = pkgs.callPackage ./to_objects.nix {}; | |
30 | commonConfig = { | |
31 | eldiron = { | |
32 | processWarn = "250"; processAlert = "400"; | |
33 | loadWarn = "8.0"; loadAlert = "10.0"; | |
34 | }; | |
35 | backup-2 = { | |
36 | processWarn = "50"; processAlert = "60"; | |
37 | loadWarn = "1.0"; loadAlert = "2.0"; | |
38 | }; | |
39 | }; | |
40 | commonObjects = pkgs.callPackage ./objects_common.nix ({ | |
41 | hostFQDN = config.hostEnv.FQDN; | |
42 | sudo = "/run/wrappers/bin/sudo"; | |
43 | } // builtins.getAttr name commonConfig); | |
44 | hostObjects = | |
45 | let | |
46 | specific_file = ./. + "/objects_" + name + ".nix"; | |
47 | in | |
48 | lib.attrsets.optionalAttrs (builtins.pathExists specific_file) (pkgs.callPackage specific_file { inherit config; }); | |
49 | in | |
50 | { | |
51 | options = { | |
52 | myServices.monitoring = { | |
53 | enable = lib.mkOption { | |
54 | type = lib.types.bool; | |
55 | default = false; | |
56 | description = '' | |
57 | Whether to enable monitoring. | |
58 | ''; | |
59 | }; | |
60 | }; | |
61 | }; | |
62 | ||
63 | config = lib.mkIf config.myServices.monitoring.enable { | |
64 | services.duplyBackup.profiles.monitoring = { | |
65 | rootDir = config.services.naemon.varDir; | |
66 | }; | |
67 | security.sudo.extraRules = [ | |
68 | { | |
69 | commands = [ | |
70 | { command = "${pkgs.mdadm}/bin/mdadm --monitor --scan -1"; options = [ "NOPASSWD" ]; } | |
71 | { command = "${pkgs.postfix}/bin/mailq"; options = [ "NOPASSWD" ]; } | |
72 | ]; | |
73 | users = [ "naemon" ]; | |
74 | runAs = "root"; | |
75 | } | |
76 | { | |
77 | commands = [ | |
78 | { command = "${myplugins}/check_last_file_date /backup2/*"; options = [ "NOPASSWD" ]; } | |
79 | ]; | |
80 | users = [ "naemon" ]; | |
81 | runAs = "ALL"; | |
82 | } | |
83 | { | |
84 | commands = [ | |
85 | { command = "${myplugins}/check_postgres_replication *"; options = [ "NOPASSWD" ]; } | |
86 | ]; | |
87 | users = [ "naemon" ]; | |
88 | runAs = "postgres"; | |
89 | } | |
90 | { | |
91 | commands = [ | |
92 | { command = "${myplugins}/check_mysql_replication *"; options = [ "NOPASSWD" ]; } | |
93 | ]; | |
94 | users = [ "naemon" ]; | |
95 | runAs = "mysql"; | |
96 | } | |
97 | { | |
98 | commands = [ | |
99 | { command = "${myplugins}/check_openldap_replication *"; options = [ "NOPASSWD" ]; } | |
100 | ]; | |
101 | users = [ "naemon" ]; | |
102 | runAs = "openldap"; | |
103 | } | |
104 | { | |
105 | commands = [ | |
106 | { command = "${myplugins}/check_redis_replication *"; options = [ "NOPASSWD" ]; } | |
107 | ]; | |
108 | users = [ "naemon" ]; | |
109 | runAs = "redis"; | |
110 | } | |
111 | ]; | |
112 | environment.etc."mdadm.conf" = { | |
113 | enable = true; | |
114 | mode = "0644"; | |
115 | user = "root"; | |
116 | text = "MAILADDR ${config.myEnv.monitoring.email}"; | |
117 | }; | |
118 | ||
119 | # needed since extraResource is not in the closure | |
120 | systemd.services.naemon.path = [ myplugins ]; | |
121 | services.naemon = { | |
122 | enable = true; | |
123 | extraConfig = '' | |
124 | broker_module=${pkgs.naemon-livestatus}/lib/naemon-livestatus/livestatus.so ${config.services.naemon.runDir}/live | |
125 | use_syslog=1 | |
126 | log_initial_states=1 | |
127 | date_format=iso8601 | |
128 | admin_email=${config.myEnv.monitoring.email} | |
129 | ||
130 | obsess_over_services=1 | |
131 | ocsp_command=notify-master | |
132 | ''; | |
133 | extraResource = '' | |
134 | $USER2$=${myplugins} | |
135 | $USER200$=${config.myEnv.monitoring.status_url} | |
136 | $USER201$=${config.myEnv.monitoring.status_token} | |
137 | ''; | |
138 | objectDefs = toObjects commonObjects + toObjects hostObjects; | |
139 | }; | |
140 | }; | |
141 | } |