at v192 3.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 tsdbHost = ${cfg.opentsdbHost} 10 httpListen = ${cfg.listenAddress} 11 stateFile = ${cfg.stateFile} 12 checkFrequency = 5m 13 14 ${cfg.extraConfig} 15 ''; 16 17in { 18 19 options = { 20 21 services.bosun = { 22 23 enable = mkOption { 24 type = types.bool; 25 default = false; 26 description = '' 27 Whether to run bosun. 28 ''; 29 }; 30 31 package = mkOption { 32 type = types.package; 33 default = pkgs.bosun; 34 example = literalExample "pkgs.bosun"; 35 description = '' 36 bosun binary to use. 37 ''; 38 }; 39 40 user = mkOption { 41 type = types.string; 42 default = "bosun"; 43 description = '' 44 User account under which bosun runs. 45 ''; 46 }; 47 48 group = mkOption { 49 type = types.string; 50 default = "bosun"; 51 description = '' 52 Group account under which bosun runs. 53 ''; 54 }; 55 56 opentsdbHost = mkOption { 57 type = types.string; 58 default = "localhost:4242"; 59 description = '' 60 Host and port of the OpenTSDB database that stores bosun data. 61 ''; 62 }; 63 64 listenAddress = mkOption { 65 type = types.string; 66 default = ":8070"; 67 description = '' 68 The host address and port that bosun's web interface will listen on. 69 ''; 70 }; 71 72 stateFile = mkOption { 73 type = types.string; 74 default = "/var/lib/bosun/bosun.state"; 75 description = '' 76 Path to bosun's state file. 77 ''; 78 }; 79 80 extraConfig = mkOption { 81 type = types.string; 82 default = ""; 83 description = '' 84 Extra configuration options for Bosun. You should describe your 85 desired templates, alerts, macros, etc through this configuration 86 option. 87 88 A detailed description of the supported syntax can be found at-spi2-atk 89 http://bosun.org/configuration.html 90 ''; 91 }; 92 93 }; 94 95 }; 96 97 config = mkIf cfg.enable { 98 99 systemd.services.bosun = { 100 description = "bosun metrics collector (part of Bosun)"; 101 wantedBy = [ "multi-user.target" ]; 102 103 preStart = 104 '' 105 mkdir -p `dirname ${cfg.stateFile}`; 106 touch ${cfg.stateFile} 107 touch ${cfg.stateFile}.tmp 108 109 if [ "$(id -u)" = 0 ]; then 110 chown ${cfg.user}:${cfg.group} ${cfg.stateFile} 111 chown ${cfg.user}:${cfg.group} ${cfg.stateFile}.tmp 112 fi 113 ''; 114 115 serviceConfig = { 116 PermissionsStartOnly = true; 117 User = cfg.user; 118 Group = cfg.group; 119 ExecStart = '' 120 ${cfg.package}/bin/bosun -c ${configFile} 121 ''; 122 }; 123 }; 124 125 users.extraUsers.bosun = { 126 description = "bosun user"; 127 group = "bosun"; 128 uid = config.ids.uids.bosun; 129 }; 130 131 users.extraGroups.bosun.gid = config.ids.gids.bosun; 132 133 }; 134 135}