1 import ./make-test-python.nix ({ pkgs, lib, ... }: {
3 meta.maintainers = [ ];
5 nodes.machine = { pkgs, ... }: {
6 virtualisation.memorySize = 4096;
7 virtualisation.diskSize = 1024 * 6;
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")
69 machine.wait_until_succeeds(
70 "journalctl -o cat -u graylog.service | grep 'Started REST API at <127.0.0.1:9000>'"
73 machine.wait_for_open_port(9000)
74 machine.succeed("curl -sSfL http://127.0.0.1:9000/")
76 machine.wait_until_succeeds(
77 "journalctl -o cat -u graylog.service | grep 'Graylog server up and running'"
80 session = machine.succeed(
82 + "-sSfL http://127.0.0.1:9000/api/system/sessions "
83 + "-d $(cat ${payloads.login}) "
84 + "-H 'Content-Type: application/json' "
85 + "-H 'Accept: application/json' "
86 + "-H 'x-requested-by: cli' "
87 + "| jq .session_id | xargs echo"
92 + f"-sSfL http://127.0.0.1:9000/api/system/inputs -u {session}:session "
93 + '-d $(cat ${payloads.input} | sed -e "s,@node@,$(cat /var/lib/graylog/server/node-id),") '
94 + "-H 'Accept: application/json' "
95 + "-H 'Content-Type: application/json' "
96 + "-H 'x-requested-by: cli' "
99 machine.wait_until_succeeds(
100 "journalctl -o cat -u graylog.service | grep -E 'Input \[GELF UDP/Demo/[[:alnum:]]{24}\] is now RUNNING'"
103 machine.wait_until_succeeds(
104 "test \"$(curl -sSfL 'http://127.0.0.1:9000/api/cluster/inputstates' "
105 + f"-u {session}:session "
106 + "-H 'Accept: application/json' "
107 + "-H 'Content-Type: application/json' "
108 + "-H 'x-requested-by: cli'"
109 + "| jq 'to_entries[]|.value|.[0]|.state' | xargs echo"
114 "echo -n $(cat ${payloads.gelf_message}) | nc -w10 -u 127.0.0.1 12201"
118 'test "$(curl -X GET '
119 + "-sSfL 'http://127.0.0.1:9000/api/search/universal/relative?query=*' "
120 + f"-u {session}:session "
121 + "-H 'Accept: application/json' "
122 + "-H 'Content-Type: application/json' "
123 + "-H 'x-requested-by: cli'"
124 + ' | jq \'.total_results\' | xargs echo)" = "1"'