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