diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2020-01-05 17:08:32 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2020-01-05 17:08:32 +0100 |
commit | e820134d38c3b7470ea5112f40a6dc967f039878 (patch) | |
tree | f05a5cefe285d060aa0ebf52829bcfcd35549f8b /modules/private/monitoring/default.nix | |
parent | b22ce4895ef1e9723a02061f7293e528cfbf9754 (diff) | |
download | Nix-e820134d38c3b7470ea5112f40a6dc967f039878.tar.gz Nix-e820134d38c3b7470ea5112f40a6dc967f039878.tar.zst Nix-e820134d38c3b7470ea5112f40a6dc967f039878.zip |
Add monitoring host
Diffstat (limited to 'modules/private/monitoring/default.nix')
-rw-r--r-- | modules/private/monitoring/default.nix | 99 |
1 files changed, 94 insertions, 5 deletions
diff --git a/modules/private/monitoring/default.nix b/modules/private/monitoring/default.nix index d6c91ac..a1f4b3f 100644 --- a/modules/private/monitoring/default.nix +++ b/modules/private/monitoring/default.nix | |||
@@ -1,5 +1,6 @@ | |||
1 | { config, pkgs, lib, name, ... }: | 1 | { config, pkgs, lib, name, nodes, ... }: |
2 | let | 2 | let |
3 | cfg = config.myServices.monitoring; | ||
3 | myplugins = pkgs.runCommand "buildplugins" { | 4 | myplugins = pkgs.runCommand "buildplugins" { |
4 | buildInputs = [ pkgs.makeWrapper pkgs.perl ]; | 5 | buildInputs = [ pkgs.makeWrapper pkgs.perl ]; |
5 | } '' | 6 | } '' |
@@ -10,6 +11,9 @@ let | |||
10 | wrapProgram $out/send_nrdp.sh --prefix PATH : ${lib.makeBinPath [ | 11 | wrapProgram $out/send_nrdp.sh --prefix PATH : ${lib.makeBinPath [ |
11 | pkgs.curl pkgs.jq | 12 | pkgs.curl pkgs.jq |
12 | ]} | 13 | ]} |
14 | wrapProgram $out/check_maison_bbc --prefix PATH : ${lib.makeBinPath [ | ||
15 | pkgs.curl pkgs.jq | ||
16 | ]} | ||
13 | wrapProgram $out/check_mem.sh --prefix PATH : ${lib.makeBinPath [ | 17 | wrapProgram $out/check_mem.sh --prefix PATH : ${lib.makeBinPath [ |
14 | pkgs.gnugrep pkgs.gawk pkgs.procps-ng | 18 | pkgs.gnugrep pkgs.gawk pkgs.procps-ng |
15 | ]} | 19 | ]} |
@@ -25,6 +29,24 @@ let | |||
25 | wrapProgram $out/check_openldap_replication --prefix PATH : ${lib.makeBinPath [ | 29 | wrapProgram $out/check_openldap_replication --prefix PATH : ${lib.makeBinPath [ |
26 | pkgs.gnugrep pkgs.gnused pkgs.coreutils pkgs.openldap | 30 | pkgs.gnugrep pkgs.gnused pkgs.coreutils pkgs.openldap |
27 | ]} | 31 | ]} |
32 | wrapProgram $out/check_ftp_database --prefix PATH : ${lib.makeBinPath [ | ||
33 | pkgs.lftp | ||
34 | ]} | ||
35 | wrapProgram $out/check_git --prefix PATH : ${lib.makeBinPath [ | ||
36 | pkgs.git pkgs.openssh | ||
37 | ]} | ||
38 | wrapProgram $out/check_imap_connection --prefix PATH : ${lib.makeBinPath [ | ||
39 | pkgs.openssl | ||
40 | ]} | ||
41 | wrapProgram $out/notify_maison_bbc_by_email --prefix PATH : ${lib.makeBinPath [ | ||
42 | pkgs.mailutils pkgs.gawk | ||
43 | ]} | ||
44 | wrapProgram $out/notify_by_email --prefix PATH : ${lib.makeBinPath [ | ||
45 | pkgs.mailutils | ||
46 | ]} | ||
47 | wrapProgram $out/notify_by_slack --prefix PATH : ${lib.makeBinPath [ | ||
48 | pkgs.curl pkgs.jq | ||
49 | ]} | ||
28 | ''; | 50 | ''; |
29 | toObjects = pkgs.callPackage ./to_objects.nix {}; | 51 | toObjects = pkgs.callPackage ./to_objects.nix {}; |
30 | commonConfig = { | 52 | commonConfig = { |
@@ -36,16 +58,48 @@ let | |||
36 | processWarn = "50"; processAlert = "60"; | 58 | processWarn = "50"; processAlert = "60"; |
37 | loadWarn = "1.0"; loadAlert = "2.0"; | 59 | loadWarn = "1.0"; loadAlert = "2.0"; |
38 | }; | 60 | }; |
61 | monitoring-1 = { | ||
62 | processWarn = "50"; processAlert = "60"; | ||
63 | loadWarn = "1.0"; loadAlert = "2.0"; | ||
64 | }; | ||
39 | }; | 65 | }; |
66 | masterPassiveObjects = let | ||
67 | otherPassiveObjects = map | ||
68 | (n: (pkgs.callPackage (./. + "/objects_" + n + ".nix") {})) | ||
69 | [ "caldance-1" "ulminfo-fr" "immae-eu" "phare" "tiboqorl-fr" ]; | ||
70 | otherPassiveServices = lib.flatten (map (h: h.service or []) otherPassiveObjects); | ||
71 | otherPassiveHosts = (map (h: h.host)) otherPassiveObjects; | ||
72 | passiveNodes = lib.attrsets.filterAttrs (n: _: builtins.elem n ["backup-2" "eldiron"]) nodes; | ||
73 | toPassiveServices = map (s: s.passiveInfo.filter s // s.passiveInfo); | ||
74 | passiveServices = lib.flatten (lib.attrsets.mapAttrsToList | ||
75 | (_: n: toPassiveServices n.config.myServices.monitoring.services) | ||
76 | passiveNodes | ||
77 | ); | ||
78 | in { | ||
79 | service = passiveServices ++ otherPassiveServices; | ||
80 | host = lib.lists.foldr | ||
81 | (a: b: a//b) | ||
82 | {} | ||
83 | (otherPassiveHosts ++ lib.attrsets.mapAttrsToList (_: h: h.config.myServices.monitoring.hosts) passiveNodes); | ||
84 | }; | ||
85 | masterObjects = pkgs.callPackage ./objects_master.nix { inherit config; }; | ||
40 | commonObjects = pkgs.callPackage ./objects_common.nix ({ | 86 | commonObjects = pkgs.callPackage ./objects_common.nix ({ |
87 | master = cfg.master; | ||
41 | hostFQDN = config.hostEnv.FQDN; | 88 | hostFQDN = config.hostEnv.FQDN; |
89 | hostName = name; | ||
42 | sudo = "/run/wrappers/bin/sudo"; | 90 | sudo = "/run/wrappers/bin/sudo"; |
43 | } // builtins.getAttr name commonConfig); | 91 | } // builtins.getAttr name commonConfig); |
44 | hostObjects = | 92 | hostObjects = |
45 | let | 93 | let |
46 | specific_file = ./. + "/objects_" + name + ".nix"; | 94 | specific_file = ./. + "/objects_" + name + ".nix"; |
47 | in | 95 | in |
48 | lib.attrsets.optionalAttrs (builtins.pathExists specific_file) (pkgs.callPackage specific_file { inherit config; }); | 96 | lib.attrsets.optionalAttrs |
97 | (builtins.pathExists specific_file) | ||
98 | (pkgs.callPackage specific_file { | ||
99 | inherit config; | ||
100 | hostFQDN = config.hostEnv.FQDN; | ||
101 | hostName = name; | ||
102 | }); | ||
49 | in | 103 | in |
50 | { | 104 | { |
51 | options = { | 105 | options = { |
@@ -57,10 +111,27 @@ in | |||
57 | Whether to enable monitoring. | 111 | Whether to enable monitoring. |
58 | ''; | 112 | ''; |
59 | }; | 113 | }; |
114 | master = lib.mkOption { | ||
115 | type = lib.types.bool; | ||
116 | default = false; | ||
117 | description = '' | ||
118 | This instance is the master instance | ||
119 | ''; | ||
120 | }; | ||
121 | hosts = lib.mkOption { | ||
122 | readOnly = true; | ||
123 | description = "Hosts list for this host"; | ||
124 | default = (commonObjects.host or {}) // (hostObjects.host or {}); | ||
125 | }; | ||
126 | services = lib.mkOption { | ||
127 | readOnly = true; | ||
128 | description = "Services list for this host"; | ||
129 | default = commonObjects.service ++ hostObjects.service; | ||
130 | }; | ||
60 | }; | 131 | }; |
61 | }; | 132 | }; |
62 | 133 | ||
63 | config = lib.mkIf config.myServices.monitoring.enable { | 134 | config = lib.mkIf cfg.enable { |
64 | services.duplyBackup.profiles.monitoring = { | 135 | services.duplyBackup.profiles.monitoring = { |
65 | rootDir = config.services.naemon.varDir; | 136 | rootDir = config.services.naemon.varDir; |
66 | }; | 137 | }; |
@@ -116,6 +187,15 @@ in | |||
116 | text = "MAILADDR ${config.myEnv.monitoring.email}"; | 187 | text = "MAILADDR ${config.myEnv.monitoring.email}"; |
117 | }; | 188 | }; |
118 | 189 | ||
190 | secrets.keys = [ | ||
191 | { | ||
192 | dest = "naemon/id_rsa"; | ||
193 | user = "naemon"; | ||
194 | group = "naemon"; | ||
195 | premissions = "0400"; | ||
196 | text = config.myEnv.monitoring.ssh_secret_key; | ||
197 | } | ||
198 | ]; | ||
119 | # needed since extraResource is not in the closure | 199 | # needed since extraResource is not in the closure |
120 | systemd.services.naemon.path = [ myplugins ]; | 200 | systemd.services.naemon.path = [ myplugins ]; |
121 | services.naemon = { | 201 | services.naemon = { |
@@ -126,7 +206,7 @@ in | |||
126 | log_initial_states=1 | 206 | log_initial_states=1 |
127 | date_format=iso8601 | 207 | date_format=iso8601 |
128 | admin_email=${config.myEnv.monitoring.email} | 208 | admin_email=${config.myEnv.monitoring.email} |
129 | 209 | '' + lib.optionalString (!cfg.master) '' | |
130 | obsess_over_services=1 | 210 | obsess_over_services=1 |
131 | ocsp_command=notify-master | 211 | ocsp_command=notify-master |
132 | ''; | 212 | ''; |
@@ -134,8 +214,17 @@ in | |||
134 | $USER2$=${myplugins} | 214 | $USER2$=${myplugins} |
135 | $USER200$=${config.myEnv.monitoring.status_url} | 215 | $USER200$=${config.myEnv.monitoring.status_url} |
136 | $USER201$=${config.myEnv.monitoring.status_token} | 216 | $USER201$=${config.myEnv.monitoring.status_token} |
217 | $USER202$=${config.myEnv.monitoring.http_user_password} | ||
218 | $USER203$=${config.secrets.fullPaths."naemon/id_rsa"} | ||
219 | $USER204$=${config.myEnv.monitoring.imap_login} | ||
220 | $USER205$=${config.myEnv.monitoring.imap_password} | ||
221 | $USER206$=${config.myEnv.monitoring.slack_channel} | ||
222 | $USER207$=${config.myEnv.monitoring.slack_url} | ||
137 | ''; | 223 | ''; |
138 | objectDefs = toObjects commonObjects + toObjects hostObjects; | 224 | objectDefs = toObjects commonObjects |
225 | + toObjects hostObjects | ||
226 | + lib.optionalString cfg.master (toObjects masterObjects) | ||
227 | + lib.optionalString cfg.master (toObjects masterPassiveObjects); | ||
139 | }; | 228 | }; |
140 | }; | 229 | }; |
141 | } | 230 | } |