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.package = pkgs.elasticsearch-oss;
12 services.elasticsearch.extraConf = ''
13 network.publish_host: 127.0.0.1
14 network.bind_host: 127.0.0.1
19 passwordSecret = "YGhZ59wXMrYOojx5xdgEpBpDw2N6FbhM4lTtaJ1KPxxmKrUvSlDbtWArwAWMQ5LKx1ojHEVrQrBMVRdXbRyZLqffoUzHfssc";
20 elasticsearchHosts = [ "http://localhost:9200" ];
22 # `echo -n "nixos" | shasum -a 256`
23 rootPasswordSha2 = "6ed332bcfa615381511d4d5ba44a293bb476f368f7e9e304f0dff50230d1a85b";
26 environment.systemPackages = [ pkgs.jq ];
28 systemd.services.graylog.path = [ pkgs.netcat ];
29 systemd.services.graylog.preStart = ''
30 until nc -z localhost 9200; do
37 payloads.login = pkgs.writeText "login.json" (builtins.toJSON {
38 host = "127.0.0.1:9000";
43 payloads.input = pkgs.writeText "input.json" (builtins.toJSON {
46 type = "org.graylog2.inputs.gelf.udp.GELFUDPInput";
49 bind_address = "0.0.0.0";
50 decompress_size_limit = 8388608;
51 number_worker_threads = 1;
52 override_source = null;
54 recv_buffer_size = 262144;
58 payloads.gelf_message = pkgs.writeText "gelf.json" (builtins.toJSON {
60 short_message = "A short message";
61 full_message = "A long message";
68 machine.wait_for_unit("graylog.service")
69 machine.wait_for_open_port(9000)
70 machine.succeed("curl -sSfL http://127.0.0.1:9000/")
72 session = machine.succeed(
74 + "-sSfL http://127.0.0.1:9000/api/system/sessions "
75 + "-d $(cat ${payloads.login}) "
76 + "-H 'Content-Type: application/json' "
77 + "-H 'Accept: application/json' "
78 + "-H 'x-requested-by: cli' "
79 + "| jq .session_id | xargs echo"
84 + f"-sSfL http://127.0.0.1:9000/api/system/inputs -u {session}:session "
85 + '-d $(cat ${payloads.input} | sed -e "s,@node@,$(cat /var/lib/graylog/server/node-id),") '
86 + "-H 'Accept: application/json' "
87 + "-H 'Content-Type: application/json' "
88 + "-H 'x-requested-by: cli' "
91 machine.wait_until_succeeds(
92 "test \"$(curl -sSfL 'http://127.0.0.1:9000/api/cluster/inputstates' "
93 + f"-u {session}:session "
94 + "-H 'Accept: application/json' "
95 + "-H 'Content-Type: application/json' "
96 + "-H 'x-requested-by: cli'"
97 + "| jq 'to_entries[]|.value|.[0]|.state' | xargs echo"
102 "echo -n $(cat ${payloads.gelf_message}) | nc -w10 -u 127.0.0.1 12201"
106 'test "$(curl -X GET '
107 + "-sSfL 'http://127.0.0.1:9000/api/search/universal/relative?query=*' "
108 + f"-u {session}:session "
109 + "-H 'Accept: application/json' "
110 + "-H 'Content-Type: application/json' "
111 + "-H 'x-requested-by: cli'"
112 + ' | jq \'.total_results\' | xargs echo)" = "1"'