1 import ./make-test-python.nix ({ pkgs, lib, ... }:
4 api_token = "f87f42114e44b63ad1b9e3c3d33d6fbe"; # random md5 hash
5 wrong_api_token = "e68ba041fcf1eab923a7a6de3af5f726"; # another random md5 hash
9 meta.maintainers = lib.teams.wdz.members;
12 time.timeZone = "Europe/Berlin";
14 environment.systemPackages = with pkgs; [
21 hostname = "librenms";
25 database = "librenms";
26 username = "librenms";
27 passwordFile = pkgs.writeText "librenms-db-pass" "librenmsdbpass";
32 enableOneMinutePolling = true;
34 enable_billing = true;
38 # systemd oneshot to create a dummy admin user and a API token for testing
39 systemd.services.lnms-api-init = {
40 description = "LibreNMS API init";
41 after = [ "librenms-setup.service" ];
42 wantedBy = [ "multi-user.target" ];
45 RemainAfterExit = true;
51 API_TOKEN=${api_token} # random md5 hash
53 # seeding database to get the admin roles
54 ${pkgs.librenms}/artisan db:seed --force --no-interaction
56 # we don't need to know the password, it just has to exist
57 API_USER_PASS=$(${pkgs.pwgen}/bin/pwgen -s 64 1)
58 ${pkgs.librenms}/artisan user:add $API_USER_NAME -r admin -p $API_USER_PASS
59 API_USER_ID=$(${pkgs.mariadb}/bin/mysql -D librenms -N -B -e "SELECT user_id FROM users WHERE username = '$API_USER_NAME';")
61 ${pkgs.mariadb}/bin/mysql -D librenms -e "INSERT INTO api_tokens (user_id, token_hash, description) VALUES ($API_USER_ID, '$API_TOKEN', 'API User')"
73 com2sec readonly default public
75 group MyROGroup v2c readonly
76 view all included .1 80
77 access MyROGroup "" any noauth exact all none none
79 syslocation Testcity, Testcountry
80 syscontact Testi mc Test <test@example.com>
89 snmphost.wait_for_unit("snmpd.service")
91 librenms.wait_for_unit("lnms-api-init.service")
92 librenms.wait_for_open_port(80)
94 # Test that we can authenticate against the API
95 librenms.succeed("curl --fail -H 'X-Auth-Token: ${api_token}' http://localhost/api/v0")
96 librenms.fail("curl --fail -H 'X-Auth-Token: ${wrong_api_token}' http://localhost/api/v0")
98 # add snmphost as a device
99 librenms.succeed("curl --fail -X POST -d '{\"hostname\":\"snmphost\",\"version\":\"v2c\",\"community\":\"public\"}' -H 'X-Auth-Token: ${api_token}' http://localhost/api/v0/devices")
101 # wait until snmphost gets polled
102 librenms.wait_until_succeeds("test $(curl -H 'X-Auth-Token: ${api_token}' http://localhost/api/v0/devices/snmphost | jq -Mr .devices[0].last_polled) != 'null'")