mirror of
https://github.com/Febbweiss/logstash-forwarder-java.git
synced 2026-03-05 06:35:44 +00:00
Implementation of config file loading.
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package info.fetter.logstashforwarder.config;
|
||||
|
||||
import static org.apache.log4j.Level.DEBUG;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.log4j.BasicConfigurator;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.spi.RootLogger;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
|
||||
public class ConfigurationManagerTest {
|
||||
Logger logger = Logger.getLogger(ConfigurationManagerTest.class);
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
BasicConfigurator.configure();
|
||||
RootLogger.getRootLogger().setLevel(DEBUG);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception {
|
||||
BasicConfigurator.resetConfiguration();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadConfig1() throws JsonParseException, JsonMappingException, IOException {
|
||||
ConfigurationManager manager = new ConfigurationManager(new File(ConfigurationManagerTest.class.getClassLoader().getResource("config1.json").getFile()));
|
||||
manager.readConfiguration();
|
||||
logger.debug(manager.getConfig().toString());
|
||||
}
|
||||
}
|
||||
52
src/test/resources/config1.json
Normal file
52
src/test/resources/config1.json
Normal file
@@ -0,0 +1,52 @@
|
||||
{
|
||||
// The network section covers network configuration :)
|
||||
"network": {
|
||||
// A list of downstream servers listening for our messages.
|
||||
// logstash-forwarder will pick one at random and only switch if
|
||||
// the selected one appears to be dead or unresponsive
|
||||
"servers": [ "localhost:5043" ],
|
||||
|
||||
// The path to your client ssl certificate (optional)
|
||||
"ssl certificate": "./logstash-forwarder.crt",
|
||||
// The path to your client ssl key (optional)
|
||||
"ssl key": "./logstash-forwarder.key",
|
||||
|
||||
// The path to your trusted ssl CA file. This is used
|
||||
// to authenticate your downstream server.
|
||||
"ssl ca": "./logstash-forwarder.crt",
|
||||
|
||||
// Network timeout in seconds. This is most important for
|
||||
// logstash-forwarder determining whether to stop waiting for an
|
||||
// acknowledgement from the downstream server. If an timeout is reached,
|
||||
// logstash-forwarder will assume the connection or server is bad and
|
||||
// will connect to a server chosen at random from the servers list.
|
||||
"timeout": 15
|
||||
},
|
||||
|
||||
// The list of files configurations
|
||||
"files": [
|
||||
// An array of hashes. Each hash tells what paths to watch and
|
||||
// what fields to annotate on events from those paths.
|
||||
{
|
||||
"paths": [
|
||||
// single paths are fine
|
||||
"/var/log/messages",
|
||||
// globs are fine too, they will be periodically evaluated
|
||||
// to see if any new files match the wildcard.
|
||||
"/var/log/*.log"
|
||||
],
|
||||
|
||||
// A dictionary of fields to annotate on each event.
|
||||
"fields": { "type": "syslog" }
|
||||
}, {
|
||||
// A path of "-" means stdin.
|
||||
"paths": [ "-" ],
|
||||
"fields": { "type": "stdin" }
|
||||
}, {
|
||||
"paths": [
|
||||
"/var/log/apache/httpd-*.log"
|
||||
],
|
||||
"fields": { "type": "apache" }
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user