at 25.11-pre 3.7 kB view raw
1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7let 8 cfg = config.services.bosun; 9 10 configFile = pkgs.writeText "bosun.conf" '' 11 ${lib.optionalString (cfg.opentsdbHost != null) "tsdbHost = ${cfg.opentsdbHost}"} 12 ${lib.optionalString (cfg.influxHost != null) "influxHost = ${cfg.influxHost}"} 13 httpListen = ${cfg.listenAddress} 14 stateFile = ${cfg.stateFile} 15 ledisDir = ${cfg.ledisDir} 16 checkFrequency = ${cfg.checkFrequency} 17 18 ${cfg.extraConfig} 19 ''; 20 21in 22{ 23 24 options = { 25 26 services.bosun = { 27 28 enable = lib.mkEnableOption "bosun"; 29 30 package = lib.mkPackageOption pkgs "bosun" { }; 31 32 user = lib.mkOption { 33 type = lib.types.str; 34 default = "bosun"; 35 description = '' 36 User account under which bosun runs. 37 ''; 38 }; 39 40 group = lib.mkOption { 41 type = lib.types.str; 42 default = "bosun"; 43 description = '' 44 Group account under which bosun runs. 45 ''; 46 }; 47 48 opentsdbHost = lib.mkOption { 49 type = lib.types.nullOr lib.types.str; 50 default = "localhost:4242"; 51 description = '' 52 Host and port of the OpenTSDB database that stores bosun data. 53 To disable opentsdb you can pass null as parameter. 54 ''; 55 }; 56 57 influxHost = lib.mkOption { 58 type = lib.types.nullOr lib.types.str; 59 default = null; 60 example = "localhost:8086"; 61 description = '' 62 Host and port of the influxdb database. 63 ''; 64 }; 65 66 listenAddress = lib.mkOption { 67 type = lib.types.str; 68 default = ":8070"; 69 description = '' 70 The host address and port that bosun's web interface will listen on. 71 ''; 72 }; 73 74 stateFile = lib.mkOption { 75 type = lib.types.path; 76 default = "/var/lib/bosun/bosun.state"; 77 description = '' 78 Path to bosun's state file. 79 ''; 80 }; 81 82 ledisDir = lib.mkOption { 83 type = lib.types.path; 84 default = "/var/lib/bosun/ledis_data"; 85 description = '' 86 Path to bosun's ledis data dir 87 ''; 88 }; 89 90 checkFrequency = lib.mkOption { 91 type = lib.types.str; 92 default = "5m"; 93 description = '' 94 Bosun's check frequency 95 ''; 96 }; 97 98 extraConfig = lib.mkOption { 99 type = lib.types.lines; 100 default = ""; 101 description = '' 102 Extra configuration options for Bosun. You should describe your 103 desired templates, alerts, macros, etc through this configuration 104 option. 105 106 A detailed description of the supported syntax can be found at-spi2-atk 107 <https://bosun.org/configuration.html> 108 ''; 109 }; 110 111 }; 112 113 }; 114 115 config = lib.mkIf cfg.enable { 116 117 systemd.services.bosun = { 118 description = "bosun metrics collector (part of Bosun)"; 119 wantedBy = [ "multi-user.target" ]; 120 121 preStart = '' 122 mkdir -p "$(dirname "${cfg.stateFile}")"; 123 touch "${cfg.stateFile}" 124 touch "${cfg.stateFile}.tmp" 125 126 mkdir -p "${cfg.ledisDir}"; 127 128 if [ "$(id -u)" = 0 ]; then 129 chown ${cfg.user}:${cfg.group} "${cfg.stateFile}" 130 chown ${cfg.user}:${cfg.group} "${cfg.stateFile}.tmp" 131 chown ${cfg.user}:${cfg.group} "${cfg.ledisDir}" 132 fi 133 ''; 134 135 serviceConfig = { 136 PermissionsStartOnly = true; 137 User = cfg.user; 138 Group = cfg.group; 139 ExecStart = '' 140 ${cfg.package}/bin/bosun -c ${configFile} 141 ''; 142 }; 143 }; 144 145 users.users.bosun = { 146 description = "bosun user"; 147 group = "bosun"; 148 uid = config.ids.uids.bosun; 149 }; 150 151 users.groups.bosun.gid = config.ids.gids.bosun; 152 153 }; 154 155}