vuls: init at 0.27.0
[NixPkgs.git] / nixos / tests / karma.nix
blob5ac2983b8aa3eede3cddec79ff28a904941487f8
1 import ./make-test-python.nix ({ lib, pkgs, ... }: {
2   name = "karma";
3   nodes = {
4     server = { ... }: {
5       services.prometheus.alertmanager = {
6         enable = true;
7         logLevel = "debug";
8         port = 9093;
9         openFirewall = true;
10         configuration = {
11           global = {
12             resolve_timeout = "1m";
13           };
14           route = {
15             # Root route node
16             receiver = "test";
17             group_by = ["..."];
18             continue = false;
19             group_wait = "1s";
20             group_interval="15s";
21             repeat_interval = "24h";
22           };
23           receivers = [
24             {
25               name = "test";
26               webhook_configs = [
27                 {
28                   url = "http://localhost:1234";
29                   send_resolved = true;
30                   max_alerts = 0;
31                 }
32               ];
33             }
34           ];
35         };
36       };
37       services.karma = {
38         enable = true;
39         openFirewall = true;
40         settings = {
41           listen = {
42             address = "0.0.0.0";
43             port = 8081;
44           };
45           alertmanager = {
46             servers = [
47               {
48                 name = "alertmanager";
49                 uri = "https://127.0.0.1:9093";
50               }
51             ];
52           };
53           karma.name = "test-dashboard";
54           log.config = true;
55           log.requests = true;
56           log.timestamp = true;
57         };
58       };
59     };
60   };
62   testScript = ''
63     start_all()
65     with subtest("Wait for server to come up"):
67       server.wait_for_unit("alertmanager.service")
68       server.wait_for_unit("karma.service")
70       server.sleep(5) # wait for both services to settle
72       server.wait_for_open_port(9093)
73       server.wait_for_open_port(8081)
75     with subtest("Test alertmanager readiness"):
76       server.succeed("curl -s http://127.0.0.1:9093/-/ready")
78       # Karma only starts serving the dashboard once it has established connectivity to all alertmanagers in its config
79       # Therefore, this will fail if karma isn't able to reach alertmanager
80       server.succeed("curl -s http://127.0.0.1:8081")
82     server.shutdown()
83   '';