1 import ./make-test-python.nix ({ pkgs, lib, ... }: {
3 meta.maintainers = with lib.maintainers; [ ];
5 nodes.machine = { pkgs, ... }: {
6 virtualisation.memorySize = 4096;
7 virtualisation.diskSize = 4096;
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
18 passwordSecret = "YGhZ59wXMrYOojx5xdgEpBpDw2N6FbhM4lTtaJ1KPxxmKrUvSlDbtWArwAWMQ5LKx1ojHEVrQrBMVRdXbRyZLqffoUzHfssc";
19 elasticsearchHosts = [ "http://localhost:9200" ];
21 # `echo -n "nixos" | shasum -a 256`
22 rootPasswordSha2 = "6ed332bcfa615381511d4d5ba44a293bb476f368f7e9e304f0dff50230d1a85b";
25 environment.systemPackages = [ pkgs.jq ];
27 systemd.services.graylog.path = [ pkgs.netcat ];
28 systemd.services.graylog.preStart = ''
29 until nc -z localhost 9200; do
36 payloads.login = pkgs.writeText "login.json" (builtins.toJSON {
37 host = "127.0.0.1:9000";
42 payloads.input = pkgs.writeText "input.json" (builtins.toJSON {
45 type = "org.graylog2.inputs.gelf.udp.GELFUDPInput";
48 bind_address = "0.0.0.0";
49 decompress_size_limit = 8388608;
50 number_worker_threads = 1;
51 override_source = null;
53 recv_buffer_size = 262144;
57 payloads.gelf_message = pkgs.writeText "gelf.json" (builtins.toJSON {
59 short_message = "A short message";
60 full_message = "A long message";
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/")
71 session = machine.succeed(
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"
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' "
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"
101 "echo -n $(cat ${payloads.gelf_message}) | nc -w10 -u 127.0.0.1 12201"
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"'