diff --git a/nix/grafana_test.nix b/nix/grafana_test.nix index 9d0cb725..e635214c 100644 --- a/nix/grafana_test.nix +++ b/nix/grafana_test.nix @@ -1,4 +1,49 @@ -{ pkgs, config, ... }: { +{ pkgs, config, ... }: +let + dashboardUid = "adnyzrfa5cqv4c" + dashboardTitle = "Test dashboard" + dashboardJson = pkgs.writeText "test_dashboard.json" '' + { + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "grafana", + "uid": "-- Grafana --" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": 3, + "links": [], + "panels": [], + "schemaVersion": 39, + "tags": [], + "templating": { + "list": [] + }, + "time": { + "from": "now-6h", + "to": "now" + }, + "timepicker": {}, + "timezone": "browser", + "title": "${dashboardTitle}", + "uid": "${dashboardUid}", + "version": 1, + "weekStart": "" + } + '' +in { services.grafana."gf1" = { enable = true; @@ -7,6 +52,15 @@ security.admin_user = "patato"; security.admin_password = "potato"; }; + providers = [ + { + name = "Test dashboard provider"; + type = "file"; + options = { + path = builtins.dirOf dashboardJson; + }; + } + ]; }; settings.processes.test = @@ -22,8 +76,12 @@ ADMIN=${cfg.extraConf.security.admin_user} PASSWORD=${cfg.extraConf.security.admin_password} ROOT_URL="${cfg.protocol}://${cfg.domain}:${builtins.toString cfg.http_port}"; + # The admin user can authenticate against the running service. curl -sSfN -u $ADMIN:$PASSWORD $ROOT_URL/api/org/users -i curl -sSfN -u $ADMIN:$PASSWORD $ROOT_URL/api/org/users | grep admin\@localhost + # The dashboard provisioner was used to create a dashboard. + curl -sSfN -u $ADMIN:$PASSWORD $ROOT_URL/api/org/dashboards/uid/${dashboardUid} -i + curl -sSfN -u $ADMIN:$PASSWORD $ROOT_URL/api/org/dashboards/uid/${dashboardUid} | grep '"title":${dashboardTitle}' ''; name = "grafana-test"; };