Merge pull request #190496 from NukaDuka/kthxbye

authored by Sandro and committed by GitHub d374d79d cf49501b

+331
+8
nixos/doc/manual/from_md/release-notes/rl-2211.section.xml
··· 212 212 </listitem> 213 213 <listitem> 214 214 <para> 215 + <link xlink:href="https://github.com/prymitive/kthxbye">kthxbye</link>, 216 + an alert acknowledgement management daemon for Prometheus 217 + Alertmanager. Available as 218 + <link xlink:href="options.html#opt-services.kthxbye.enable">services.kthxbye</link> 219 + </para> 220 + </listitem> 221 + <listitem> 222 + <para> 215 223 <link xlink:href="https://github.com/jtroo/kanata">kanata</link>, 216 224 a tool to improve keyboard comfort and usability with advanced 217 225 customization. Available as
+2
nixos/doc/manual/release-notes/rl-2211.section.md
··· 77 77 - [infnoise](https://github.com/leetronics/infnoise), a hardware True Random Number Generator dongle. 78 78 Available as [services.infnoise](options.html#opt-services.infnoise.enable). 79 79 80 + - [kthxbye](https://github.com/prymitive/kthxbye), an alert acknowledgement management daemon for Prometheus Alertmanager. Available as [services.kthxbye](options.html#opt-services.kthxbye.enable) 81 + 80 82 - [kanata](https://github.com/jtroo/kanata), a tool to improve keyboard comfort and usability with advanced customization. 81 83 Available as [services.kanata](options.html#opt-services.kanata.enable). 82 84
+1
nixos/modules/module-list.nix
··· 681 681 ./services/monitoring/heapster.nix 682 682 ./services/monitoring/incron.nix 683 683 ./services/monitoring/kapacitor.nix 684 + ./services/monitoring/kthxbye.nix 684 685 ./services/monitoring/loki.nix 685 686 ./services/monitoring/longview.nix 686 687 ./services/monitoring/mackerel-agent.nix
+166
nixos/modules/services/monitoring/kthxbye.nix
··· 1 + { config, pkgs, lib, ... }: 2 + with lib; 3 + 4 + let 5 + cfg = config.services.kthxbye; 6 + in 7 + 8 + { 9 + options.services.kthxbye = { 10 + enable = mkEnableOption (mdDoc "kthxbye alert acknowledgement management daemon"); 11 + 12 + package = mkOption { 13 + type = types.package; 14 + default = pkgs.kthxbye; 15 + defaultText = literalExpression "pkgs.kthxbye"; 16 + description = mdDoc '' 17 + The kthxbye package that should be used. 18 + ''; 19 + }; 20 + 21 + openFirewall = mkOption { 22 + type = types.bool; 23 + default = false; 24 + description = mdDoc '' 25 + Whether to open ports in the firewall needed for the daemon to function. 26 + ''; 27 + }; 28 + 29 + extraOptions = mkOption { 30 + type = with types; listOf str; 31 + default = []; 32 + description = mdDoc '' 33 + Extra command line options. 34 + 35 + Documentation can be found [here](https://github.com/prymitive/kthxbye/blob/main/README.md). 36 + ''; 37 + example = literalExpression '' 38 + [ 39 + "-extend-with-prefix 'ACK!'" 40 + ]; 41 + ''; 42 + }; 43 + 44 + alertmanager = { 45 + timeout = mkOption { 46 + type = types.str; 47 + default = "1m0s"; 48 + description = mdDoc '' 49 + Alertmanager request timeout duration in the [time.Duration](https://pkg.go.dev/time#ParseDuration) format. 50 + ''; 51 + example = "30s"; 52 + }; 53 + uri = mkOption { 54 + type = types.str; 55 + default = "http://localhost:9093"; 56 + description = mdDoc '' 57 + Alertmanager URI to use. 58 + ''; 59 + example = "https://alertmanager.example.com"; 60 + }; 61 + }; 62 + 63 + extendBy = mkOption { 64 + type = types.str; 65 + default = "15m0s"; 66 + description = mdDoc '' 67 + Extend silences by adding DURATION seconds. 68 + 69 + DURATION should be provided in the [time.Duration](https://pkg.go.dev/time#ParseDuration) format. 70 + ''; 71 + example = "6h0m0s"; 72 + }; 73 + 74 + extendIfExpiringIn = mkOption { 75 + type = types.str; 76 + default = "5m0s"; 77 + description = mdDoc '' 78 + Extend silences that are about to expire in the next DURATION seconds. 79 + 80 + DURATION should be provided in the [time.Duration](https://pkg.go.dev/time#ParseDuration) format. 81 + ''; 82 + example = "1m0s"; 83 + }; 84 + 85 + extendWithPrefix = mkOption { 86 + type = types.str; 87 + default = "ACK!"; 88 + description = mdDoc '' 89 + Extend silences with comment starting with PREFIX string. 90 + ''; 91 + example = "!perma-silence"; 92 + }; 93 + 94 + interval = mkOption { 95 + type = types.str; 96 + default = "45s"; 97 + description = mdDoc '' 98 + Silence check interval duration in the [time.Duration](https://pkg.go.dev/time#ParseDuration) format. 99 + ''; 100 + example = "30s"; 101 + }; 102 + 103 + listenAddress = mkOption { 104 + type = types.str; 105 + default = "0.0.0.0"; 106 + description = mdDoc '' 107 + The address to listen on for HTTP requests. 108 + ''; 109 + example = "127.0.0.1"; 110 + }; 111 + 112 + port = mkOption { 113 + type = types.port; 114 + default = 8080; 115 + description = mdDoc '' 116 + The port to listen on for HTTP requests. 117 + ''; 118 + }; 119 + 120 + logJSON = mkOption { 121 + type = types.bool; 122 + default = false; 123 + description = mdDoc '' 124 + Format logged messages as JSON. 125 + ''; 126 + }; 127 + 128 + maxDuration = mkOption { 129 + type = with types; nullOr str; 130 + default = null; 131 + description = mdDoc '' 132 + Maximum duration of a silence, it won't be extended anymore after reaching it. 133 + 134 + Duration should be provided in the [time.Duration](https://pkg.go.dev/time#ParseDuration) format. 135 + ''; 136 + example = "30d"; 137 + }; 138 + }; 139 + 140 + config = mkIf cfg.enable { 141 + systemd.services.kthxbye = { 142 + description = "kthxbye Alertmanager ack management daemon"; 143 + wantedBy = [ "multi-user.target" ]; 144 + script = '' 145 + ${cfg.package}/bin/kthxbye \ 146 + -alertmanager.timeout ${cfg.alertmanager.timeout} \ 147 + -alertmanager.uri ${cfg.alertmanager.uri} \ 148 + -extend-by ${cfg.extendBy} \ 149 + -extend-if-expiring-in ${cfg.extendIfExpiringIn} \ 150 + -extend-with-prefix ${cfg.extendWithPrefix} \ 151 + -interval ${cfg.interval} \ 152 + -listen ${cfg.listenAddress}:${toString cfg.port} \ 153 + ${optionalString cfg.logJSON "-log-json"} \ 154 + ${optionalString (cfg.maxDuration != null) "-max-duration ${cfg.maxDuration}"} \ 155 + ${concatStringsSep " " cfg.extraOptions} 156 + ''; 157 + serviceConfig = { 158 + Type = "simple"; 159 + DynamicUser = true; 160 + Restart = "on-failure"; 161 + }; 162 + }; 163 + 164 + networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.port ]; 165 + }; 166 + }
+1
nixos/tests/all-tests.nix
··· 277 277 komga = handleTest ./komga.nix {}; 278 278 krb5 = discoverTests (import ./krb5 {}); 279 279 ksm = handleTest ./ksm.nix {}; 280 + kthxbye = handleTest ./kthxbye.nix {}; 280 281 kubernetes = handleTestOn ["x86_64-linux"] ./kubernetes {}; 281 282 languagetool = handleTest ./languagetool.nix {}; 282 283 latestKernel.login = handleTest ./login.nix { latestKernel = true; };
+110
nixos/tests/kthxbye.nix
··· 1 + import ./make-test-python.nix ({ lib, pkgs, ... }: 2 + { 3 + name = "kthxbye"; 4 + 5 + meta = with lib.maintainers; { 6 + maintainers = [ nukaduka ]; 7 + }; 8 + 9 + nodes.server = { ... }: { 10 + environment.systemPackages = with pkgs; [ prometheus-alertmanager ]; 11 + services.prometheus = { 12 + enable = true; 13 + 14 + globalConfig = { 15 + scrape_interval = "5s"; 16 + scrape_timeout = "5s"; 17 + evaluation_interval = "5s"; 18 + }; 19 + 20 + scrapeConfigs = [ 21 + { 22 + job_name = "prometheus"; 23 + scrape_interval = "5s"; 24 + static_configs = [ 25 + { 26 + targets = [ "localhost:9090" ]; 27 + } 28 + ]; 29 + } 30 + ]; 31 + 32 + rules = [ 33 + '' 34 + groups: 35 + - name: test 36 + rules: 37 + - alert: node_up 38 + expr: up != 0 39 + for: 5s 40 + labels: 41 + severity: bottom of the barrel 42 + annotations: 43 + summary: node is fine 44 + '' 45 + ]; 46 + 47 + alertmanagers = [ 48 + { 49 + static_configs = [ 50 + { 51 + targets = [ 52 + "localhost:9093" 53 + ]; 54 + } 55 + ]; 56 + } 57 + ]; 58 + 59 + alertmanager = { 60 + enable = true; 61 + openFirewall = true; 62 + configuration.route = { 63 + receiver = "test"; 64 + group_wait = "5s"; 65 + group_interval = "5s"; 66 + group_by = [ "..." ]; 67 + }; 68 + configuration.receivers = [ 69 + { 70 + name = "test"; 71 + webhook_configs = [ 72 + { 73 + url = "http://localhost:1234"; 74 + } 75 + ]; 76 + } 77 + ]; 78 + }; 79 + }; 80 + 81 + services.kthxbye = { 82 + enable = true; 83 + openFirewall = true; 84 + extendIfExpiringIn = "30s"; 85 + logJSON = true; 86 + maxDuration = "15m"; 87 + interval = "5s"; 88 + }; 89 + }; 90 + 91 + testScript = '' 92 + with subtest("start the server"): 93 + start_all() 94 + server.wait_for_unit("prometheus.service") 95 + server.wait_for_unit("alertmanager.service") 96 + server.wait_for_unit("kthxbye.service") 97 + 98 + server.sleep(2) # wait for units to settle 99 + server.systemctl("restart kthxbye.service") # make sure kthxbye comes up after alertmanager 100 + server.sleep(2) 101 + 102 + with subtest("set up test silence which expires in 20s"): 103 + server.succeed('amtool --alertmanager.url "http://localhost:9093" silence add alertname="node_up" -a "nixosTest" -d "20s" -c "ACK! this server is fine!!"') 104 + 105 + with subtest("wait for 21 seconds and check if the silence is still active"): 106 + server.sleep(21) 107 + server.systemctl("status kthxbye.service") 108 + server.succeed("amtool --alertmanager.url 'http://localhost:9093' silence | grep 'ACK'") 109 + ''; 110 + })
+39
pkgs/servers/monitoring/prometheus/kthxbye.nix
··· 1 + { pkgs 2 + , lib 3 + , buildGoModule 4 + , fetchFromGitHub 5 + , nixosTests 6 + }: 7 + 8 + buildGoModule rec { 9 + pname = "kthxbye"; 10 + version = "0.15"; 11 + 12 + src = fetchFromGitHub rec { 13 + owner = "prymitive"; 14 + repo = "kthxbye"; 15 + rev = "v${version}"; 16 + hash = "sha256-N1MzutjzLk9MnE1b7dKRsiS7LL4Nb61+NpmjTBPGohI="; 17 + }; 18 + 19 + vendorHash = "sha256-PtINxblqX/wxJyN42mS+hmwMy0lCd6FcQgmBnxTUdcc="; 20 + 21 + buildPhase = '' 22 + make -j$NIX_BUILD_CORES 23 + ''; 24 + 25 + installPhase = '' 26 + install -Dm755 ./kthxbye -t $out/bin 27 + ''; 28 + 29 + passthru.tests = { 30 + kthxbye = nixosTests.kthxbye; 31 + }; 32 + 33 + meta = with lib; { 34 + description = "Prometheus Alertmanager alert acknowledgement management daemon"; 35 + homepage = "https://github.com/prymitive/kthxbye"; 36 + license = licenses.asl20; 37 + maintainers = with maintainers; [ nukaduka ]; 38 + }; 39 + }
+4
pkgs/top-level/all-packages.nix
··· 29277 29277 29278 29278 pinniped = callPackage ../applications/networking/cluster/pinniped { }; 29279 29279 29280 + kthxbye = callPackage ../servers/monitoring/prometheus/kthxbye.nix { 29281 + buildGoModule = buildGo119Module; 29282 + }; 29283 + 29280 29284 pgo-client = callPackage ../applications/networking/cluster/pgo-client { }; 29281 29285 29282 29286 popeye = callPackage ../applications/networking/cluster/popeye { };