]>
Commit | Line | Data |
---|---|---|
1 | { config, myconfig, pkgs, lib, ... }: | |
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 | ''; | |
17 | in | |
18 | { | |
19 | options = { | |
20 | myServices.monitoring.enable = lib.mkOption { | |
21 | type = lib.types.bool; | |
22 | default = false; | |
23 | description = '' | |
24 | Whether to enable monitoring. | |
25 | ''; | |
26 | }; | |
27 | }; | |
28 | ||
29 | config = lib.mkIf config.myServices.monitoring.enable { | |
30 | services.duplyBackup.profiles.monitoring = { | |
31 | rootDir = config.services.naemon.varDir; | |
32 | }; | |
33 | security.sudo.extraRules = [ | |
34 | { | |
35 | commands = [ | |
36 | { command = "${pkgs.mdadm}/bin/mdadm --monitor --scan -1"; options = [ "NOPASSWD" ]; } | |
37 | { command = "${pkgs.postfix}/bin/mailq"; options = [ "NOPASSWD" ]; } | |
38 | ]; | |
39 | users = [ "naemon" ]; | |
40 | runAs = "root"; | |
41 | } | |
42 | ]; | |
43 | environment.etc."mdadm.conf" = { | |
44 | enable = true; | |
45 | mode = "0644"; | |
46 | user = "root"; | |
47 | text = "MAILADDR ${myconfig.env.monitoring.email}"; | |
48 | }; | |
49 | ||
50 | # needed since extraResource is not in the closure | |
51 | systemd.services.naemon.path = [ myplugins ]; | |
52 | services.naemon = { | |
53 | enable = true; | |
54 | extraConfig = '' | |
55 | broker_module=${pkgs.naemon-livestatus}/lib/naemon-livestatus/livestatus.so ${config.services.naemon.runDir}/live | |
56 | use_syslog=1 | |
57 | log_initial_states=1 | |
58 | date_format=iso8601 | |
59 | admin_email=${myconfig.env.monitoring.email} | |
60 | ||
61 | obsess_over_services=1 | |
62 | ocsp_command=notify-master | |
63 | ''; | |
64 | extraResource = '' | |
65 | $USER2$=${myplugins} | |
66 | $USER200$=${myconfig.env.monitoring.status_url} | |
67 | $USER201$=${myconfig.env.monitoring.status_token} | |
68 | ''; | |
69 | objectDefs = builtins.readFile ./conf/local_services.cfg | |
70 | + builtins.readFile ./conf/timeperiods.cfg | |
71 | + builtins.readFile ./conf/services.cfg | |
72 | + builtins.readFile ./conf/contacts.cfg | |
73 | + builtins.readFile ./conf/hosts.cfg | |
74 | + '' | |
75 | define command { | |
76 | command_line ${myplugins}/send_nrdp.sh -u "$USER200$" -t "$USER201$" -H "$HOSTADDRESS$" -s "$SERVICEDESC$" -S "$SERVICESTATEID$" -o "$SERVICEOUTPUT$" | |
77 | command_name notify-master | |
78 | } | |
79 | define service { | |
80 | service_description No mdadm array is degraded | |
81 | use local-service | |
82 | check_command check_command_output!${pkgs.mdadm}/bin/mdadm --monitor --scan -1!^$!-s 0 -r root | |
83 | } | |
84 | ||
85 | define service { | |
86 | service_description mailq is empty | |
87 | use local-service | |
88 | check_command check_mailq | |
89 | } | |
90 | ||
91 | define command { | |
92 | command_name check_mailq | |
93 | command_line $USER1$/check_mailq -s -w 1 -c 2 | |
94 | } | |
95 | ||
96 | define service { | |
97 | name local-service | |
98 | use generic-service | |
99 | host_name eldiron.immae.eu | |
100 | check_interval 5 | |
101 | max_check_attempts 4 | |
102 | register 0 | |
103 | retry_interval 1 | |
104 | } | |
105 | define host { | |
106 | host_name eldiron.immae.eu | |
107 | alias eldiron.immae.eu | |
108 | address eldiron.immae.eu | |
109 | use linux-server | |
110 | } | |
111 | ''; | |
112 | }; | |
113 | }; | |
114 | } |