2022-10-23 12:08:45 +01:00
|
|
|
import ../make-test-python.nix ({ lib, pkgs, ... }:
|
2017-09-18 15:59:50 +01:00
|
|
|
|
2019-07-15 15:41:55 +01:00
|
|
|
let
|
|
|
|
inherit (lib) mkMerge nameValuePair maintainers;
|
2017-09-18 15:59:50 +01:00
|
|
|
|
2019-07-15 15:41:55 +01:00
|
|
|
baseGrafanaConf = {
|
2017-09-18 15:59:50 +01:00
|
|
|
services.grafana = {
|
|
|
|
enable = true;
|
2022-10-24 16:31:50 +01:00
|
|
|
settings = {
|
|
|
|
analytics.reporting_enabled = false;
|
|
|
|
|
|
|
|
server = {
|
|
|
|
http_addr = "localhost";
|
|
|
|
domain = "localhost";
|
|
|
|
};
|
|
|
|
|
|
|
|
security = {
|
|
|
|
admin_user = "testadmin";
|
|
|
|
admin_password = "snakeoilpwd";
|
|
|
|
};
|
2019-07-15 15:41:55 +01:00
|
|
|
};
|
2017-09-18 15:59:50 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-07-15 15:41:55 +01:00
|
|
|
extraNodeConfs = {
|
2022-10-15 18:42:48 +01:00
|
|
|
sqlite = {};
|
|
|
|
|
2022-12-14 12:57:51 +00:00
|
|
|
socket = { config, ... }: {
|
|
|
|
services.grafana.settings.server = {
|
|
|
|
protocol = "socket";
|
|
|
|
socket = "/run/grafana/sock";
|
|
|
|
socket_gid = config.users.groups.nginx.gid;
|
|
|
|
};
|
|
|
|
|
|
|
|
users.users.grafana.extraGroups = [ "nginx" ];
|
|
|
|
|
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
|
|
|
recommendedProxySettings = true;
|
|
|
|
virtualHosts."_".locations."/".proxyPass = "http://unix:/run/grafana/sock";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-12-30 17:59:52 +00:00
|
|
|
declarativePlugins = {
|
|
|
|
services.grafana.declarativePlugins = [ pkgs.grafanaPlugins.grafana-clock-panel ];
|
|
|
|
};
|
|
|
|
|
2019-07-15 15:41:55 +01:00
|
|
|
postgresql = {
|
2022-10-24 16:31:50 +01:00
|
|
|
services.grafana.settings.database = {
|
2019-07-15 15:41:55 +01:00
|
|
|
host = "127.0.0.1:5432";
|
|
|
|
user = "grafana";
|
|
|
|
};
|
|
|
|
services.postgresql = {
|
|
|
|
enable = true;
|
|
|
|
ensureDatabases = [ "grafana" ];
|
|
|
|
ensureUsers = [{
|
|
|
|
name = "grafana";
|
|
|
|
ensurePermissions."DATABASE grafana" = "ALL PRIVILEGES";
|
|
|
|
}];
|
|
|
|
};
|
|
|
|
systemd.services.grafana.after = [ "postgresql.service" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
mysql = {
|
2022-10-24 16:31:50 +01:00
|
|
|
services.grafana.settings.database.user = "grafana";
|
2019-07-15 15:41:55 +01:00
|
|
|
services.mysql = {
|
|
|
|
enable = true;
|
|
|
|
ensureDatabases = [ "grafana" ];
|
|
|
|
ensureUsers = [{
|
|
|
|
name = "grafana";
|
|
|
|
ensurePermissions."grafana.*" = "ALL PRIVILEGES";
|
|
|
|
}];
|
|
|
|
package = pkgs.mariadb;
|
|
|
|
};
|
|
|
|
systemd.services.grafana.after = [ "mysql.service" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-10-15 18:42:48 +01:00
|
|
|
nodes = builtins.mapAttrs (_: val: mkMerge [ val baseGrafanaConf ]) extraNodeConfs;
|
2019-07-15 15:41:55 +01:00
|
|
|
in {
|
2022-09-18 10:35:07 +01:00
|
|
|
name = "grafana-basic";
|
2019-07-15 15:41:55 +01:00
|
|
|
|
|
|
|
meta = with maintainers; {
|
|
|
|
maintainers = [ willibutz ];
|
|
|
|
};
|
|
|
|
|
|
|
|
inherit nodes;
|
|
|
|
|
2017-09-18 15:59:50 +01:00
|
|
|
testScript = ''
|
2019-11-06 15:50:33 +00:00
|
|
|
start_all()
|
2019-07-15 15:41:55 +01:00
|
|
|
|
2020-12-30 17:59:52 +00:00
|
|
|
with subtest("Declarative plugins installed"):
|
|
|
|
declarativePlugins.wait_for_unit("grafana.service")
|
|
|
|
declarativePlugins.wait_for_open_port(3000)
|
|
|
|
declarativePlugins.succeed(
|
2021-06-05 14:50:58 +01:00
|
|
|
"curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1:3000/api/plugins | grep grafana-clock-panel"
|
2020-12-30 17:59:52 +00:00
|
|
|
)
|
|
|
|
declarativePlugins.shutdown()
|
|
|
|
|
2019-11-06 15:50:33 +00:00
|
|
|
with subtest("Successful API query as admin user with sqlite db"):
|
|
|
|
sqlite.wait_for_unit("grafana.service")
|
|
|
|
sqlite.wait_for_open_port(3000)
|
2022-10-12 19:45:15 +01:00
|
|
|
print(sqlite.succeed(
|
|
|
|
"curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1:3000/api/org/users -i"
|
|
|
|
))
|
2019-11-06 15:50:33 +00:00
|
|
|
sqlite.succeed(
|
2022-10-12 19:45:15 +01:00
|
|
|
"curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1:3000/api/org/users | grep admin\@localhost"
|
2019-11-06 15:50:33 +00:00
|
|
|
)
|
|
|
|
sqlite.shutdown()
|
2019-07-15 15:41:55 +01:00
|
|
|
|
2022-12-14 12:57:51 +00:00
|
|
|
with subtest("Successful API query as admin user with sqlite db listening on socket"):
|
|
|
|
socket.wait_for_unit("grafana.service")
|
|
|
|
socket.wait_for_open_port(80)
|
|
|
|
print(socket.succeed(
|
|
|
|
"curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1/api/org/users -i"
|
|
|
|
))
|
|
|
|
socket.succeed(
|
|
|
|
"curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1/api/org/users | grep admin\@localhost"
|
|
|
|
)
|
|
|
|
socket.shutdown()
|
|
|
|
|
2019-11-06 15:50:33 +00:00
|
|
|
with subtest("Successful API query as admin user with postgresql db"):
|
|
|
|
postgresql.wait_for_unit("grafana.service")
|
|
|
|
postgresql.wait_for_unit("postgresql.service")
|
|
|
|
postgresql.wait_for_open_port(3000)
|
|
|
|
postgresql.wait_for_open_port(5432)
|
|
|
|
postgresql.succeed(
|
2022-10-12 19:45:15 +01:00
|
|
|
"curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1:3000/api/org/users | grep admin\@localhost"
|
2019-11-06 15:50:33 +00:00
|
|
|
)
|
|
|
|
postgresql.shutdown()
|
2019-07-15 15:41:55 +01:00
|
|
|
|
2019-11-06 15:50:33 +00:00
|
|
|
with subtest("Successful API query as admin user with mysql db"):
|
|
|
|
mysql.wait_for_unit("grafana.service")
|
|
|
|
mysql.wait_for_unit("mysql.service")
|
|
|
|
mysql.wait_for_open_port(3000)
|
|
|
|
mysql.wait_for_open_port(3306)
|
|
|
|
mysql.succeed(
|
2022-10-12 19:45:15 +01:00
|
|
|
"curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1:3000/api/org/users | grep admin\@localhost"
|
2019-11-06 15:50:33 +00:00
|
|
|
)
|
|
|
|
mysql.shutdown()
|
2017-09-18 15:59:50 +01:00
|
|
|
'';
|
2022-10-23 12:08:45 +01:00
|
|
|
})
|