2014-11-20 15:49:45 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.bosun;
|
|
|
|
|
|
|
|
configFile = pkgs.writeText "bosun.conf" ''
|
2015-11-16 14:08:10 +01:00
|
|
|
${optionalString (cfg.opentsdbHost !=null) "tsdbHost = ${cfg.opentsdbHost}"}
|
|
|
|
${optionalString (cfg.influxHost !=null) "influxHost = ${cfg.influxHost}"}
|
2014-11-20 15:49:45 +01:00
|
|
|
httpListen = ${cfg.listenAddress}
|
|
|
|
stateFile = ${cfg.stateFile}
|
2015-11-16 14:08:10 +01:00
|
|
|
ledisDir = ${cfg.ledisDir}
|
2015-11-07 23:59:23 +01:00
|
|
|
checkFrequency = ${cfg.checkFrequency}
|
2014-11-20 15:56:49 +01:00
|
|
|
|
|
|
|
${cfg.extraConfig}
|
2014-11-20 15:49:45 +01: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 06:11:08 +02:00
|
|
|
default = pkgs.bosun;
|
2016-01-17 19:34:55 +01:00
|
|
|
defaultText = "pkgs.bosun";
|
2015-09-05 06:11:08 +02:00
|
|
|
example = literalExample "pkgs.bosun";
|
2014-11-20 15:49:45 +01: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 {
|
2015-11-16 14:08:10 +01:00
|
|
|
type = types.nullOr types.string;
|
2014-11-20 15:49:45 +01:00
|
|
|
default = "localhost:4242";
|
|
|
|
description = ''
|
|
|
|
Host and port of the OpenTSDB database that stores bosun data.
|
2015-11-16 14:08:10 +01:00
|
|
|
To disable opentsdb you can pass null as parameter.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
influxHost = mkOption {
|
|
|
|
type = types.nullOr types.string;
|
|
|
|
default = null;
|
|
|
|
example = "localhost:8086";
|
|
|
|
description = ''
|
|
|
|
Host and port of the influxdb database.
|
2014-11-20 15:49:45 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
listenAddress = mkOption {
|
|
|
|
type = types.string;
|
|
|
|
default = ":8070";
|
|
|
|
description = ''
|
|
|
|
The host address and port that bosun's web interface will listen on.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
stateFile = mkOption {
|
2015-11-16 14:08:10 +01:00
|
|
|
type = types.path;
|
2014-11-20 15:49:45 +01:00
|
|
|
default = "/var/lib/bosun/bosun.state";
|
|
|
|
description = ''
|
|
|
|
Path to bosun's state file.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-11-16 14:08:10 +01:00
|
|
|
ledisDir = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/lib/bosun/ledis_data";
|
|
|
|
description = ''
|
|
|
|
Path to bosun's ledis data dir
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-11-07 23:59:23 +01:00
|
|
|
checkFrequency = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "5m";
|
|
|
|
description = ''
|
|
|
|
Bosun's check frequency
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-11-20 15:56:49 +01:00
|
|
|
extraConfig = mkOption {
|
2016-10-23 19:33:41 +02:00
|
|
|
type = types.lines;
|
2014-11-20 15:56:49 +01:00
|
|
|
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 15:49:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2014-12-02 12:59:14 +01:00
|
|
|
config = mkIf cfg.enable {
|
2015-11-16 14:08:10 +01:00
|
|
|
|
2014-11-20 15:49:45 +01:00
|
|
|
systemd.services.bosun = {
|
|
|
|
description = "bosun metrics collector (part of Bosun)";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
2016-01-18 15:57:25 +01:00
|
|
|
preStart = ''
|
|
|
|
mkdir -p "$(dirname "${cfg.stateFile}")";
|
|
|
|
touch "${cfg.stateFile}"
|
|
|
|
touch "${cfg.stateFile}.tmp"
|
|
|
|
|
|
|
|
mkdir -p "${cfg.ledisDir}";
|
2014-11-20 15:49:45 +01:00
|
|
|
|
|
|
|
if [ "$(id -u)" = 0 ]; then
|
2016-01-18 15:57:25 +01:00
|
|
|
chown ${cfg.user}:${cfg.group} "${cfg.stateFile}"
|
|
|
|
chown ${cfg.user}:${cfg.group} "${cfg.stateFile}.tmp"
|
|
|
|
chown ${cfg.user}:${cfg.group} "${cfg.ledisDir}"
|
2014-11-20 15:49:45 +01:00
|
|
|
fi
|
2016-01-18 15:57:25 +01:00
|
|
|
'';
|
2014-11-20 15:49:45 +01:00
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
PermissionsStartOnly = true;
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
ExecStart = ''
|
2016-06-13 23:32:16 +02:00
|
|
|
${cfg.package.bin}/bin/bosun -c ${configFile}
|
2014-11-20 15:49:45 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
users.extraUsers.bosun = {
|
|
|
|
description = "bosun user";
|
|
|
|
group = "bosun";
|
|
|
|
uid = config.ids.uids.bosun;
|
|
|
|
};
|
|
|
|
|
|
|
|
users.extraGroups.bosun.gid = config.ids.gids.bosun;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|