1 import ../../make-test-python.nix (
5 inherit (lib) mkMerge maintainers;
10 provision.enable = true;
12 analytics.reporting_enabled = false;
20 admin_user = "testadmin";
21 admin_password = "$__file{${pkgs.writeText "pwd" "snakeoilpwd"}}";
26 systemd.tmpfiles.rules =
28 dashboard = pkgs.writeText "test.json" (builtins.readFile ./test_dashboard.json);
31 "d /var/lib/grafana/dashboards 0700 grafana grafana -"
32 "C+ /var/lib/grafana/dashboards/test.json - - - - ${dashboard}"
38 services.grafana.provision = {
39 datasources.settings = {
43 name = "Test Datasource";
46 uid = "test_datasource";
51 dashboards.settings = {
56 options.path = "/var/lib/grafana/dashboards";
65 name = "test_rule_group";
66 folder = "test_folder";
76 datasourceUid = "-100";
84 operator.type = "and";
85 query.params = [ "A" ];
86 reducer.type = "last";
96 maxDataPoints = 43200;
109 contactPoints.settings = {
112 name = "Test Contact Point";
115 uid = "test_contact_point";
116 type = "prometheus-alertmanager";
117 settings.url = "http://localhost:9000";
124 policies.settings = {
127 receiver = "Test Contact Point";
132 templates.settings = {
135 name = "Test Template";
136 template = "Test message";
141 muteTimings.settings = {
144 name = "Test Mute Timing";
153 services.grafana.provision = {
154 datasources.path = ./datasources.yaml;
155 dashboards.path = ./dashboards.yaml;
157 rules.path = ./rules.yaml;
158 contactPoints.path = ./contact-points.yaml;
159 policies.path = ./policies.yaml;
160 templates.path = ./templates.yaml;
161 muteTimings.path = ./mute-timings.yaml;
168 mkdir = p: pkgs.writeTextDir (baseNameOf p) (builtins.readFile p);
171 services.grafana.provision = {
172 datasources.path = mkdir ./datasources.yaml;
173 dashboards.path = mkdir ./dashboards.yaml;
175 rules.path = mkdir ./rules.yaml;
176 contactPoints.path = mkdir ./contact-points.yaml;
177 policies.path = mkdir ./policies.yaml;
178 templates.path = mkdir ./templates.yaml;
179 muteTimings.path = mkdir ./mute-timings.yaml;
185 nodes = builtins.mapAttrs (
194 name = "grafana-provision";
196 meta = with maintainers; {
197 maintainers = [ willibutz ];
205 nodeNix = ("Nix (new format)", provisionNix)
206 nodeYaml = ("Nix (YAML)", provisionYaml)
207 nodeYamlDir = ("Nix (YAML in dirs)", provisionYamlDirs)
209 for description, machine in [nodeNix, nodeYaml, nodeYamlDir]:
210 with subtest(f"Should start provision node: {description}"):
211 machine.wait_for_unit("grafana.service")
212 machine.wait_for_open_port(3000, addr="::1")
214 with subtest(f"Successful datasource provision with {description}"):
216 "curl -sSfN -u testadmin:snakeoilpwd http://[::1]:3000/api/datasources/uid/test_datasource | grep Test\ Datasource"
219 with subtest(f"Successful dashboard provision with {description}"):
221 "curl -sSfN -u testadmin:snakeoilpwd http://[::1]:3000/api/dashboards/uid/test_dashboard | grep Test\ Dashboard"
224 with subtest(f"Successful rule provision with {description}"):
226 "curl -sSfN -u testadmin:snakeoilpwd http://[::1]:3000/api/v1/provisioning/alert-rules/test_rule | grep Test\ Rule"
229 with subtest(f"Successful contact point provision with {description}"):
231 "curl -sSfN -u testadmin:snakeoilpwd http://[::1]:3000/api/v1/provisioning/contact-points | grep Test\ Contact\ Point"
234 with subtest(f"Successful policy provision with {description}"):
236 "curl -sSfN -u testadmin:snakeoilpwd http://[::1]:3000/api/v1/provisioning/policies | grep Test\ Contact\ Point"
239 with subtest(f"Successful template provision with {description}"):
241 "curl -sSfN -u testadmin:snakeoilpwd http://[::1]:3000/api/v1/provisioning/templates | grep Test\ Template"
244 with subtest("Successful mute timings provision with {description}"):
246 "curl -sSfN -u testadmin:snakeoilpwd http://[::1]:3000/api/v1/provisioning/mute-timings | grep Test\ Mute\ Timing"