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.package = pkgs.elasticsearch-oss;
12 services.elasticsearch.extraConf = ''
13 network.publish_host: 127.0.0.1
14 network.bind_host: 127.0.0.1
15 '';
16
17 services.graylog = {
18 enable = true;
19 passwordSecret = "YGhZ59wXMrYOojx5xdgEpBpDw2N6FbhM4lTtaJ1KPxxmKrUvSlDbtWArwAWMQ5LKx1ojHEVrQrBMVRdXbRyZLqffoUzHfssc";
20 elasticsearchHosts = [ "http://localhost:9200" ];
21
22 # `echo -n "nixos" | shasum -a 256`
23 rootPasswordSha2 = "6ed332bcfa615381511d4d5ba44a293bb476f368f7e9e304f0dff50230d1a85b";
24 };
25
26 environment.systemPackages = [ pkgs.jq ];
27
28 systemd.services.graylog.path = [ pkgs.netcat ];
29 systemd.services.graylog.preStart = ''
30 until nc -z localhost 9200; do
31 sleep 2
32 done
33 '';
34 };
35
36 testScript = let
37 payloads.login = pkgs.writeText "login.json" (builtins.toJSON {
38 host = "127.0.0.1:9000";
39 username = "admin";
40 password = "nixos";
41 });
42
43 payloads.input = pkgs.writeText "input.json" (builtins.toJSON {
44 title = "Demo";
45 global = false;
46 type = "org.graylog2.inputs.gelf.udp.GELFUDPInput";
47 node = "@node@";
48 configuration = {
49 bind_address = "0.0.0.0";
50 decompress_size_limit = 8388608;
51 number_worker_threads = 1;
52 override_source = null;
53 port = 12201;
54 recv_buffer_size = 262144;
55 };
56 });
57
58 payloads.gelf_message = pkgs.writeText "gelf.json" (builtins.toJSON {
59 host = "example.org";
60 short_message = "A short message";
61 full_message = "A long message";
62 version = "1.1";
63 level = 5;
64 facility = "Test";
65 });
66 in ''
67 machine.start()
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/")
71
72 session = machine.succeed(
73 "curl -X POST "
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"
80 ).rstrip()
81
82 machine.succeed(
83 "curl -X POST "
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' "
89 )
90
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"
98 + ')" = "RUNNING"'
99 )
100
101 machine.succeed(
102 "echo -n $(cat ${payloads.gelf_message}) | nc -w10 -u 127.0.0.1 12201"
103 )
104
105 machine.succeed(
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"'
113 )
114 '';
115})