at 23.11-pre 3.6 kB view raw
1import ./make-test-python.nix ({ pkgs, lib, ... }: { 2 name = "graylog"; 3 meta.maintainers = with lib.maintainers; [ ]; 4 5 nodes.machine = { pkgs, ... }: { 6 virtualisation.memorySize = 4096; 7 virtualisation.diskSize = 4096; 8 9 services.mongodb.enable = true; 10 services.elasticsearch.enable = true; 11 services.elasticsearch.extraConf = '' 12 network.publish_host: 127.0.0.1 13 network.bind_host: 127.0.0.1 14 ''; 15 16 services.graylog = { 17 enable = true; 18 passwordSecret = "YGhZ59wXMrYOojx5xdgEpBpDw2N6FbhM4lTtaJ1KPxxmKrUvSlDbtWArwAWMQ5LKx1ojHEVrQrBMVRdXbRyZLqffoUzHfssc"; 19 elasticsearchHosts = [ "http://localhost:9200" ]; 20 21 # `echo -n "nixos" | shasum -a 256` 22 rootPasswordSha2 = "6ed332bcfa615381511d4d5ba44a293bb476f368f7e9e304f0dff50230d1a85b"; 23 }; 24 25 environment.systemPackages = [ pkgs.jq ]; 26 27 systemd.services.graylog.path = [ pkgs.netcat ]; 28 systemd.services.graylog.preStart = '' 29 until nc -z localhost 9200; do 30 sleep 2 31 done 32 ''; 33 }; 34 35 testScript = let 36 payloads.login = pkgs.writeText "login.json" (builtins.toJSON { 37 host = "127.0.0.1:9000"; 38 username = "admin"; 39 password = "nixos"; 40 }); 41 42 payloads.input = pkgs.writeText "input.json" (builtins.toJSON { 43 title = "Demo"; 44 global = false; 45 type = "org.graylog2.inputs.gelf.udp.GELFUDPInput"; 46 node = "@node@"; 47 configuration = { 48 bind_address = "0.0.0.0"; 49 decompress_size_limit = 8388608; 50 number_worker_threads = 1; 51 override_source = null; 52 port = 12201; 53 recv_buffer_size = 262144; 54 }; 55 }); 56 57 payloads.gelf_message = pkgs.writeText "gelf.json" (builtins.toJSON { 58 host = "example.org"; 59 short_message = "A short message"; 60 full_message = "A long message"; 61 version = "1.1"; 62 level = 5; 63 facility = "Test"; 64 }); 65 in '' 66 machine.start() 67 machine.wait_for_unit("graylog.service") 68 machine.wait_for_open_port(9000) 69 machine.succeed("curl -sSfL http://127.0.0.1:9000/") 70 71 session = machine.succeed( 72 "curl -X POST " 73 + "-sSfL http://127.0.0.1:9000/api/system/sessions " 74 + "-d $(cat ${payloads.login}) " 75 + "-H 'Content-Type: application/json' " 76 + "-H 'Accept: application/json' " 77 + "-H 'x-requested-by: cli' " 78 + "| jq .session_id | xargs echo" 79 ).rstrip() 80 81 machine.succeed( 82 "curl -X POST " 83 + f"-sSfL http://127.0.0.1:9000/api/system/inputs -u {session}:session " 84 + '-d $(cat ${payloads.input} | sed -e "s,@node@,$(cat /var/lib/graylog/server/node-id),") ' 85 + "-H 'Accept: application/json' " 86 + "-H 'Content-Type: application/json' " 87 + "-H 'x-requested-by: cli' " 88 ) 89 90 machine.wait_until_succeeds( 91 "test \"$(curl -sSfL 'http://127.0.0.1:9000/api/cluster/inputstates' " 92 + f"-u {session}:session " 93 + "-H 'Accept: application/json' " 94 + "-H 'Content-Type: application/json' " 95 + "-H 'x-requested-by: cli'" 96 + "| jq 'to_entries[]|.value|.[0]|.state' | xargs echo" 97 + ')" = "RUNNING"' 98 ) 99 100 machine.succeed( 101 "echo -n $(cat ${payloads.gelf_message}) | nc -w10 -u 127.0.0.1 12201" 102 ) 103 104 machine.succeed( 105 'test "$(curl -X GET ' 106 + "-sSfL 'http://127.0.0.1:9000/api/search/universal/relative?query=*' " 107 + f"-u {session}:session " 108 + "-H 'Accept: application/json' " 109 + "-H 'Content-Type: application/json' " 110 + "-H 'x-requested-by: cli'" 111 + ' | jq \'.total_results\' | xargs echo)" = "1"' 112 ) 113 ''; 114})