2014-11-20 14:49:45 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.bosun;
|
|
|
|
|
|
|
|
configFile = pkgs.writeText "bosun.conf" ''
|
|
|
|
tsdbHost = ${cfg.opentsdbHost}
|
|
|
|
httpListen = ${cfg.listenAddress}
|
|
|
|
stateFile = ${cfg.stateFile}
|
2015-11-07 22:59:23 +00:00
|
|
|
checkFrequency = ${cfg.checkFrequency}
|
2014-11-20 14:56:49 +00:00
|
|
|
|
|
|
|
${cfg.extraConfig}
|
2014-11-20 14:49:45 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
in {
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.bosun = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to run bosun.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
2015-09-05 05:11:08 +01:00
|
|
|
default = pkgs.bosun;
|
|
|
|
example = literalExample "pkgs.bosun";
|
2014-11-20 14:49:45 +00:00
|
|
|
description = ''
|
|
|
|
bosun binary to use.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.string;
|
|
|
|
default = "bosun";
|
|
|
|
description = ''
|
|
|
|
User account under which bosun runs.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
type = types.string;
|
|
|
|
default = "bosun";
|
|
|
|
description = ''
|
|
|
|
Group account under which bosun runs.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
opentsdbHost = mkOption {
|
|
|
|
type = types.string;
|
|
|
|
default = "localhost:4242";
|
|
|
|
description = ''
|
|
|
|
Host and port of the OpenTSDB database that stores bosun data.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
listenAddress = mkOption {
|
|
|
|
type = types.string;
|
|
|
|
default = ":8070";
|
|
|
|
description = ''
|
|
|
|
The host address and port that bosun's web interface will listen on.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
stateFile = mkOption {
|
|
|
|
type = types.string;
|
|
|
|
default = "/var/lib/bosun/bosun.state";
|
|
|
|
description = ''
|
|
|
|
Path to bosun's state file.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-11-07 22:59:23 +00:00
|
|
|
checkFrequency = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "5m";
|
|
|
|
description = ''
|
|
|
|
Bosun's check frequency
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-11-20 14:56:49 +00:00
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.string;
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Extra configuration options for Bosun. You should describe your
|
|
|
|
desired templates, alerts, macros, etc through this configuration
|
|
|
|
option.
|
|
|
|
|
|
|
|
A detailed description of the supported syntax can be found at-spi2-atk
|
|
|
|
http://bosun.org/configuration.html
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-11-20 14:49:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2014-12-02 11:59:14 +00:00
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2014-11-20 14:49:45 +00:00
|
|
|
systemd.services.bosun = {
|
|
|
|
description = "bosun metrics collector (part of Bosun)";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
preStart =
|
|
|
|
''
|
|
|
|
mkdir -p `dirname ${cfg.stateFile}`;
|
|
|
|
touch ${cfg.stateFile}
|
|
|
|
touch ${cfg.stateFile}.tmp
|
|
|
|
|
|
|
|
if [ "$(id -u)" = 0 ]; then
|
|
|
|
chown ${cfg.user}:${cfg.group} ${cfg.stateFile}
|
|
|
|
chown ${cfg.user}:${cfg.group} ${cfg.stateFile}.tmp
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
PermissionsStartOnly = true;
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
ExecStart = ''
|
|
|
|
${cfg.package}/bin/bosun -c ${configFile}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
users.extraUsers.bosun = {
|
|
|
|
description = "bosun user";
|
|
|
|
group = "bosun";
|
|
|
|
uid = config.ids.uids.bosun;
|
|
|
|
};
|
|
|
|
|
|
|
|
users.extraGroups.bosun.gid = config.ids.gids.bosun;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|