mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-14 06:00:33 +03:00
Merge pull request #64463 from Ma27/graylog-test
nixos/graylog: minor fixes, add test
This commit is contained in:
commit
376b5fd000
5 changed files with 122 additions and 20 deletions
|
@ -150,6 +150,9 @@ in
|
||||||
rm -rf /var/lib/graylog/plugins || true
|
rm -rf /var/lib/graylog/plugins || true
|
||||||
mkdir -p /var/lib/graylog/plugins -m 755
|
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
|
for declarativeplugin in `ls ${glPlugins}/bin/`; do
|
||||||
ln -sf ${glPlugins}/bin/$declarativeplugin /var/lib/graylog/plugins/$declarativeplugin
|
ln -sf ${glPlugins}/bin/$declarativeplugin /var/lib/graylog/plugins/$declarativeplugin
|
||||||
done
|
done
|
||||||
|
|
|
@ -100,6 +100,7 @@ in
|
||||||
graphene = handleTest ./graphene.nix {};
|
graphene = handleTest ./graphene.nix {};
|
||||||
grafana = handleTest ./grafana.nix {};
|
grafana = handleTest ./grafana.nix {};
|
||||||
graphite = handleTest ./graphite.nix {};
|
graphite = handleTest ./graphite.nix {};
|
||||||
|
graylog = handleTest ./graylog.nix {};
|
||||||
hadoop.hdfs = handleTestOn [ "x86_64-linux" ] ./hadoop/hdfs.nix {};
|
hadoop.hdfs = handleTestOn [ "x86_64-linux" ] ./hadoop/hdfs.nix {};
|
||||||
hadoop.yarn = handleTestOn [ "x86_64-linux" ] ./hadoop/yarn.nix {};
|
hadoop.yarn = handleTestOn [ "x86_64-linux" ] ./hadoop/yarn.nix {};
|
||||||
handbrake = handleTestOn ["x86_64-linux"] ./handbrake.nix {};
|
handbrake = handleTestOn ["x86_64-linux"] ./handbrake.nix {};
|
||||||
|
|
111
nixos/tests/graylog.nix
Normal file
111
nixos/tests/graylog.nix
Normal 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\""
|
||||||
|
);
|
||||||
|
'';
|
||||||
|
})
|
|
@ -1,19 +1,17 @@
|
||||||
{ stdenv, buildGoPackage, fetchFromGitHub }:
|
{ stdenv, buildGoModule, fetchFromGitHub }:
|
||||||
|
|
||||||
buildGoPackage rec {
|
buildGoModule rec {
|
||||||
name = "SystemdJournal2Gelf-${version}";
|
pname = "SystemdJournal2Gelf-unstable";
|
||||||
version = "20170413";
|
version = "20190702";
|
||||||
|
|
||||||
goPackagePath = "github.com/parse-nl/SystemdJournal2Gelf";
|
|
||||||
|
|
||||||
src = fetchFromGitHub {
|
src = fetchFromGitHub {
|
||||||
rev = "862b1d60d2ba12cd8480304ca95041066cc8bdd0";
|
rev = "b1aa5ff31307d11a3c9b4dd08c3cd6230d935ec5";
|
||||||
owner = "parse-nl";
|
owner = "parse-nl";
|
||||||
repo = "SystemdJournal2Gelf";
|
repo = "SystemdJournal2Gelf";
|
||||||
sha256 = "0xvvc7w2sxkhb33nkq5v626l673d5j2z0yc75wvmqzncwfkkv94v";
|
sha256 = "0i2pv817fjm2xazxb01dk2gg1xb4d9b6743gqrbsyghbkm7krx29";
|
||||||
};
|
};
|
||||||
|
|
||||||
goDeps = ./deps.nix;
|
modSha256 = "0f66bjij3bkjs09xhhp26arivlqrd66z1j5ziy4lq4krg82krsdp";
|
||||||
|
|
||||||
meta = with stdenv.lib; {
|
meta = with stdenv.lib; {
|
||||||
description = "Export entries from systemd's journal and send them to a graylog server using gelf";
|
description = "Export entries from systemd's journal and send them to a graylog server using gelf";
|
||||||
|
|
11
pkgs/tools/system/systemd-journal2gelf/deps.nix
generated
11
pkgs/tools/system/systemd-journal2gelf/deps.nix
generated
|
@ -1,11 +0,0 @@
|
||||||
[
|
|
||||||
{
|
|
||||||
goPackagePath = "github.com/DECK36/go-gelf";
|
|
||||||
fetch = {
|
|
||||||
type = "git";
|
|
||||||
url = "https://github.com/DECK36/go-gelf";
|
|
||||||
rev = "4bc6123df0946a1c23fd54e0c1d0ed68b44fd99f";
|
|
||||||
sha256 = "071zdwcl8ld05gv88yym1p7xq72igd6jj05n5d7v01hn6rvj48ay";
|
|
||||||
};
|
|
||||||
}
|
|
||||||
]
|
|
Loading…
Add table
Add a link
Reference in a new issue