about summary refs log tree commit diff
path: root/nixos/tests/grafana/provision-notifiers.nix
blob: 2419a458c004d31515c878d70f2d4ab5869d2974 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
args@{ pkgs, ... }:

(import ../make-test-python.nix ({ lib, pkgs, ... }:

let
  inherit (lib) mkMerge nameValuePair maintainers;

  baseGrafanaConf = {
    services.grafana = {
      enable = true;
      addr = "localhost";
      analytics.reporting.enable = false;
      domain = "localhost";
      security = {
        adminUser = "testadmin";
        adminPassword = "snakeoilpwd";
      };
      provision.enable = true;
    };
  };

  extraNodeConfs = {
    provisionNotifiers = {
      services.grafana.provision = {
        notifiers = [{
          uid = "test_notifiers";
          name = "Test Notifiers";
          type = "email";
          settings = {
            singleEmail = true;
            addresses = "test@test.com";
          };
        }];
      };
    };
  };

  nodes = builtins.listToAttrs (map (provisionType:
    nameValuePair provisionType (mkMerge [
    baseGrafanaConf
    (extraNodeConfs.${provisionType} or {})
  ])) [ "provisionNotifiers" ]);

in {
  name = "grafana-provision-notifiers";

  meta = with maintainers; {
    maintainers = [ kfears willibutz ];
  };

  inherit nodes;

  testScript = ''
    start_all()
    with subtest("Successful notifiers provision with Nix"):
        provisionNotifiers.wait_for_unit("grafana.service")
        provisionNotifiers.wait_for_open_port(3000)
        provisionNotifiers.succeed(
            "curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1:3000/api/alert-notifications/uid/test_notifiers | grep Test\ Notifiers"
        )
        provisionNotifiers.shutdown()
  '';
})) args