mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-12-27 08:04:14 +00:00
4f0dadbf38
After final improvements to the official formatter implementation, this commit now performs the first treewide reformat of Nix files using it. This is part of the implementation of RFC 166. Only "inactive" files are reformatted, meaning only files that aren't being touched by any PR with activity in the past 2 months. This is to avoid conflicts for PRs that might soon be merged. Later we can do a full treewide reformat to get the rest, which should not cause as many conflicts. A CI check has already been running for some time to ensure that new and already-formatted files are formatted, so the files being reformatted here should also stay formatted. This commit was automatically created and can be verified using nix-builda08b3a4d19
.tar.gz \ --argstr baseRevb32a094368
result/bin/apply-formatting $NIXPKGS_PATH
107 lines
3.4 KiB
Nix
107 lines
3.4 KiB
Nix
import ./make-test-python.nix (
|
|
{ pkgs, lib, ... }:
|
|
|
|
let
|
|
api_token = "f87f42114e44b63ad1b9e3c3d33d6fbe"; # random md5 hash
|
|
wrong_api_token = "e68ba041fcf1eab923a7a6de3af5f726"; # another random md5 hash
|
|
in
|
|
{
|
|
name = "librenms";
|
|
meta.maintainers = lib.teams.wdz.members;
|
|
|
|
nodes.librenms = {
|
|
time.timeZone = "Europe/Berlin";
|
|
|
|
environment.systemPackages = with pkgs; [
|
|
curl
|
|
jq
|
|
];
|
|
|
|
services.librenms = {
|
|
enable = true;
|
|
hostname = "librenms";
|
|
database = {
|
|
createLocally = true;
|
|
host = "localhost";
|
|
database = "librenms";
|
|
username = "librenms";
|
|
passwordFile = pkgs.writeText "librenms-db-pass" "librenmsdbpass";
|
|
};
|
|
nginx = {
|
|
default = true;
|
|
};
|
|
enableOneMinutePolling = true;
|
|
settings = {
|
|
enable_billing = true;
|
|
};
|
|
};
|
|
|
|
# systemd oneshot to create a dummy admin user and a API token for testing
|
|
systemd.services.lnms-api-init = {
|
|
description = "LibreNMS API init";
|
|
after = [ "librenms-setup.service" ];
|
|
wantedBy = [ "multi-user.target" ];
|
|
serviceConfig = {
|
|
Type = "oneshot";
|
|
RemainAfterExit = true;
|
|
User = "root";
|
|
Group = "root";
|
|
};
|
|
script = ''
|
|
API_USER_NAME=api
|
|
API_TOKEN=${api_token} # random md5 hash
|
|
|
|
# seeding database to get the admin roles
|
|
${pkgs.librenms}/artisan db:seed --force --no-interaction
|
|
|
|
# we don't need to know the password, it just has to exist
|
|
API_USER_PASS=$(${pkgs.pwgen}/bin/pwgen -s 64 1)
|
|
${pkgs.librenms}/artisan user:add $API_USER_NAME -r admin -p $API_USER_PASS
|
|
API_USER_ID=$(${pkgs.mariadb}/bin/mysql -D librenms -N -B -e "SELECT user_id FROM users WHERE username = '$API_USER_NAME';")
|
|
|
|
${pkgs.mariadb}/bin/mysql -D librenms -e "INSERT INTO api_tokens (user_id, token_hash, description) VALUES ($API_USER_ID, '$API_TOKEN', 'API User')"
|
|
'';
|
|
};
|
|
};
|
|
|
|
nodes.snmphost = {
|
|
|
|
services.snmpd = {
|
|
enable = true;
|
|
openFirewall = true;
|
|
|
|
configText = ''
|
|
com2sec readonly default public
|
|
|
|
group MyROGroup v2c readonly
|
|
view all included .1 80
|
|
access MyROGroup "" any noauth exact all none none
|
|
|
|
syslocation Testcity, Testcountry
|
|
syscontact Testi mc Test <test@example.com>
|
|
'';
|
|
|
|
};
|
|
};
|
|
|
|
testScript = ''
|
|
start_all()
|
|
|
|
snmphost.wait_for_unit("snmpd.service")
|
|
|
|
librenms.wait_for_unit("lnms-api-init.service")
|
|
librenms.wait_for_open_port(80)
|
|
|
|
# Test that we can authenticate against the API
|
|
librenms.succeed("curl --fail -H 'X-Auth-Token: ${api_token}' http://localhost/api/v0")
|
|
librenms.fail("curl --fail -H 'X-Auth-Token: ${wrong_api_token}' http://localhost/api/v0")
|
|
|
|
# add snmphost as a device
|
|
librenms.succeed("curl --fail -X POST -d '{\"hostname\":\"snmphost\",\"version\":\"v2c\",\"community\":\"public\"}' -H 'X-Auth-Token: ${api_token}' http://localhost/api/v0/devices")
|
|
|
|
# wait until snmphost gets polled
|
|
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'")
|
|
'';
|
|
}
|
|
)
|