1 { config, lib, pkgs, ... }:
3 cfg = config.services.bosun;
5 configFile = pkgs.writeText "bosun.conf" ''
6 ${lib.optionalString (cfg.opentsdbHost !=null) "tsdbHost = ${cfg.opentsdbHost}"}
7 ${lib.optionalString (cfg.influxHost !=null) "influxHost = ${cfg.influxHost}"}
8 httpListen = ${cfg.listenAddress}
9 stateFile = ${cfg.stateFile}
10 ledisDir = ${cfg.ledisDir}
11 checkFrequency = ${cfg.checkFrequency}
22 enable = lib.mkEnableOption "bosun";
24 package = lib.mkPackageOption pkgs "bosun" { };
30 User account under which bosun runs.
34 group = lib.mkOption {
38 Group account under which bosun runs.
42 opentsdbHost = lib.mkOption {
43 type = lib.types.nullOr lib.types.str;
44 default = "localhost:4242";
46 Host and port of the OpenTSDB database that stores bosun data.
47 To disable opentsdb you can pass null as parameter.
51 influxHost = lib.mkOption {
52 type = lib.types.nullOr lib.types.str;
54 example = "localhost:8086";
56 Host and port of the influxdb database.
60 listenAddress = lib.mkOption {
64 The host address and port that bosun's web interface will listen on.
68 stateFile = lib.mkOption {
69 type = lib.types.path;
70 default = "/var/lib/bosun/bosun.state";
72 Path to bosun's state file.
76 ledisDir = lib.mkOption {
77 type = lib.types.path;
78 default = "/var/lib/bosun/ledis_data";
80 Path to bosun's ledis data dir
84 checkFrequency = lib.mkOption {
88 Bosun's check frequency
92 extraConfig = lib.mkOption {
93 type = lib.types.lines;
96 Extra configuration options for Bosun. You should describe your
97 desired templates, alerts, macros, etc through this configuration
100 A detailed description of the supported syntax can be found at-spi2-atk
101 https://bosun.org/configuration.html
109 config = lib.mkIf cfg.enable {
111 systemd.services.bosun = {
112 description = "bosun metrics collector (part of Bosun)";
113 wantedBy = [ "multi-user.target" ];
116 mkdir -p "$(dirname "${cfg.stateFile}")";
117 touch "${cfg.stateFile}"
118 touch "${cfg.stateFile}.tmp"
120 mkdir -p "${cfg.ledisDir}";
122 if [ "$(id -u)" = 0 ]; then
123 chown ${cfg.user}:${cfg.group} "${cfg.stateFile}"
124 chown ${cfg.user}:${cfg.group} "${cfg.stateFile}.tmp"
125 chown ${cfg.user}:${cfg.group} "${cfg.ledisDir}"
130 PermissionsStartOnly = true;
134 ${cfg.package}/bin/bosun -c ${configFile}
139 users.users.bosun = {
140 description = "bosun user";
142 uid = config.ids.uids.bosun;
145 users.groups.bosun.gid = config.ids.gids.bosun;