Merge pull request #64463 from Ma27/graylog-test

nixos/graylog: minor fixes, add test
This commit is contained in:
Franz Pletz 2019-07-21 20:53:39 +00:00 committed by GitHub
commit 376b5fd000
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 122 additions and 20 deletions

View file

@ -150,6 +150,9 @@ in
rm -rf /var/lib/graylog/plugins || true
mkdir -p /var/lib/graylog/plugins -m 755
mkdir -p "$(dirname ${cfg.nodeIdFile})"
chown -R ${cfg.user} "$(dirname ${cfg.nodeIdFile})"
for declarativeplugin in `ls ${glPlugins}/bin/`; do
ln -sf ${glPlugins}/bin/$declarativeplugin /var/lib/graylog/plugins/$declarativeplugin
done

View file

@ -100,6 +100,7 @@ in
graphene = handleTest ./graphene.nix {};
grafana = handleTest ./grafana.nix {};
graphite = handleTest ./graphite.nix {};
graylog = handleTest ./graylog.nix {};
hadoop.hdfs = handleTestOn [ "x86_64-linux" ] ./hadoop/hdfs.nix {};
hadoop.yarn = handleTestOn [ "x86_64-linux" ] ./hadoop/yarn.nix {};
handbrake = handleTestOn ["x86_64-linux"] ./handbrake.nix {};

111
nixos/tests/graylog.nix Normal file
View file

@ -0,0 +1,111 @@
import ./make-test.nix ({ pkgs, lib, ... }: {
name = "graylog";
meta.maintainers = with lib.maintainers; [ ma27 ];
machine = { pkgs, ... }: {
virtualisation.memorySize = 4096;
virtualisation.diskSize = 4096;
services.mongodb.enable = true;
services.elasticsearch.enable = true;
services.elasticsearch.package = pkgs.elasticsearch-oss;
services.elasticsearch.extraConf = ''
network.publish_host: 127.0.0.1
network.bind_host: 127.0.0.1
'';
services.graylog = {
enable = true;
passwordSecret = "YGhZ59wXMrYOojx5xdgEpBpDw2N6FbhM4lTtaJ1KPxxmKrUvSlDbtWArwAWMQ5LKx1ojHEVrQrBMVRdXbRyZLqffoUzHfssc";
elasticsearchHosts = [ "http://localhost:9200" ];
# `echo -n "nixos" | shasum -a 256`
rootPasswordSha2 = "6ed332bcfa615381511d4d5ba44a293bb476f368f7e9e304f0dff50230d1a85b";
};
environment.systemPackages = [ pkgs.jq ];
systemd.services.graylog.path = [ pkgs.netcat ];
systemd.services.graylog.preStart = ''
until nc -z localhost 9200; do
sleep 2
done
'';
};
testScript = let
payloads.login = pkgs.writeText "login.json" (builtins.toJSON {
host = "127.0.0.1:9000";
username = "admin";
password = "nixos";
});
payloads.input = pkgs.writeText "input.json" (builtins.toJSON {
title = "Demo";
global = false;
type = "org.graylog2.inputs.gelf.udp.GELFUDPInput";
node = "@node@";
configuration = {
bind_address = "0.0.0.0";
decompress_size_limit = 8388608;
number_worker_threads = 1;
override_source = null;
port = 12201;
recv_buffer_size = 262144;
};
});
payloads.gelf_message = pkgs.writeText "gelf.json" (builtins.toJSON {
host = "example.org";
short_message = "A short message";
full_message = "A long message";
version = "1.1";
level = 5;
facility = "Test";
});
in ''
$machine->start;
$machine->waitForUnit("graylog.service");
$machine->waitForOpenPort(9000);
$machine->succeed("curl -sSfL http://127.0.0.1:9000/");
my $session = $machine->succeed("curl -X POST "
. "-sSfL http://127.0.0.1:9000/api/system/sessions "
. "-d \$(cat ${payloads.login}) "
. "-H 'Content-Type: application/json' "
. "-H 'Accept: application/json' "
. "-H 'x-requested-by: cli' "
. "| jq .session_id | xargs echo"
);
chomp($session);
$machine->succeed("curl -X POST "
. "-sSfL http://127.0.0.1:9000/api/system/inputs -u $session:session "
. "-d \$(cat ${payloads.input} | sed -e \"s,\@node\@,\$(cat /var/lib/graylog/server/node-id),\") "
. "-H 'Accept: application/json' "
. "-H 'Content-Type: application/json' "
. "-H 'x-requested-by: cli' "
);
$machine->waitUntilSucceeds("test \"\$(curl -sSfL 'http://127.0.0.1:9000/api/cluster/inputstates' "
. "-u $session:session "
. "-H 'Accept: application/json' "
. "-H 'Content-Type: application/json' "
. "-H 'x-requested-by: cli'"
. "| jq 'to_entries[]|.value|.[0]|.state' | xargs echo"
. ")\" = \"RUNNING\""
);
$machine->succeed("echo -n \$(cat ${payloads.gelf_message}) | nc -w10 -u 127.0.0.1 12201");
$machine->succeed("test \"\$(curl -X GET "
. "-sSfL 'http://127.0.0.1:9000/api/search/universal/relative?query=*' "
. "-u $session:session "
. "-H 'Accept: application/json' "
. "-H 'Content-Type: application/json' "
. "-H 'x-requested-by: cli'"
. " | jq '.total_results' | xargs echo)\" = \"1\""
);
'';
})

View file

@ -1,19 +1,17 @@
{ stdenv, buildGoPackage, fetchFromGitHub }:
{ stdenv, buildGoModule, fetchFromGitHub }:
buildGoPackage rec {
name = "SystemdJournal2Gelf-${version}";
version = "20170413";
goPackagePath = "github.com/parse-nl/SystemdJournal2Gelf";
buildGoModule rec {
pname = "SystemdJournal2Gelf-unstable";
version = "20190702";
src = fetchFromGitHub {
rev = "862b1d60d2ba12cd8480304ca95041066cc8bdd0";
rev = "b1aa5ff31307d11a3c9b4dd08c3cd6230d935ec5";
owner = "parse-nl";
repo = "SystemdJournal2Gelf";
sha256 = "0xvvc7w2sxkhb33nkq5v626l673d5j2z0yc75wvmqzncwfkkv94v";
sha256 = "0i2pv817fjm2xazxb01dk2gg1xb4d9b6743gqrbsyghbkm7krx29";
};
goDeps = ./deps.nix;
modSha256 = "0f66bjij3bkjs09xhhp26arivlqrd66z1j5ziy4lq4krg82krsdp";
meta = with stdenv.lib; {
description = "Export entries from systemd's journal and send them to a graylog server using gelf";

View file

@ -1,11 +0,0 @@
[
{
goPackagePath = "github.com/DECK36/go-gelf";
fetch = {
type = "git";
url = "https://github.com/DECK36/go-gelf";
rev = "4bc6123df0946a1c23fd54e0c1d0ed68b44fd99f";
sha256 = "071zdwcl8ld05gv88yym1p7xq72igd6jj05n5d7v01hn6rvj48ay";
};
}
]