2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.bosun;
|
|
|
|
|
|
|
|
configFile = pkgs.writeText "bosun.conf" ''
|
|
|
|
${optionalString (cfg.opentsdbHost !=null) "tsdbHost = ${cfg.opentsdbHost}"}
|
|
|
|
${optionalString (cfg.influxHost !=null) "influxHost = ${cfg.influxHost}"}
|
|
|
|
httpListen = ${cfg.listenAddress}
|
|
|
|
stateFile = ${cfg.stateFile}
|
|
|
|
ledisDir = ${cfg.ledisDir}
|
|
|
|
checkFrequency = ${cfg.checkFrequency}
|
|
|
|
|
|
|
|
${cfg.extraConfig}
|
|
|
|
'';
|
|
|
|
|
|
|
|
in {
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.bosun = {
|
|
|
|
|
2022-11-21 17:40:18 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "bosun");
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.bosun;
|
2021-10-06 13:57:05 +00:00
|
|
|
defaultText = literalExpression "pkgs.bosun";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
bosun binary to use.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "bosun";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
User account under which bosun runs.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "bosun";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Group account under which bosun runs.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
opentsdbHost = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = "localhost:4242";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Host and port of the OpenTSDB database that stores bosun data.
|
|
|
|
To disable opentsdb you can pass null as parameter.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
influxHost = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "localhost:8086";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Host and port of the influxdb database.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
listenAddress = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = ":8070";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
The host address and port that bosun's web interface will listen on.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
stateFile = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/lib/bosun/bosun.state";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Path to bosun's state file.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
ledisDir = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/lib/bosun/ledis_data";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Path to bosun's ledis data dir
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
checkFrequency = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "5m";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Bosun's check frequency
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
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
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
mkdir -p "${cfg.ledisDir}";
|
|
|
|
|
|
|
|
if [ "$(id -u)" = 0 ]; then
|
|
|
|
chown ${cfg.user}:${cfg.group} "${cfg.stateFile}"
|
|
|
|
chown ${cfg.user}:${cfg.group} "${cfg.stateFile}.tmp"
|
|
|
|
chown ${cfg.user}:${cfg.group} "${cfg.ledisDir}"
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
PermissionsStartOnly = true;
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
ExecStart = ''
|
2020-05-15 21:57:56 +00:00
|
|
|
${cfg.package}/bin/bosun -c ${configFile}
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
users.users.bosun = {
|
|
|
|
description = "bosun user";
|
|
|
|
group = "bosun";
|
|
|
|
uid = config.ids.uids.bosun;
|
|
|
|
};
|
|
|
|
|
|
|
|
users.groups.bosun.gid = config.ids.gids.bosun;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|