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.
This commit is contained in:
Casey Ransom 2016-10-08 15:04:27 +00:00 committed by Casey Ransom
parent a000ed181c
commit 74558c88fb
2 changed files with 76 additions and 31 deletions

View File

@ -6,31 +6,39 @@ let
cfg = config.services.smokeping; cfg = config.services.smokeping;
smokepingHome = "/var/lib/smokeping"; smokepingHome = "/var/lib/smokeping";
smokepingPidDir = "/run"; smokepingPidDir = "/run";
configFile = '' configFile =
*** General *** if cfg.config == null
owner = ${cfg.owner} then
contact = ${cfg.ownerEmail} ''
mailhost = ${cfg.mailHost} *** General ***
#sendmail = /var/setuid-wrappers/sendmail owner = ${cfg.owner}
imgcache = ${smokepingHome}/cache contact = ${cfg.ownerEmail}
imgurl = http://${cfg.hostName}:${builtins.toString cfg.port}/cache ${lib.optionalString (cfg.mailHost != "") "mailhost = ${cfg.mailHost}"}
datadir = ${smokepingHome}/data ${lib.optionalString (cfg.sendmail != null) "sendmail = ${cfg.sendmail}"}
piddir = ${smokepingPidDir} imgcache = ${smokepingHome}/cache
cgiurl = http://${cfg.hostName}:${builtins.toString cfg.port}/smokeping.cgi imgurl = http://${cfg.hostName}:${builtins.toString cfg.port}/cache
smokemail = ${cfg.smokeMailTemplate} datadir = ${smokepingHome}/data
*** Presentation *** pagedir = ${smokepingHome}/cache
template = ${cfg.presentationTemplate} piddir = ${smokepingPidDir}
${cfg.presentationConfig} cgiurl = http://${cfg.hostName}:${builtins.toString cfg.port}/smokeping.cgi
#*** Alerts *** linkstyle = ${cfg.linkStyle}
#${cfg.alertConfig} smokemail = ${cfg.smokeMailTemplate}
*** Database *** *** Presentation ***
${cfg.databaseConfig} template = ${cfg.presentationTemplate}
*** Probes *** ${cfg.presentationConfig}
${cfg.probeConfig} *** Alerts ***
*** Targets *** ${cfg.alertConfig}
${cfg.targetConfig} *** Database ***
${cfg.extraConfig} ${cfg.databaseConfig}
''; *** Probes ***
${cfg.probeConfig}
*** Targets ***
${cfg.targetConfig}
${cfg.extraConfig}
''
else
cfg.config;
configPath = pkgs.writeText "smokeping.conf" configFile; configPath = pkgs.writeText "smokeping.conf" configFile;
cgiHome = pkgs.writeScript "smokeping.fcgi" '' cgiHome = pkgs.writeScript "smokeping.fcgi" ''
#!${pkgs.bash}/bin/bash #!${pkgs.bash}/bin/bash
@ -59,8 +67,15 @@ in
}; };
mailHost = mkOption { mailHost = mkOption {
type = types.string; type = types.string;
default = "127.0.0.1"; default = "";
description = "Use this SMTP server rather than localhost"; example = "localhost";
description = "Use this SMTP server to send alerts";
};
sendmail = mkOption {
type = types.nullOr types.path;
default = null;
example = "/var/setuid-wrappers/sendmail";
description = "Use this sendmail compatible script to deliver alerts";
}; };
smokeMailTemplate = mkOption { smokeMailTemplate = mkOption {
type = types.string; type = types.string;
@ -71,6 +86,7 @@ in
package = mkOption { package = mkOption {
type = types.package; type = types.package;
default = pkgs.smokeping; default = pkgs.smokeping;
defaultText = "pkgs.smokeping";
description = "Specify a custom smokeping package"; description = "Specify a custom smokeping package";
}; };
owner = mkOption { owner = mkOption {
@ -85,6 +101,12 @@ in
example = "somewhere.example.com"; example = "somewhere.example.com";
description = "DNS name for the urls generated in the cgi."; description = "DNS name for the urls generated in the cgi.";
}; };
linkStyle = mkOption {
type = types.enum ["original" "absolute" "relative"];
default = "relative";
example = "absolute";
description = "DNS name for the urls generated in the cgi.";
};
port = mkOption { port = mkOption {
type = types.int; type = types.int;
default = 8081; default = 8081;
@ -132,7 +154,10 @@ in
}; };
alertConfig = mkOption { alertConfig = mkOption {
type = types.string; type = types.string;
default = ""; default = ''
to = root@localhost
from = smokeping@localhost
'';
example = literalExample '' example = literalExample ''
to = alertee@address.somewhere to = alertee@address.somewhere
from = smokealert@company.xy from = smokealert@company.xy
@ -223,12 +248,26 @@ in
default = ""; default = "";
description = "Any additional customization not already included."; description = "Any additional customization not already included.";
}; };
config = mkOption {
type = types.nullOr types.string;
default = null;
description = "Full smokeping config supplied by the user. Overrides " +
"and replaces any other configuration supplied.";
};
}; };
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
assertions = [
{
assertion = !(cfg.sendmail != null && cfg.mailHost != "");
message = "services.smokeping: sendmail and Mailhost cannot both be enabled.";
}
];
security.setuidPrograms = [ "fping" ];
environment.systemPackages = [ pkgs.fping ];
users.extraUsers = singleton { users.extraUsers = singleton {
name = cfg.user; name = cfg.user;
isNormalUser = false; isNormalUser = false;
@ -243,9 +282,12 @@ in
serviceConfig.PermissionsStartOnly = true; serviceConfig.PermissionsStartOnly = true;
preStart = '' preStart = ''
mkdir -m 0755 -p ${smokepingHome}/cache ${smokepingHome}/data mkdir -m 0755 -p ${smokepingHome}/cache ${smokepingHome}/data
rm -f ${smokepingHome}/cropper
ln -s ${cfg.package}/htdocs/cropper ${smokepingHome}/cropper
chown -R ${cfg.user} ${smokepingHome} chown -R ${cfg.user} ${smokepingHome}
cp ${cgiHome} ${smokepingHome}/smokeping.fcgi cp ${cgiHome} ${smokepingHome}/smokeping.fcgi
${cfg.package}/bin/smokeping --check --config=${configPath} ${cfg.package}/bin/smokeping --check --config=${configPath}
${cfg.package}/bin/smokeping --static --config=${configPath}
''; '';
script = ''${cfg.package}/bin/smokeping --config=${configPath} --nodaemon''; script = ''${cfg.package}/bin/smokeping --config=${configPath} --nodaemon'';
}; };
@ -253,8 +295,9 @@ in
wantedBy = [ "multi-user.target"]; wantedBy = [ "multi-user.target"];
requires = [ "smokeping.service"]; requires = [ "smokeping.service"];
partOf = [ "smokeping.service"]; partOf = [ "smokeping.service"];
path = with pkgs; [ bash rrdtool smokeping ]; path = with pkgs; [ bash rrdtool smokeping thttpd ];
script = ''${pkgs.thttpd}/bin/thttpd -u ${cfg.user} -c "**.fcgi" -d ${smokepingHome} -p ${builtins.toString cfg.port} -D''; script = ''thttpd -u ${cfg.user} -c "**.fcgi" -d ${smokepingHome} -p ${builtins.toString cfg.port} -D -nos'';
serviceConfig.Restart = "always";
}; };
}; };
} }

View File

@ -11,9 +11,10 @@ import ./make-test.nix ({ pkgs, ...} : {
services.smokeping = { services.smokeping = {
enable = true; enable = true;
port = 8081; port = 8081;
mailHost = "127.0.0.2";
probeConfig = '' probeConfig = ''
+ FPing + FPing
binary = ${pkgs.fping}/bin/fping binary = /var/setuid-wrappers/fping
offset = 0% offset = 0%
''; '';
}; };
@ -27,5 +28,6 @@ import ./make-test.nix ({ pkgs, ...} : {
$sm->waitForFile("/var/lib/smokeping/data/Local/LocalMachine.rrd"); $sm->waitForFile("/var/lib/smokeping/data/Local/LocalMachine.rrd");
$sm->succeed("curl -s -f localhost:8081/smokeping.fcgi?target=Local"); $sm->succeed("curl -s -f localhost:8081/smokeping.fcgi?target=Local");
$sm->succeed("ls /var/lib/smokeping/cache/Local/LocalMachine_mini.png"); $sm->succeed("ls /var/lib/smokeping/cache/Local/LocalMachine_mini.png");
$sm->succeed("ls /var/lib/smokeping/cache/index.html");
''; '';
}) })