git.iko.soy/typeable/nixpkgs
on master help sign in
smokeping module: fix missing js, broken alerts

The initial commit accidentally left in some commented code and if you were using alerts, they simply didn't work. Smokeping also includes some JS code for the webui allowing you to zoom into graphs and it was not passed into the homedir. Additionally, generate static html pages for other webservers to serve the cache directory. Add additional options to specify sendmail path or mailhost and verify that both are not set. Add one extra config hook that allows you to bypass all of the invidual config stanzas and just hand it a string.

commit74558c88fb52683952e42793b76716dfb7f5b148 authorCasey Ransom <cransom@referentiallabs.com> dateSat 8 Oct 2016, 15:04 (10 years ago) parenta000ed1
2 files changed+76−31
nixos/modules/services/networking/smokeping.nix+73−30 nixos/tests/smokeping.nix+3−1
nixos/modules/services/networking/smokeping.nix+73−30
@@ -6,31 +6,39 @@ let
66 cfg = config.services.smokeping;
77 smokepingHome = "/var/lib/smokeping";
88 smokepingPidDir = "/run";
9− configFile = ''
10− *** General ***
11− owner = ${cfg.owner}
12− contact = ${cfg.ownerEmail}
13− mailhost = ${cfg.mailHost}
14− #sendmail = /var/setuid-wrappers/sendmail
15− imgcache = ${smokepingHome}/cache
16− imgurl = http://${cfg.hostName}:${builtins.toString cfg.port}/cache
17− datadir = ${smokepingHome}/data
18− piddir = ${smokepingPidDir}
19− cgiurl = http://${cfg.hostName}:${builtins.toString cfg.port}/smokeping.cgi
20− smokemail = ${cfg.smokeMailTemplate}
21− *** Presentation ***
22− template = ${cfg.presentationTemplate}
23− ${cfg.presentationConfig}
24− #*** Alerts ***
25− #${cfg.alertConfig}
26− *** Database ***
27− ${cfg.databaseConfig}
28− *** Probes ***
29− ${cfg.probeConfig}
30− *** Targets ***
31− ${cfg.targetConfig}
32− ${cfg.extraConfig}
33− '';
9+ configFile =
10+ if cfg.config == null
11+ then
12+ ''
13+ *** General ***
14+ owner = ${cfg.owner}
15+ contact = ${cfg.ownerEmail}
16+ ${lib.optionalString (cfg.mailHost != "") "mailhost = ${cfg.mailHost}"}
17+ ${lib.optionalString (cfg.sendmail != null) "sendmail = ${cfg.sendmail}"}
18+ imgcache = ${smokepingHome}/cache
19+ imgurl = http://${cfg.hostName}:${builtins.toString cfg.port}/cache
20+ datadir = ${smokepingHome}/data
21+ pagedir = ${smokepingHome}/cache
22+ piddir = ${smokepingPidDir}
23+ cgiurl = http://${cfg.hostName}:${builtins.toString cfg.port}/smokeping.cgi
24+ linkstyle = ${cfg.linkStyle}
25+ smokemail = ${cfg.smokeMailTemplate}
26+ *** Presentation ***
27+ template = ${cfg.presentationTemplate}
28+ ${cfg.presentationConfig}
29+ *** Alerts ***
30+ ${cfg.alertConfig}
31+ *** Database ***
32+ ${cfg.databaseConfig}
33+ *** Probes ***
34+ ${cfg.probeConfig}
35+ *** Targets ***
36+ ${cfg.targetConfig}
37+ ${cfg.extraConfig}
38+ ''
39+ else
40+ cfg.config;
41+
3442 configPath = pkgs.writeText "smokeping.conf" configFile;
3543 cgiHome = pkgs.writeScript "smokeping.fcgi" ''
3644 #!${pkgs.bash}/bin/bash
@@ -59,8 +67,15 @@ in
5967 };
6068 mailHost = mkOption {
6169 type = types.string;
62− default = "127.0.0.1";
63− description = "Use this SMTP server rather than localhost";
70+ default = "";
71+ example = "localhost";
72+ description = "Use this SMTP server to send alerts";
73+ };
74+ sendmail = mkOption {
75+ type = types.nullOr types.path;
76+ default = null;
77+ example = "/var/setuid-wrappers/sendmail";
78+ description = "Use this sendmail compatible script to deliver alerts";
6479 };
6580 smokeMailTemplate = mkOption {
6681 type = types.string;
@@ -71,6 +86,7 @@ in
7186 package = mkOption {
7287 type = types.package;
7388 default = pkgs.smokeping;
89+ defaultText = "pkgs.smokeping";
7490 description = "Specify a custom smokeping package";
7591 };
7692 owner = mkOption {
@@ -85,6 +101,12 @@ in
85101 example = "somewhere.example.com";
86102 description = "DNS name for the urls generated in the cgi.";
87103 };
104+ linkStyle = mkOption {
105+ type = types.enum ["original" "absolute" "relative"];
106+ default = "relative";
107+ example = "absolute";
108+ description = "DNS name for the urls generated in the cgi.";
109+ };
88110 port = mkOption {
89111 type = types.int;
90112 default = 8081;
@@ -132,7 +154,10 @@ in
132154 };
133155 alertConfig = mkOption {
134156 type = types.string;
135− default = "";
157+ default = ''
158+ to = root@localhost
159+ from = smokeping@localhost
160+ '';
136161 example = literalExample ''
137162 to = alertee@address.somewhere
138163 from = smokealert@company.xy
@@ -223,12 +248,26 @@ in
223248 default = "";
224249 description = "Any additional customization not already included.";
225250 };
251+ config = mkOption {
252+ type = types.nullOr types.string;
253+ default = null;
254+ description = "Full smokeping config supplied by the user. Overrides " +
255+ "and replaces any other configuration supplied.";
256+ };
226257
227258 };
228259
229260 };
230261
231262 config = mkIf cfg.enable {
263+ assertions = [
264+ {
265+ assertion = !(cfg.sendmail != null && cfg.mailHost != "");
266+ message = "services.smokeping: sendmail and Mailhost cannot both be enabled.";
267+ }
268+ ];
269+ security.setuidPrograms = [ "fping" ];
270+ environment.systemPackages = [ pkgs.fping ];
232271 users.extraUsers = singleton {
233272 name = cfg.user;
234273 isNormalUser = false;
@@ -243,9 +282,12 @@ in
243282 serviceConfig.PermissionsStartOnly = true;
244283 preStart = ''
245284 mkdir -m 0755 -p ${smokepingHome}/cache ${smokepingHome}/data
285+ rm -f ${smokepingHome}/cropper
286+ ln -s ${cfg.package}/htdocs/cropper ${smokepingHome}/cropper
246287 chown -R ${cfg.user} ${smokepingHome}
247288 cp ${cgiHome} ${smokepingHome}/smokeping.fcgi
248289 ${cfg.package}/bin/smokeping --check --config=${configPath}
290+ ${cfg.package}/bin/smokeping --static --config=${configPath}
249291 '';
250292 script = ''${cfg.package}/bin/smokeping --config=${configPath} --nodaemon'';
251293 };
@@ -253,8 +295,9 @@ in
253295 wantedBy = [ "multi-user.target"];
254296 requires = [ "smokeping.service"];
255297 partOf = [ "smokeping.service"];
256− path = with pkgs; [ bash rrdtool smokeping ];
257− script = ''${pkgs.thttpd}/bin/thttpd -u ${cfg.user} -c "**.fcgi" -d ${smokepingHome} -p ${builtins.toString cfg.port} -D'';
298+ path = with pkgs; [ bash rrdtool smokeping thttpd ];
299+ script = ''thttpd -u ${cfg.user} -c "**.fcgi" -d ${smokepingHome} -p ${builtins.toString cfg.port} -D -nos'';
300+ serviceConfig.Restart = "always";
258301 };
259302 };
260303}
nixos/tests/smokeping.nix+3−1
@@ -11,9 +11,10 @@ import ./make-test.nix ({ pkgs, ...} : {
1111 services.smokeping = {
1212 enable = true;
1313 port = 8081;
14+ mailHost = "127.0.0.2";
1415 probeConfig = ''
1516 + FPing
16− binary = ${pkgs.fping}/bin/fping
17+ binary = /var/setuid-wrappers/fping
1718 offset = 0%
1819 '';
1920 };
@@ -27,5 +28,6 @@ import ./make-test.nix ({ pkgs, ...} : {
2728 $sm->waitForFile("/var/lib/smokeping/data/Local/LocalMachine.rrd");
2829 $sm->succeed("curl -s -f localhost:8081/smokeping.fcgi?target=Local");
2930 $sm->succeed("ls /var/lib/smokeping/cache/Local/LocalMachine_mini.png");
31+ $sm->succeed("ls /var/lib/smokeping/cache/index.html");
3032 '';
3133})