1
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-06-21 17:01:10 +03:00
nixpkgs/nixos/modules/services/monitoring/bosun.nix
Silvan Mosberger 4f0dadbf38 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build a08b3a4d19.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +01:00

155 lines
3.6 KiB
Nix

{
config,
lib,
pkgs,
...
}:
let
cfg = config.services.bosun;
configFile = pkgs.writeText "bosun.conf" ''
${lib.optionalString (cfg.opentsdbHost != null) "tsdbHost = ${cfg.opentsdbHost}"}
${lib.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 = {
enable = lib.mkEnableOption "bosun";
package = lib.mkPackageOption pkgs "bosun" { };
user = lib.mkOption {
type = lib.types.str;
default = "bosun";
description = ''
User account under which bosun runs.
'';
};
group = lib.mkOption {
type = lib.types.str;
default = "bosun";
description = ''
Group account under which bosun runs.
'';
};
opentsdbHost = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = "localhost:4242";
description = ''
Host and port of the OpenTSDB database that stores bosun data.
To disable opentsdb you can pass null as parameter.
'';
};
influxHost = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
example = "localhost:8086";
description = ''
Host and port of the influxdb database.
'';
};
listenAddress = lib.mkOption {
type = lib.types.str;
default = ":8070";
description = ''
The host address and port that bosun's web interface will listen on.
'';
};
stateFile = lib.mkOption {
type = lib.types.path;
default = "/var/lib/bosun/bosun.state";
description = ''
Path to bosun's state file.
'';
};
ledisDir = lib.mkOption {
type = lib.types.path;
default = "/var/lib/bosun/ledis_data";
description = ''
Path to bosun's ledis data dir
'';
};
checkFrequency = lib.mkOption {
type = lib.types.str;
default = "5m";
description = ''
Bosun's check frequency
'';
};
extraConfig = lib.mkOption {
type = lib.types.lines;
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
https://bosun.org/configuration.html
'';
};
};
};
config = lib.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 = ''
${cfg.package}/bin/bosun -c ${configFile}
'';
};
};
users.users.bosun = {
description = "bosun user";
group = "bosun";
uid = config.ids.uids.bosun;
};
users.groups.bosun.gid = config.ids.gids.bosun;
};
}