├── .gitignore
├── lib
└── sigar-1.6.4
│ ├── sigar.jar
│ ├── sigar-x86-winnt.dll
│ ├── sigar-x86-winnt.lib
│ ├── libsigar-ppc-aix-5.so
│ ├── libsigar-ppc-linux.so
│ ├── libsigar-x86-linux.so
│ ├── sigar-amd64-winnt.dll
│ ├── libsigar-amd64-linux.so
│ ├── libsigar-ia64-hpux-11.sl
│ ├── libsigar-ia64-linux.so
│ ├── libsigar-pa-hpux-11.sl
│ ├── libsigar-ppc64-aix-5.so
│ ├── libsigar-ppc64-linux.so
│ ├── libsigar-s390x-linux.so
│ ├── libsigar-x86-solaris.so
│ ├── libsigar-amd64-solaris.so
│ ├── libsigar-sparc-solaris.so
│ ├── libsigar-x86-freebsd-5.so
│ ├── libsigar-x86-freebsd-6.so
│ ├── libsigar-amd64-freebsd-6.so
│ ├── libsigar-sparc64-solaris.so
│ ├── libsigar-universal-macosx.dylib
│ └── libsigar-universal64-macosx.dylib
├── src
├── main
│ ├── resources
│ │ ├── collector-version.properties
│ │ ├── log4j2.xml
│ │ └── ValidationMessages.properties
│ ├── scripts
│ │ ├── graylog-collector-script-config.sh
│ │ ├── graylog-collector.bat
│ │ └── graylog-collector.sh
│ ├── java
│ │ └── org
│ │ │ └── graylog
│ │ │ └── collector
│ │ │ ├── cli
│ │ │ ├── commands
│ │ │ │ ├── CollectorCommand.java
│ │ │ │ ├── CollectorHelp.java
│ │ │ │ └── Version.java
│ │ │ └── Main.java
│ │ │ ├── buffer
│ │ │ ├── BufferConsumer.java
│ │ │ ├── Buffer.java
│ │ │ ├── BufferModule.java
│ │ │ ├── MessageBufferConfiguration.java
│ │ │ ├── MessageBuffer.java
│ │ │ └── BufferProcessor.java
│ │ │ ├── config
│ │ │ ├── Configuration.java
│ │ │ ├── ConfigurationError.java
│ │ │ ├── ConfigurationModule.java
│ │ │ ├── constraints
│ │ │ │ ├── IsOneOf.java
│ │ │ │ └── IsOneOfValidator.java
│ │ │ ├── ConfigurationParser.java
│ │ │ ├── ConfigurationUtils.java
│ │ │ └── ConfigurationValidator.java
│ │ │ ├── file
│ │ │ ├── naming
│ │ │ │ ├── FileNamingStrategy.java
│ │ │ │ ├── ExactFileStrategy.java
│ │ │ │ └── NumberSuffixStrategy.java
│ │ │ ├── splitters
│ │ │ │ ├── ContentSplitter.java
│ │ │ │ └── NewlineChunkSplitter.java
│ │ │ ├── FileModule.java
│ │ │ ├── PathSet.java
│ │ │ ├── FileChunk.java
│ │ │ ├── ChunkBufferStore.java
│ │ │ ├── SinglePathSet.java
│ │ │ └── ChunkProcessor.java
│ │ │ ├── inputs
│ │ │ ├── InputService.java
│ │ │ ├── Input.java
│ │ │ ├── file
│ │ │ │ ├── ValidFileInputConfiguration.java
│ │ │ │ ├── FileInput.java
│ │ │ │ └── FileInputConfigurationValidator.java
│ │ │ ├── InputsModule.java
│ │ │ ├── eventlog
│ │ │ │ ├── WindowsEventlogInputConfiguration.java
│ │ │ │ ├── WindowsEventlogInput.java
│ │ │ │ └── WindowsEventlogHandler.java
│ │ │ └── InputConfiguration.java
│ │ │ ├── outputs
│ │ │ ├── OutputService.java
│ │ │ ├── Output.java
│ │ │ ├── OutputsModule.java
│ │ │ ├── stdout
│ │ │ │ ├── StdoutOutputConfiguration.java
│ │ │ │ └── StdoutOutput.java
│ │ │ ├── OutputRouter.java
│ │ │ └── OutputConfiguration.java
│ │ │ ├── utils
│ │ │ ├── Utils.java
│ │ │ ├── CollectorIdModule.java
│ │ │ ├── MemoryReporterModule.java
│ │ │ ├── CollectorHostNameModule.java
│ │ │ ├── CollectorHostNameConfiguration.java
│ │ │ ├── CollectorIdConfiguration.java
│ │ │ ├── CollectorHostNameProvider.java
│ │ │ ├── MemoryReporterServiceConfiguration.java
│ │ │ ├── CollectorHostNameSupplier.java
│ │ │ └── CollectorId.java
│ │ │ ├── services
│ │ │ ├── ServicesModule.java
│ │ │ ├── ServiceManagerProvider.java
│ │ │ └── CollectorServiceManager.java
│ │ │ ├── annotations
│ │ │ ├── CollectorHostName.java
│ │ │ └── GraylogServerURL.java
│ │ │ ├── metrics
│ │ │ ├── MetricsModule.java
│ │ │ ├── MetricServiceConfiguration.java
│ │ │ └── MetricService.java
│ │ │ ├── heartbeat
│ │ │ ├── HeartbeatModule.java
│ │ │ ├── CollectorRegistrationService.java
│ │ │ ├── CollectorRegistrationServiceProvider.java
│ │ │ ├── CollectorNodeDetailsSummary.java
│ │ │ ├── CollectorRegistrationRequestProvider.java
│ │ │ ├── CollectorRegistrationRequest.java
│ │ │ └── HeartbeatService.java
│ │ │ ├── serverapi
│ │ │ ├── ServerApiModule.java
│ │ │ ├── ServerURLProvider.java
│ │ │ └── RestAdapterProvider.java
│ │ │ ├── guice
│ │ │ ├── CollectorInjector.java
│ │ │ └── CollectorModule.java
│ │ │ ├── MessageFields.java
│ │ │ ├── CollectorVersion.java
│ │ │ └── Message.java
│ └── assembly
│ │ └── collector.xml
└── test
│ └── java
│ └── org
│ └── graylog
│ └── collector
│ ├── utils
│ ├── CollectorHostNameProviderTest.java
│ ├── CollectorHostNameConfigurationTest.java
│ └── CollectorHostNameSupplierTest.java
│ ├── file
│ ├── CollectingBuffer.java
│ ├── ChunkBufferStoreTest.java
│ ├── MultithreadedBaseTest.java
│ ├── naming
│ │ └── FileNamingStrategyTest.java
│ ├── SinglePathSetTest.java
│ └── Utils.java
│ ├── config
│ ├── constraints
│ │ └── IsOneOfValidatorTest.java
│ └── ConfigurationParserTest.java
│ └── MessageFieldsTest.java
├── bin
└── windows
│ ├── graylog-collector-service-x64.exe
│ ├── graylog-collector-service-x86.exe
│ └── graylog-collector-service-manager.exe
├── .travis.yml
├── development
└── forbidden-apis
│ └── signatures.txt
├── CONTRIBUTING.md
├── CHANGELOG.md
└── config
└── collector.conf.example
/.gitignore:
--------------------------------------------------------------------------------
1 | /.idea/
2 | /config/*.conf
3 | /config/collector-id
4 | /logs/
5 | /target/
6 | *.iml
7 |
--------------------------------------------------------------------------------
/lib/sigar-1.6.4/sigar.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/graylog-labs/collector/HEAD/lib/sigar-1.6.4/sigar.jar
--------------------------------------------------------------------------------
/lib/sigar-1.6.4/sigar-x86-winnt.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/graylog-labs/collector/HEAD/lib/sigar-1.6.4/sigar-x86-winnt.dll
--------------------------------------------------------------------------------
/lib/sigar-1.6.4/sigar-x86-winnt.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/graylog-labs/collector/HEAD/lib/sigar-1.6.4/sigar-x86-winnt.lib
--------------------------------------------------------------------------------
/lib/sigar-1.6.4/libsigar-ppc-aix-5.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/graylog-labs/collector/HEAD/lib/sigar-1.6.4/libsigar-ppc-aix-5.so
--------------------------------------------------------------------------------
/lib/sigar-1.6.4/libsigar-ppc-linux.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/graylog-labs/collector/HEAD/lib/sigar-1.6.4/libsigar-ppc-linux.so
--------------------------------------------------------------------------------
/lib/sigar-1.6.4/libsigar-x86-linux.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/graylog-labs/collector/HEAD/lib/sigar-1.6.4/libsigar-x86-linux.so
--------------------------------------------------------------------------------
/lib/sigar-1.6.4/sigar-amd64-winnt.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/graylog-labs/collector/HEAD/lib/sigar-1.6.4/sigar-amd64-winnt.dll
--------------------------------------------------------------------------------
/src/main/resources/collector-version.properties:
--------------------------------------------------------------------------------
1 | version=${project.version}
2 | commit-id=${buildNumber}
3 | timestamp=${timestamp}
--------------------------------------------------------------------------------
/lib/sigar-1.6.4/libsigar-amd64-linux.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/graylog-labs/collector/HEAD/lib/sigar-1.6.4/libsigar-amd64-linux.so
--------------------------------------------------------------------------------
/lib/sigar-1.6.4/libsigar-ia64-hpux-11.sl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/graylog-labs/collector/HEAD/lib/sigar-1.6.4/libsigar-ia64-hpux-11.sl
--------------------------------------------------------------------------------
/lib/sigar-1.6.4/libsigar-ia64-linux.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/graylog-labs/collector/HEAD/lib/sigar-1.6.4/libsigar-ia64-linux.so
--------------------------------------------------------------------------------
/lib/sigar-1.6.4/libsigar-pa-hpux-11.sl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/graylog-labs/collector/HEAD/lib/sigar-1.6.4/libsigar-pa-hpux-11.sl
--------------------------------------------------------------------------------
/lib/sigar-1.6.4/libsigar-ppc64-aix-5.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/graylog-labs/collector/HEAD/lib/sigar-1.6.4/libsigar-ppc64-aix-5.so
--------------------------------------------------------------------------------
/lib/sigar-1.6.4/libsigar-ppc64-linux.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/graylog-labs/collector/HEAD/lib/sigar-1.6.4/libsigar-ppc64-linux.so
--------------------------------------------------------------------------------
/lib/sigar-1.6.4/libsigar-s390x-linux.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/graylog-labs/collector/HEAD/lib/sigar-1.6.4/libsigar-s390x-linux.so
--------------------------------------------------------------------------------
/lib/sigar-1.6.4/libsigar-x86-solaris.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/graylog-labs/collector/HEAD/lib/sigar-1.6.4/libsigar-x86-solaris.so
--------------------------------------------------------------------------------
/lib/sigar-1.6.4/libsigar-amd64-solaris.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/graylog-labs/collector/HEAD/lib/sigar-1.6.4/libsigar-amd64-solaris.so
--------------------------------------------------------------------------------
/lib/sigar-1.6.4/libsigar-sparc-solaris.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/graylog-labs/collector/HEAD/lib/sigar-1.6.4/libsigar-sparc-solaris.so
--------------------------------------------------------------------------------
/lib/sigar-1.6.4/libsigar-x86-freebsd-5.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/graylog-labs/collector/HEAD/lib/sigar-1.6.4/libsigar-x86-freebsd-5.so
--------------------------------------------------------------------------------
/lib/sigar-1.6.4/libsigar-x86-freebsd-6.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/graylog-labs/collector/HEAD/lib/sigar-1.6.4/libsigar-x86-freebsd-6.so
--------------------------------------------------------------------------------
/bin/windows/graylog-collector-service-x64.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/graylog-labs/collector/HEAD/bin/windows/graylog-collector-service-x64.exe
--------------------------------------------------------------------------------
/bin/windows/graylog-collector-service-x86.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/graylog-labs/collector/HEAD/bin/windows/graylog-collector-service-x86.exe
--------------------------------------------------------------------------------
/lib/sigar-1.6.4/libsigar-amd64-freebsd-6.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/graylog-labs/collector/HEAD/lib/sigar-1.6.4/libsigar-amd64-freebsd-6.so
--------------------------------------------------------------------------------
/lib/sigar-1.6.4/libsigar-sparc64-solaris.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/graylog-labs/collector/HEAD/lib/sigar-1.6.4/libsigar-sparc64-solaris.so
--------------------------------------------------------------------------------
/lib/sigar-1.6.4/libsigar-universal-macosx.dylib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/graylog-labs/collector/HEAD/lib/sigar-1.6.4/libsigar-universal-macosx.dylib
--------------------------------------------------------------------------------
/bin/windows/graylog-collector-service-manager.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/graylog-labs/collector/HEAD/bin/windows/graylog-collector-service-manager.exe
--------------------------------------------------------------------------------
/lib/sigar-1.6.4/libsigar-universal64-macosx.dylib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/graylog-labs/collector/HEAD/lib/sigar-1.6.4/libsigar-universal64-macosx.dylib
--------------------------------------------------------------------------------
/src/main/scripts/graylog-collector-script-config.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | COLLECTOR_JAVA_DEFAULT_OPTS="${collector.jvm-opts} -Djava.library.path=${collector.share-path}/lib/sigar"
4 | COLLECTOR_DEFAULT_JAR="${collector.jar-path}"
5 |
6 | # For Debian/Ubuntu based systems.
7 | if [ -f "/etc/default/graylog-collector" ]; then
8 | . "/etc/default/graylog-collector"
9 | fi
10 |
11 | # For RedHat/Fedora based systems.
12 | if [ -f "/etc/sysconfig/graylog-collector" ]; then
13 | . "/etc/sysconfig/graylog-collector"
14 | fi
15 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: false
2 | language: java
3 | jdk:
4 | - oraclejdk7
5 | - oraclejdk8
6 | after_success:
7 | - mvn -DskipTests -B assembly:single
8 | deploy:
9 | provider: s3
10 | access_key_id: AKIAJBL3SCAJTENB5ZQA
11 | secret_access_key:
12 | secure: EY9WZbf/e1I7Ft3qfhBXMYpzn1CGOzCp1hjMQK8NsO8nJEYtT5V/RRsqsgBNr0bQF3FHxcidqRi4CoY0cS5c71pLff9lYa9Dkyi5oJ0W8/rzGMu69WNhNmUWrpwxs0IL91/st6L1/okoSSb0WXCPLRFG5t8/xKE1YY6XKC4DM9I=
13 | bucket: graylog2-builds
14 | region: eu-west-1
15 | skip_cleanup: true
16 | local-dir: target/assembly
17 | on:
18 | repo: Graylog2/collector
19 | jdk: oraclejdk7
20 | branch:
21 | - master
22 |
--------------------------------------------------------------------------------
/src/main/resources/log4j2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/main/scripts/graylog-collector.bat:
--------------------------------------------------------------------------------
1 | :: Graylog Collector startup script for Windows
2 |
3 | @ECHO OFF
4 |
5 | SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
6 | TITLE Graylog Collector ${project.version}
7 |
8 | IF DEFINED JAVA_HOME goto :continue
9 |
10 | :: JAVA_HOME needs to be set to find the JVM.
11 | :jvmError
12 | ECHO JAVA_HOME not set! 1>&2
13 | EXIT /B 1
14 |
15 | :: Execute the JAR.
16 | :continue
17 | set COLLECTOR_BIN_DIR=%~dp0
18 |
19 | :: Get root directory of the Collector.
20 | FOR %%D in ("%COLLECTOR_BIN_DIR%..") DO SET COLLECTOR_ROOT=%%~dpfD
21 |
22 | SET COLLECTOR_JAR=%COLLECTOR_ROOT%\${project.artifactId}.jar
23 | SET COLLECTOR_JVM_OPTIONS=-Djava.library.path="%COLLECTOR_ROOT%\lib\sigar" -Dfile.encoding=UTF-8 ${collector.jvm-opts}
24 |
25 | "%JAVA_HOME%\bin\java" %COLLECTOR_JVM_OPTIONS% -jar "%COLLECTOR_JAR%" %*
26 |
27 | ENDLOCAL
28 |
--------------------------------------------------------------------------------
/development/forbidden-apis/signatures.txt:
--------------------------------------------------------------------------------
1 | @defaultMessage Use a custom thread factory to ensure proper thread naming.
2 | java.util.concurrent.Executors#defaultThreadFactory()
3 | java.util.concurrent.Executors#newCachedThreadPool()
4 | java.util.concurrent.Executors#newFixedThreadPool(int)
5 | java.util.concurrent.Executors#newScheduledThreadPool(int)
6 | java.util.concurrent.Executors#newSingleThreadExecutor()
7 | java.util.concurrent.Executors#newSingleThreadScheduledExecutor()
8 | java.util.concurrent.Executors#privilegedThreadFactory()
9 |
10 | @defaultMessage Do not create a DateTime without an explicit time zone.
11 | org.joda.time.DateTime#()
12 | org.joda.time.DateTime#(long)
13 | org.joda.time.DateTime#(int, int, int, int, int)
14 | org.joda.time.DateTime#(int, int, int, int, int, int)
15 | org.joda.time.DateTime#(int, int, int, int, int, int, int)
16 | org.joda.time.DateTime#now()
17 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/cli/commands/CollectorCommand.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.cli.commands;
18 |
19 | public interface CollectorCommand extends Runnable {
20 | void stop();
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/buffer/BufferConsumer.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.buffer;
18 |
19 | import org.graylog.collector.Message;
20 |
21 | public interface BufferConsumer {
22 | void process(Message message);
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/buffer/Buffer.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.buffer;
18 |
19 | import org.graylog.collector.Message;
20 |
21 | public interface Buffer {
22 | void insert(Message message);
23 |
24 | Message remove();
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/config/Configuration.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.config;
18 |
19 | import java.util.Map;
20 |
21 | public interface Configuration {
22 | String getId();
23 |
24 | Map toStringValues();
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/file/naming/FileNamingStrategy.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.file.naming;
18 |
19 | import java.nio.file.Path;
20 |
21 | public interface FileNamingStrategy {
22 |
23 | boolean pathMatches(Path path);
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/inputs/InputService.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.inputs;
18 |
19 | import com.google.common.util.concurrent.AbstractService;
20 |
21 | public abstract class InputService extends AbstractService implements Input {
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/outputs/OutputService.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.outputs;
18 |
19 | import com.google.common.util.concurrent.AbstractService;
20 |
21 | public abstract class OutputService extends AbstractService implements Output {
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/resources/ValidationMessages.properties:
--------------------------------------------------------------------------------
1 | org.graylog.collector.config.constraints.IsOneOf.message="${validatedValue}" is not one of: ${validValues}
2 | org.graylog.collector.inputs.file.ValidFileInputConfiguration.message=The file input configuration is invalid
3 | org.graylog.collector.inputs.file.ValidFileInputConfiguration.invalidPattern.message=Invalid content splitter pattern: "${value}"
4 | org.graylog.collector.inputs.file.ValidFileInputConfiguration.missingPattern.message=Missing content splitter pattern.
5 | org.graylog.collector.inputs.file.ValidFileInputConfiguration.unsupportedCharset.message=Character set not supported: "${value}"
6 | org.graylog.collector.inputs.file.ValidFileInputConfiguration.illegalCharset.message=Invalid character set value: "${value}"
7 | org.graylog.collector.inputs.file.ValidFileInputConfiguration.readerBufferSizeTooSmall.message=Reader buffer size too small: "${value}"
8 | org.graylog.collector.inputs.file.ValidFileInputConfiguration.readerIntervalTooSmall.message=Reader interval too small: "${value}"
9 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/cli/commands/CollectorHelp.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.cli.commands;
18 |
19 | import io.airlift.airline.Help;
20 |
21 | public class CollectorHelp extends Help implements CollectorCommand {
22 | @Override
23 | public void stop() {
24 | // nothing to stop
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/utils/Utils.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.utils;
18 |
19 | import java.util.Locale;
20 |
21 | public class Utils {
22 | private static final boolean IS_WINDOWS = System.getProperty("os.name").toLowerCase(Locale.US).startsWith("windows");
23 |
24 | public static boolean isWindows() {
25 | return IS_WINDOWS;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/config/ConfigurationError.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.config;
18 |
19 | public class ConfigurationError {
20 | private final String messsage;
21 |
22 | public ConfigurationError(String messsage) {
23 | this.messsage = messsage;
24 | }
25 |
26 | public String getMesssage() {
27 | return messsage;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/utils/CollectorIdModule.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.utils;
18 |
19 | import org.graylog.collector.guice.CollectorModule;
20 |
21 | public class CollectorIdModule extends CollectorModule {
22 | @Override
23 | protected void configure() {
24 | bind(CollectorIdConfiguration.class);
25 | bind(CollectorId.class);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/services/ServicesModule.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.services;
18 |
19 | import com.google.common.util.concurrent.ServiceManager;
20 | import org.graylog.collector.guice.CollectorModule;
21 |
22 | public class ServicesModule extends CollectorModule {
23 | @Override
24 | protected void configure() {
25 | bind(CollectorServiceManager.class);
26 | bind(ServiceManager.class).toProvider(ServiceManagerProvider.class);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/annotations/CollectorHostName.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.annotations;
18 |
19 | import com.google.inject.BindingAnnotation;
20 |
21 | import java.lang.annotation.ElementType;
22 | import java.lang.annotation.Retention;
23 | import java.lang.annotation.RetentionPolicy;
24 | import java.lang.annotation.Target;
25 |
26 | @Target(ElementType.PARAMETER)
27 | @Retention(RetentionPolicy.RUNTIME)
28 | @BindingAnnotation
29 | public @interface CollectorHostName {
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/annotations/GraylogServerURL.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.annotations;
18 |
19 | import com.google.inject.BindingAnnotation;
20 |
21 | import java.lang.annotation.ElementType;
22 | import java.lang.annotation.Retention;
23 | import java.lang.annotation.RetentionPolicy;
24 | import java.lang.annotation.Target;
25 |
26 | @Target(ElementType.PARAMETER)
27 | @Retention(RetentionPolicy.RUNTIME)
28 | @BindingAnnotation
29 | public @interface GraylogServerURL {
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/outputs/Output.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.outputs;
18 |
19 | import org.graylog.collector.Message;
20 | import org.graylog.collector.config.Configuration;
21 |
22 | import java.util.Set;
23 |
24 | public interface Output {
25 | String getId();
26 |
27 | Set getInputs();
28 |
29 | void write(Message message);
30 |
31 | interface Factory {
32 | T create(C configuration);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/buffer/BufferModule.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.buffer;
18 |
19 | import com.google.inject.Scopes;
20 | import org.graylog.collector.guice.CollectorModule;
21 |
22 | public class BufferModule extends CollectorModule {
23 | @Override
24 | protected void configure() {
25 | bind(MessageBufferConfiguration.class);
26 | bind(Buffer.class).to(MessageBuffer.class).in(Scopes.SINGLETON);
27 |
28 | registerService(BufferProcessor.class);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/utils/MemoryReporterModule.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.utils;
18 |
19 | import com.google.inject.Scopes;
20 | import org.graylog.collector.guice.CollectorModule;
21 |
22 | public class MemoryReporterModule extends CollectorModule {
23 | @Override
24 | protected void configure() {
25 | bind(MemoryReporterService.class).in(Scopes.SINGLETON);
26 | bind(MemoryReporterServiceConfiguration.class);
27 |
28 | registerService(MemoryReporterService.class);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/utils/CollectorHostNameModule.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.utils;
18 |
19 | import org.graylog.collector.annotations.CollectorHostName;
20 | import org.graylog.collector.guice.CollectorModule;
21 |
22 | public class CollectorHostNameModule extends CollectorModule {
23 | @Override
24 | protected void configure() {
25 | bind(CollectorHostNameConfiguration.class);
26 | bind(String.class).annotatedWith(CollectorHostName.class).toProvider(CollectorHostNameProvider.class);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/metrics/MetricsModule.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.metrics;
18 |
19 | import com.codahale.metrics.MetricRegistry;
20 | import com.google.inject.Scopes;
21 | import org.graylog.collector.guice.CollectorModule;
22 |
23 | public class MetricsModule extends CollectorModule {
24 | @Override
25 | protected void configure() {
26 | bind(MetricRegistry.class).in(Scopes.SINGLETON);
27 | bind(MetricServiceConfiguration.class);
28 |
29 | registerService(MetricService.class);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/heartbeat/HeartbeatModule.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.heartbeat;
18 |
19 | import org.graylog.collector.guice.CollectorModule;
20 |
21 | public class HeartbeatModule extends CollectorModule {
22 | @Override
23 | protected void configure() {
24 | bind(CollectorRegistrationService.class).toProvider(CollectorRegistrationServiceProvider.class);
25 | bind(CollectorRegistrationRequest.class).toProvider(CollectorRegistrationRequestProvider.class);
26 | registerService(HeartbeatService.class);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/inputs/Input.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.inputs;
18 |
19 | import org.graylog.collector.config.Configuration;
20 | import org.graylog.collector.file.ChunkReader;
21 |
22 | import java.util.Set;
23 |
24 | public interface Input {
25 | String getId();
26 |
27 | Set getOutputs();
28 |
29 | // TODO Check if needed and for what it was used.
30 | void setReaderFinished(ChunkReader chunkReader);
31 |
32 | interface Factory {
33 | T create(C configuration);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/serverapi/ServerApiModule.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.serverapi;
18 |
19 | import org.graylog.collector.annotations.GraylogServerURL;
20 | import org.graylog.collector.guice.CollectorModule;
21 | import retrofit.RestAdapter;
22 |
23 | public class ServerApiModule extends CollectorModule {
24 | @Override
25 | protected void configure() {
26 | bind(String.class).annotatedWith(GraylogServerURL.class).toProvider(ServerURLProvider.class);
27 | bind(RestAdapter.class).toProvider(RestAdapterProvider.class).asEagerSingleton();
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/scripts/graylog-collector.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # resolve links - $0 may be a softlink
4 | COLLECTOR_BIN="$0"
5 |
6 | while [ -h "$COLLECTOR_BIN" ]; do
7 | ls=$(ls -ld "$COLLECTOR_BIN")
8 | link=$(expr "$ls" : '.*-> \(.*\)$')
9 | if expr "$link" : '/.*' > /dev/null; then
10 | COLLECTOR_BIN="$link"
11 | else
12 | COLLECTOR_BIN=$(dirname "$COLLECTOR_BIN")/"$link"
13 | fi
14 | done
15 |
16 | COLLECTOR_ROOT="$(dirname $(dirname $COLLECTOR_BIN))"
17 | COLLECTOR_DEFAULT_JAR="$COLLECTOR_ROOT/graylog-collector.jar"
18 |
19 | COLLECTOR_JAVA_DEFAULT_OPTS="${collector.jvm-opts} -Djava.library.path=$COLLECTOR_ROOT/lib/sigar"
20 |
21 | if [ -f "${collector.script-config}" ]; then
22 | . "${collector.script-config}"
23 | fi
24 |
25 | COLLECTOR_JAR=${COLLECTOR_JAR:="$COLLECTOR_DEFAULT_JAR"}
26 |
27 | COLLECTOR_JAVA_CMD=${COLLECTOR_JAVA_CMD:=$(which java)}
28 | COLLECTOR_JAVA_OPTS="${COLLECTOR_JAVA_OPTS:="$COLLECTOR_JAVA_DEFAULT_OPTS"}"
29 |
30 | die() {
31 | echo $*
32 | exit 1
33 | }
34 |
35 | if [ -n "$JAVA_HOME" ]; then
36 | # Try to use $JAVA_HOME
37 | if [ -x "$JAVA_HOME"/bin/java ]; then
38 | COLLECTOR_JAVA_CMD="$JAVA_HOME"/bin/java
39 | else
40 | die "$JAVA_HOME"/bin/java is not executable
41 | fi
42 | fi
43 |
44 | exec $COLLECTOR_JAVA_CMD $COLLECTOR_JAVA_OPTS -jar $COLLECTOR_JAR "$@"
45 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/file/splitters/ContentSplitter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.file.splitters;
18 |
19 | import io.netty.buffer.ByteBuf;
20 |
21 | import java.nio.charset.Charset;
22 |
23 | public abstract class ContentSplitter {
24 |
25 | public abstract Iterable split(ByteBuf buffer, Charset charset, boolean includeRemainingData);
26 |
27 | public Iterable split(ByteBuf buffer, Charset charset) {
28 | return split(buffer, charset, false);
29 | }
30 |
31 | public Iterable splitRemaining(ByteBuf buffer, Charset charset) {
32 | return split(buffer, charset, true);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/heartbeat/CollectorRegistrationService.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.heartbeat;
18 |
19 | import retrofit.client.Response;
20 | import retrofit.http.Body;
21 | import retrofit.http.PUT;
22 | import retrofit.http.Path;
23 |
24 | public interface CollectorRegistrationService {
25 | @PUT("/plugins/org.graylog.plugins.collector/collectors/{collectorId}")
26 | Response register(@Path("collectorId") String collectorId, @Body CollectorRegistrationRequest request);
27 |
28 | @PUT("/system/collectors/{collectorId}")
29 | Response legacyRegister(@Path("collectorId") String collectorId, @Body CollectorRegistrationRequest request);
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/buffer/MessageBufferConfiguration.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.buffer;
18 |
19 | import com.typesafe.config.Config;
20 |
21 | import javax.inject.Inject;
22 |
23 | public class MessageBufferConfiguration {
24 | private static int SIZE = 128;
25 |
26 | private final int size;
27 |
28 | @Inject
29 | public MessageBufferConfiguration(Config config) {
30 | if (config.hasPath("message-buffer-size")) {
31 | this.size = config.getInt("message-buffer-size");
32 | } else {
33 | this.size = SIZE;
34 | }
35 | }
36 |
37 | public int getSize() {
38 | return size;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/utils/CollectorHostNameConfiguration.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.utils;
18 |
19 | import com.typesafe.config.Config;
20 |
21 | import javax.annotation.Nullable;
22 | import javax.inject.Inject;
23 |
24 | public class CollectorHostNameConfiguration {
25 | private static final String CONFIG_PATH = "host-name";
26 | private final String hostName;
27 |
28 | @Inject
29 | public CollectorHostNameConfiguration(Config config) {
30 | this.hostName = config.hasPath(CONFIG_PATH) ? config.getString(CONFIG_PATH) : null;
31 | }
32 |
33 | @Nullable
34 | public String getHostName() {
35 | return hostName;
36 | }
37 | }
38 |
39 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/guice/CollectorInjector.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.guice;
18 |
19 | import com.google.inject.Guice;
20 | import com.google.inject.Injector;
21 | import com.google.inject.Module;
22 | import com.google.inject.Stage;
23 |
24 | public class CollectorInjector {
25 | public static Injector createInjector(Module... modules) {
26 | final Injector injector = Guice.createInjector(Stage.PRODUCTION, new CollectorModule() {
27 | @Override
28 | protected void configure() {
29 | binder().requireExplicitBindings();
30 | }
31 | });
32 |
33 | return injector.createChildInjector(modules);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/config/ConfigurationModule.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.config;
18 |
19 | import com.google.inject.Scopes;
20 | import com.typesafe.config.Config;
21 | import org.graylog.collector.guice.CollectorModule;
22 |
23 | import java.io.File;
24 |
25 | public class ConfigurationModule extends CollectorModule {
26 | private final Config config;
27 |
28 | public ConfigurationModule(File configFile) {
29 | this.config = ConfigurationParser.parse(configFile);
30 | }
31 |
32 | @Override
33 | protected void configure() {
34 | bind(Config.class).toInstance(config);
35 | bind(ConfigurationRegistry.class).in(Scopes.SINGLETON);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/heartbeat/CollectorRegistrationServiceProvider.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.heartbeat;
18 |
19 | import retrofit.RestAdapter;
20 |
21 | import javax.inject.Inject;
22 | import javax.inject.Provider;
23 |
24 | public class CollectorRegistrationServiceProvider implements Provider {
25 | private final RestAdapter restAdapter;
26 |
27 | @Inject
28 | public CollectorRegistrationServiceProvider(RestAdapter restAdapter) {
29 | this.restAdapter = restAdapter;
30 | }
31 |
32 | @Override
33 | public CollectorRegistrationService get() {
34 | return this.restAdapter.create(CollectorRegistrationService.class);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/cli/commands/Version.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.cli.commands;
18 |
19 | import io.airlift.airline.Command;
20 | import org.graylog.collector.CollectorVersion;
21 |
22 | @Command(name = "version", description = "Show version information on STDOUT")
23 | public class Version implements CollectorCommand {
24 | @Override
25 | public void run() {
26 | final CollectorVersion v = CollectorVersion.CURRENT;
27 | final String message = String.format("Graylog Collector v%s (commit=%s, timestamp=%s)",
28 | v.version(), v.commitIdShort(), v.timestamp());
29 |
30 | System.out.println(message);
31 | }
32 |
33 | @Override
34 | public void stop() {
35 | // nothing to stop
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/utils/CollectorIdConfiguration.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.utils;
18 |
19 | import com.typesafe.config.Config;
20 |
21 | import javax.inject.Inject;
22 |
23 | public class CollectorIdConfiguration {
24 | private static final String collectorIdStatement = "collector-id";
25 | private final String collectorId;
26 |
27 | @Inject
28 | public CollectorIdConfiguration(Config config) {
29 | if (config.hasPath(collectorIdStatement)) {
30 | this.collectorId = config.getString(collectorIdStatement);
31 | } else {
32 | this.collectorId = "file:config/collector-id";
33 | }
34 | }
35 |
36 | public String getCollectorId() {
37 | return collectorId;
38 | }
39 | }
40 |
41 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/config/constraints/IsOneOf.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.config.constraints;
18 |
19 | import javax.validation.Constraint;
20 | import javax.validation.Payload;
21 | import java.lang.annotation.ElementType;
22 | import java.lang.annotation.Retention;
23 | import java.lang.annotation.RetentionPolicy;
24 | import java.lang.annotation.Target;
25 |
26 | @Target({ElementType.FIELD})
27 | @Retention(RetentionPolicy.RUNTIME)
28 | @Constraint(validatedBy = IsOneOfValidator.class)
29 | public @interface IsOneOf {
30 | String message() default "{org.graylog.collector.config.constraints.IsOneOf.message}";
31 |
32 | String[] value();
33 |
34 | Class>[] groups() default {};
35 |
36 | Class extends Payload>[] payload() default {};
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/file/FileModule.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.file;
18 |
19 | import com.google.inject.Scopes;
20 | import org.graylog.collector.guice.CollectorModule;
21 |
22 | import java.io.IOException;
23 | import java.nio.file.FileSystems;
24 | import java.nio.file.WatchService;
25 |
26 | public class FileModule extends CollectorModule {
27 | @Override
28 | protected void configure() {
29 | try {
30 | bind(WatchService.class).toInstance(FileSystems.getDefault().newWatchService());
31 | } catch (IOException e) {
32 | throw new RuntimeException("Unable to create WatchService");
33 | }
34 |
35 | bind(FileObserver.class).in(Scopes.SINGLETON);
36 | registerService(FileObserver.class);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/serverapi/ServerURLProvider.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.serverapi;
18 |
19 | import com.typesafe.config.Config;
20 |
21 | import javax.inject.Inject;
22 | import javax.inject.Provider;
23 |
24 | public class ServerURLProvider implements Provider {
25 | private static final String serverURLStatement = "server-url";
26 | private final Config config;
27 |
28 | @Inject
29 | public ServerURLProvider(Config config) {
30 | this.config = config;
31 | }
32 |
33 | @Override
34 | public String get() {
35 | if (config.hasPath(serverURLStatement)) {
36 | return config.getString(serverURLStatement);
37 | } else {
38 | return "http://localhost:12900";
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/inputs/file/ValidFileInputConfiguration.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.inputs.file;
18 |
19 | import javax.validation.Constraint;
20 | import javax.validation.Payload;
21 | import java.lang.annotation.ElementType;
22 | import java.lang.annotation.Retention;
23 | import java.lang.annotation.RetentionPolicy;
24 | import java.lang.annotation.Target;
25 |
26 | @Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE})
27 | @Retention(RetentionPolicy.RUNTIME)
28 | @Constraint(validatedBy = FileInputConfigurationValidator.class)
29 | public @interface ValidFileInputConfiguration {
30 | String message() default "{org.graylog.collector.inputs.file.ValidFileInputConfiguration.message}";
31 |
32 | Class>[] groups() default {};
33 |
34 | Class extends Payload>[] payload() default {};
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/file/PathSet.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.file;
18 |
19 | import java.io.IOException;
20 | import java.nio.file.Path;
21 | import java.util.Set;
22 |
23 | public interface PathSet {
24 | /**
25 | * Get the root path of the path set.
26 | * @return the root path
27 | */
28 | Path getRootPath();
29 |
30 | /**
31 | * Checks if the given path is in the path set.
32 | *
33 | * @param path
34 | * @return true if given path is in the path set, false otherwise
35 | */
36 | boolean isInSet(Path path);
37 |
38 | /**
39 | * Returns all files of the path set that exist in the file system.
40 | *
41 | * @return existing path set files in the file system
42 | * @throws IOException
43 | */
44 | Set getPaths() throws IOException;
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/heartbeat/CollectorNodeDetailsSummary.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.heartbeat;
18 |
19 | import com.fasterxml.jackson.annotation.JsonAutoDetect;
20 | import com.fasterxml.jackson.annotation.JsonCreator;
21 | import com.fasterxml.jackson.annotation.JsonProperty;
22 | import com.google.auto.value.AutoValue;
23 |
24 | import javax.validation.constraints.NotNull;
25 | import javax.validation.constraints.Size;
26 |
27 | @AutoValue
28 | @JsonAutoDetect
29 | public abstract class CollectorNodeDetailsSummary {
30 |
31 | @JsonProperty("operating_system")
32 | @NotNull
33 | @Size(min = 1)
34 | public abstract String operatingSystem();
35 |
36 | @JsonCreator
37 | public static CollectorNodeDetailsSummary create(@JsonProperty("operating_system") String operatingSystem) {
38 | return new AutoValue_CollectorNodeDetailsSummary(operatingSystem);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/heartbeat/CollectorRegistrationRequestProvider.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.heartbeat;
18 |
19 | import javax.inject.Inject;
20 | import javax.inject.Provider;
21 | import java.net.InetAddress;
22 | import java.net.UnknownHostException;
23 |
24 | public class CollectorRegistrationRequestProvider implements Provider {
25 | private final String operatingSystem;
26 | private final String hostname;
27 |
28 | @Inject
29 | public CollectorRegistrationRequestProvider() throws UnknownHostException {
30 | this.operatingSystem = System.getProperty("os.name", "unknown");
31 | this.hostname = InetAddress.getLocalHost().getHostName();
32 | }
33 |
34 | @Override
35 | public CollectorRegistrationRequest get() {
36 | return CollectorRegistrationRequest.create(hostname, CollectorNodeDetailsSummary.create(operatingSystem));
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/test/java/org/graylog/collector/utils/CollectorHostNameProviderTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.utils;
18 |
19 | import org.junit.Test;
20 |
21 | import static org.junit.Assert.assertEquals;
22 | import static org.mockito.Mockito.mock;
23 | import static org.mockito.Mockito.only;
24 | import static org.mockito.Mockito.verify;
25 | import static org.mockito.Mockito.when;
26 |
27 | public class CollectorHostNameProviderTest {
28 | @Test
29 | public void providerMemoizesHostName() throws Exception {
30 | final CollectorHostNameSupplier supplier = mock(CollectorHostNameSupplier.class);
31 | when(supplier.get()).thenReturn("foobar.example.net");
32 |
33 | final CollectorHostNameProvider provider = new CollectorHostNameProvider(supplier);
34 |
35 | assertEquals("foobar.example.net", provider.get());
36 | assertEquals("foobar.example.net", provider.get());
37 | verify(supplier, only()).get();
38 | }
39 | }
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/file/FileChunk.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.file;
18 |
19 | import io.netty.buffer.ByteBuf;
20 |
21 | import java.nio.file.Path;
22 |
23 | public class FileChunk {
24 |
25 | private final Path path;
26 | private final ByteBuf chunkBuffer;
27 | private final long id;
28 |
29 | public FileChunk(Path path, ByteBuf chunkBuffer, long id) {
30 | this.path = path;
31 | this.chunkBuffer = chunkBuffer;
32 | this.id = id;
33 | }
34 |
35 | public static FileChunk finalChunk(Path path) {
36 | return new FileChunk(path, null, -1);
37 | }
38 |
39 | public Path getPath() {
40 | return path;
41 | }
42 |
43 | public ByteBuf getChunkBuffer() {
44 | return chunkBuffer;
45 | }
46 |
47 | public long getId() {
48 | return id;
49 | }
50 |
51 | public boolean isFinalChunk() {
52 | return chunkBuffer == null;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/config/ConfigurationParser.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.config;
18 |
19 | import com.typesafe.config.Config;
20 | import com.typesafe.config.ConfigFactory;
21 |
22 | import java.io.File;
23 |
24 | public class ConfigurationParser {
25 | public static class Error extends RuntimeException {
26 | public Error(String message) {
27 | super(message);
28 | }
29 | }
30 |
31 | public static Config parse(File configFile) {
32 | Config config = null;
33 |
34 | if (configFile.exists() && configFile.canRead()) {
35 | config = ConfigFactory.parseFile(configFile);
36 |
37 | if (config.isEmpty()) {
38 | throw new Error("Empty configuration!");
39 | }
40 | } else {
41 | throw new Error("Configuration file " + configFile + " does not exist or is not readable!");
42 | }
43 |
44 | return config;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/utils/CollectorHostNameProvider.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.utils;
18 |
19 | import com.google.common.annotations.VisibleForTesting;
20 | import com.google.common.base.Supplier;
21 | import com.google.common.base.Suppliers;
22 |
23 | import javax.inject.Inject;
24 | import javax.inject.Provider;
25 |
26 | public class CollectorHostNameProvider implements Provider {
27 | private final Supplier hostName;
28 |
29 | @Inject
30 | public CollectorHostNameProvider(CollectorHostNameConfiguration config, CollectorId collectorId) {
31 | this(new CollectorHostNameSupplier(config.getHostName(), collectorId));
32 | }
33 |
34 | @VisibleForTesting
35 | protected CollectorHostNameProvider(CollectorHostNameSupplier supplier) {
36 | this.hostName = Suppliers.memoize(supplier);
37 | }
38 |
39 | @Override
40 | public String get() {
41 | return hostName.get();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/outputs/OutputsModule.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.outputs;
18 |
19 | import org.graylog.collector.guice.CollectorModule;
20 | import org.graylog.collector.outputs.gelf.GelfOutput;
21 | import org.graylog.collector.outputs.gelf.GelfOutputConfiguration;
22 | import org.graylog.collector.outputs.stdout.StdoutOutput;
23 | import org.graylog.collector.outputs.stdout.StdoutOutputConfiguration;
24 |
25 | public class OutputsModule extends CollectorModule {
26 | @Override
27 | protected void configure() {
28 | registerOutput("gelf",
29 | GelfOutput.class,
30 | GelfOutput.Factory.class,
31 | GelfOutputConfiguration.class,
32 | GelfOutputConfiguration.Factory.class);
33 |
34 | registerOutput("stdout",
35 | StdoutOutput.class,
36 | StdoutOutput.Factory.class,
37 | StdoutOutputConfiguration.class,
38 | StdoutOutputConfiguration.Factory.class);
39 |
40 | registerBufferConsumer(OutputRouter.class);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/utils/MemoryReporterServiceConfiguration.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.utils;
18 |
19 | import com.typesafe.config.Config;
20 |
21 | import javax.inject.Inject;
22 | import java.util.concurrent.TimeUnit;
23 |
24 | public class MemoryReporterServiceConfiguration {
25 | private long interval = 1000L;
26 | private boolean enable = false;
27 |
28 | @Inject
29 | public MemoryReporterServiceConfiguration(final Config config) {
30 | if (config.hasPath("debug")) {
31 | final Config debug = config.getConfig("debug");
32 |
33 | if (debug.hasPath("memory-reporter")) {
34 | this.enable = debug.getBoolean("memory-reporter");
35 | }
36 |
37 | if (debug.hasPath("memory-reporter-interval")) {
38 | this.interval = debug.getDuration("memory-reporter-interval", TimeUnit.MILLISECONDS);
39 | }
40 | }
41 | }
42 |
43 | public long getInterval() {
44 | return interval;
45 | }
46 |
47 | public boolean isEnable() {
48 | return enable;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/metrics/MetricServiceConfiguration.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.metrics;
18 |
19 | import com.typesafe.config.Config;
20 | import org.joda.time.Duration;
21 |
22 | import javax.inject.Inject;
23 | import java.util.concurrent.TimeUnit;
24 |
25 | public class MetricServiceConfiguration {
26 | private boolean enableLog = false;
27 | private Duration reportDuration = new Duration(60000);
28 |
29 | @Inject
30 | public MetricServiceConfiguration(Config config) {
31 | if (config.hasPath("metrics")) {
32 | final Config metrics = config.getConfig("metrics");
33 |
34 | this.enableLog = metrics.hasPath("enable-logging") && metrics.getBoolean("enable-logging");
35 |
36 | if (metrics.hasPath("log-duration")) {
37 | this.reportDuration = new Duration(metrics.getDuration("log-duration", TimeUnit.MILLISECONDS));
38 | }
39 | }
40 | }
41 |
42 | public boolean isEnableLog() {
43 | return enableLog;
44 | }
45 |
46 | public Duration getReportDuration() {
47 | return reportDuration;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/heartbeat/CollectorRegistrationRequest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.heartbeat;
18 |
19 | import com.fasterxml.jackson.annotation.JsonAutoDetect;
20 | import com.fasterxml.jackson.annotation.JsonCreator;
21 | import com.fasterxml.jackson.annotation.JsonProperty;
22 | import com.google.auto.value.AutoValue;
23 |
24 | import javax.validation.Valid;
25 | import javax.validation.constraints.NotNull;
26 | import javax.validation.constraints.Size;
27 |
28 | @AutoValue
29 | @JsonAutoDetect
30 | public abstract class CollectorRegistrationRequest {
31 | @JsonProperty("node_id")
32 | @NotNull
33 | @Size(min = 1)
34 | public abstract String nodeId();
35 |
36 | @JsonProperty("node_details")
37 | public abstract CollectorNodeDetailsSummary nodeDetails();
38 |
39 | @JsonCreator
40 | public static CollectorRegistrationRequest create(@JsonProperty("node_id") String nodeId,
41 | @JsonProperty("node_details") @Valid CollectorNodeDetailsSummary nodeDetails) {
42 | return new AutoValue_CollectorRegistrationRequest(nodeId, nodeDetails);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/test/java/org/graylog/collector/utils/CollectorHostNameConfigurationTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.utils;
18 |
19 | import com.typesafe.config.Config;
20 | import com.typesafe.config.ConfigFactory;
21 | import org.junit.Test;
22 |
23 | import java.util.Collections;
24 |
25 | import static org.junit.Assert.assertEquals;
26 | import static org.junit.Assert.assertNull;
27 |
28 | public class CollectorHostNameConfigurationTest {
29 | @Test
30 | public void getHostNameReturnsNullIfHostNameNotOverridden() {
31 | final Config config = ConfigFactory.empty();
32 | final CollectorHostNameConfiguration hostNameConfiguration = new CollectorHostNameConfiguration(config);
33 | assertNull(hostNameConfiguration.getHostName());
34 | }
35 |
36 | @Test
37 | public void getHostNameReturnsHostNameIfHostNameOverridden() {
38 | final Config config = ConfigFactory.parseMap(Collections.singletonMap("host-name", "foobar.example.net"));
39 | final CollectorHostNameConfiguration hostNameConfiguration = new CollectorHostNameConfiguration(config);
40 | assertEquals("foobar.example.net", hostNameConfiguration.getHostName());
41 | }
42 | }
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/inputs/InputsModule.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.inputs;
18 |
19 | import org.graylog.collector.guice.CollectorModule;
20 | import org.graylog.collector.inputs.eventlog.WindowsEventlogInput;
21 | import org.graylog.collector.inputs.eventlog.WindowsEventlogInputConfiguration;
22 | import org.graylog.collector.inputs.file.FileInput;
23 | import org.graylog.collector.inputs.file.FileInputConfiguration;
24 | import org.graylog.collector.utils.Utils;
25 |
26 | public class InputsModule extends CollectorModule {
27 | @Override
28 | protected void configure() {
29 | registerInput("file",
30 | FileInput.class,
31 | FileInput.Factory.class,
32 | FileInputConfiguration.class,
33 | FileInputConfiguration.Factory.class);
34 |
35 | if (Utils.isWindows()) {
36 | registerInput("windows-eventlog",
37 | WindowsEventlogInput.class,
38 | WindowsEventlogInput.Factory.class,
39 | WindowsEventlogInputConfiguration.class,
40 | WindowsEventlogInputConfiguration.Factory.class);
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/services/ServiceManagerProvider.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.services;
18 |
19 | import com.google.common.collect.ImmutableSet;
20 | import com.google.common.util.concurrent.Service;
21 | import com.google.common.util.concurrent.ServiceManager;
22 | import com.google.inject.Provider;
23 | import org.graylog.collector.config.ConfigurationRegistry;
24 |
25 | import javax.inject.Inject;
26 | import java.util.Set;
27 |
28 | public class ServiceManagerProvider implements Provider {
29 | private final Set services;
30 | private final ConfigurationRegistry configuration;
31 |
32 | @Inject
33 | public ServiceManagerProvider(Set services, ConfigurationRegistry configuration) {
34 | this.services = services;
35 | this.configuration = configuration;
36 | }
37 |
38 | @Override
39 | public ServiceManager get() {
40 | final ImmutableSet allServices = ImmutableSet.builder()
41 | .addAll(services)
42 | .addAll(configuration.getServices())
43 | .build();
44 |
45 | return new ServiceManager(allServices);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/outputs/stdout/StdoutOutputConfiguration.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.outputs.stdout;
18 |
19 | import com.google.inject.assistedinject.Assisted;
20 | import com.typesafe.config.Config;
21 | import org.graylog.collector.config.ConfigurationUtils;
22 | import org.graylog.collector.outputs.OutputConfiguration;
23 |
24 | import javax.inject.Inject;
25 |
26 | public class StdoutOutputConfiguration extends OutputConfiguration {
27 | private final StdoutOutput.Factory outputFactory;
28 |
29 | public interface Factory extends OutputConfiguration.Factory {
30 | @Override
31 | StdoutOutputConfiguration create(String id, Config config);
32 | }
33 |
34 | @Inject
35 | public StdoutOutputConfiguration(@Assisted String id,
36 | @Assisted Config output,
37 | StdoutOutput.Factory outputFactory) {
38 | super(id, output);
39 | this.outputFactory = outputFactory;
40 | }
41 |
42 | @Override
43 | public StdoutOutput createOutput() {
44 | return outputFactory.create(this);
45 | }
46 |
47 | @Override
48 | public String toString() {
49 | return ConfigurationUtils.toString(this);
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/test/java/org/graylog/collector/utils/CollectorHostNameSupplierTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.utils;
18 |
19 | import org.junit.Before;
20 | import org.junit.Test;
21 | import org.junit.runner.RunWith;
22 | import org.mockito.Mock;
23 | import org.mockito.runners.MockitoJUnitRunner;
24 |
25 | import static org.junit.Assert.assertEquals;
26 | import static org.junit.Assert.assertNotNull;
27 | import static org.mockito.Mockito.when;
28 |
29 | @RunWith(MockitoJUnitRunner.class)
30 | public class CollectorHostNameSupplierTest {
31 | @Mock
32 | public CollectorId collectorId;
33 |
34 | @Before
35 | public void setUp() throws Exception {
36 | when(collectorId.toString()).thenReturn("cafebabedeadbeef");
37 | }
38 |
39 | @Test
40 | public void getReturnsDefaultHostName() throws Exception {
41 | final CollectorHostNameSupplier supplier = new CollectorHostNameSupplier("foobar.example.net", collectorId);
42 | assertEquals("foobar.example.net", supplier.get());
43 | }
44 |
45 | @Test
46 | public void getDetectsHostNameIfDefaultIsMissing() throws Exception {
47 | final CollectorHostNameSupplier supplier = new CollectorHostNameSupplier(null, collectorId);
48 | final String hostName = supplier.get();
49 | assertNotNull(hostName);
50 | }
51 | }
--------------------------------------------------------------------------------
/src/test/java/org/graylog/collector/file/CollectingBuffer.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.file;
18 |
19 | import com.google.common.collect.Queues;
20 | import org.graylog.collector.Message;
21 | import org.graylog.collector.buffer.Buffer;
22 |
23 | import java.util.concurrent.BlockingQueue;
24 |
25 | class CollectingBuffer implements Buffer {
26 |
27 | private final BlockingQueue messages = Queues.newArrayBlockingQueue(16);
28 | private boolean outOfCapacity = false;
29 | private boolean processingDisabled = false;
30 |
31 | @Override
32 | public void insert(Message message) {
33 | messages.add(message);
34 | }
35 |
36 | @Override
37 | public Message remove() {
38 | return null;
39 | }
40 |
41 | public boolean isOutOfCapacity() {
42 | return outOfCapacity;
43 | }
44 |
45 | public void setOutOfCapacity(boolean outOfCapacity) {
46 | this.outOfCapacity = outOfCapacity;
47 | }
48 |
49 | public boolean isProcessingDisabled() {
50 | return processingDisabled;
51 | }
52 |
53 | public void setProcessingDisabled(boolean processingDisabled) {
54 | this.processingDisabled = processingDisabled;
55 | }
56 |
57 | public BlockingQueue getMessageQueue() {
58 | return messages;
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/services/CollectorServiceManager.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.services;
18 |
19 | import com.google.common.collect.ImmutableMultimap;
20 | import com.google.common.util.concurrent.Service;
21 | import com.google.common.util.concurrent.ServiceManager;
22 | import org.graylog.collector.config.ConfigurationRegistry;
23 |
24 | import javax.inject.Inject;
25 |
26 | public class CollectorServiceManager {
27 | private final ServiceManager serviceManager;
28 | private final ConfigurationRegistry configuration;
29 |
30 | @Inject
31 | public CollectorServiceManager(ServiceManager serviceManager, ConfigurationRegistry configuration) {
32 | this.serviceManager = serviceManager;
33 | this.configuration = configuration;
34 | }
35 |
36 | public ConfigurationRegistry getConfiguration() {
37 | return configuration;
38 | }
39 |
40 | public void start() {
41 | serviceManager.startAsync().awaitHealthy();
42 | }
43 |
44 | public void stop() {
45 | serviceManager.stopAsync().awaitStopped();
46 | }
47 |
48 | public void awaitStopped() {
49 | serviceManager.awaitStopped();
50 | }
51 |
52 | public ImmutableMultimap servicesByState() {
53 | return serviceManager.servicesByState();
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/serverapi/RestAdapterProvider.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.serverapi;
18 |
19 | import com.fasterxml.jackson.databind.ObjectMapper;
20 | import org.graylog.collector.CollectorVersion;
21 | import org.graylog.collector.annotations.GraylogServerURL;
22 | import retrofit.RequestInterceptor;
23 | import retrofit.RestAdapter;
24 | import retrofit.converter.JacksonConverter;
25 |
26 | import javax.inject.Inject;
27 | import javax.inject.Provider;
28 |
29 | public class RestAdapterProvider implements Provider {
30 | private final String graylogServerURL;
31 |
32 | @Inject
33 | public RestAdapterProvider(@GraylogServerURL String graylogServerURL) {
34 | this.graylogServerURL = graylogServerURL;
35 | }
36 |
37 | @Override
38 | public RestAdapter get() {
39 | return new RestAdapter.Builder()
40 | .setEndpoint(graylogServerURL)
41 | .setConverter(new JacksonConverter(new ObjectMapper()))
42 | .setRequestInterceptor(new RequestInterceptor() {
43 | @Override
44 | public void intercept(RequestFacade request) {
45 | request.addHeader("User-Agent", "Graylog Collector " + CollectorVersion.CURRENT);
46 | request.addHeader("X-Graylog-Collector-Version", CollectorVersion.CURRENT.version());
47 | }
48 | })
49 | .build();
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/config/ConfigurationUtils.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.config;
18 |
19 | import com.google.common.base.Function;
20 | import com.google.common.base.Joiner;
21 | import com.google.common.collect.Iterables;
22 |
23 | import javax.annotation.Nullable;
24 | import java.util.Locale;
25 | import java.util.Map;
26 |
27 | public class ConfigurationUtils {
28 | public static String toString(Configuration configurationObject) {
29 | return toString(configurationObject, configurationObject);
30 | }
31 |
32 | public static String toString(Configuration configurationObject, Object nameClass) {
33 | final Map values = configurationObject.toStringValues();
34 | final Iterable strings = Iterables.transform(values.entrySet(), new Function, String>() {
35 | @Nullable
36 | @Override
37 | public String apply(@Nullable Map.Entry input) {
38 | if (input == null) {
39 | return "";
40 | }
41 | return String.format(Locale.getDefault(), "%s='%s'", input.getKey(), input.getValue());
42 | }
43 | });
44 |
45 | final StringBuffer sb = new StringBuffer(nameClass.getClass().getSimpleName());
46 | sb.append('{');
47 | sb.append(Joiner.on(", ").join(strings));
48 | sb.append('}');
49 |
50 | return sb.toString();
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/config/constraints/IsOneOfValidator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.config.constraints;
18 |
19 | import com.google.common.base.Joiner;
20 | import org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext;
21 |
22 | import javax.validation.ConstraintValidator;
23 | import javax.validation.ConstraintValidatorContext;
24 | import java.util.Arrays;
25 |
26 | public class IsOneOfValidator implements ConstraintValidator {
27 | private String[] strings;
28 |
29 | @Override
30 | public void initialize(IsOneOf constraintAnnotation) {
31 | this.strings = constraintAnnotation.value();
32 | }
33 |
34 | @Override
35 | public boolean isValid(String value, ConstraintValidatorContext context) {
36 | if (value == null) {
37 | return true;
38 | }
39 | final boolean valid = Arrays.asList(strings).contains(value);
40 |
41 | if (!valid) {
42 | HibernateConstraintValidatorContext hibernateContext = context.unwrap(HibernateConstraintValidatorContext.class);
43 | hibernateContext.disableDefaultConstraintViolation();
44 |
45 | hibernateContext.addExpressionVariable("validValues", Joiner.on(" ").join(strings))
46 | .buildConstraintViolationWithTemplate(hibernateContext.getDefaultConstraintMessageTemplate())
47 | .addConstraintViolation();
48 | }
49 |
50 | return valid;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/org/graylog/collector/config/ConfigurationValidator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Graylog.
3 | *
4 | * Graylog is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Graylog is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Graylog. If not, see .
16 | */
17 | package org.graylog.collector.config;
18 |
19 | import com.google.common.collect.Lists;
20 |
21 | import javax.validation.ConstraintViolation;
22 | import javax.validation.Validation;
23 | import javax.validation.Validator;
24 | import java.util.Collections;
25 | import java.util.List;
26 | import java.util.Locale;
27 | import java.util.Set;
28 |
29 | public class ConfigurationValidator {
30 | private static final Validator VALIDATOR = Validation.buildDefaultValidatorFactory().getValidator();
31 |
32 | private final List errors = Lists.newArrayList();
33 |
34 | public boolean isValid(Configuration configuration) {
35 | return doValidate(configuration);
36 | }
37 |
38 | private boolean doValidate(Object obj) {
39 | final Set> constraintViolations = VALIDATOR.validate(obj);
40 |
41 | if (constraintViolations.size() > 0) {
42 | for (ConstraintViolation