|
1 | 1 | package com.wizecore.graylog2.plugin; |
2 | 2 |
|
3 | 3 |
|
4 | | -import java.util.List; |
5 | | -import java.util.Map; |
6 | | -import java.util.HashMap; |
7 | | -import java.util.logging.Logger; |
8 | | - |
9 | | -import javax.inject.Inject; |
10 | | - |
| 4 | +import com.google.common.collect.ImmutableMap; |
| 5 | +import com.google.inject.assistedinject.Assisted; |
11 | 6 | import org.graylog2.plugin.Message; |
12 | 7 | import org.graylog2.plugin.configuration.Configuration; |
13 | 8 | import org.graylog2.plugin.configuration.ConfigurationRequest; |
| 9 | +import org.graylog2.plugin.configuration.fields.BooleanField; |
14 | 10 | import org.graylog2.plugin.configuration.fields.ConfigurationField; |
15 | 11 | import org.graylog2.plugin.configuration.fields.DropdownField; |
16 | 12 | import org.graylog2.plugin.configuration.fields.TextField; |
17 | | -import org.graylog2.plugin.configuration.fields.BooleanField; |
18 | 13 | import org.graylog2.plugin.outputs.MessageOutput; |
19 | 14 | import org.graylog2.plugin.streams.Stream; |
20 | 15 | import org.graylog2.syslog4j.Syslog; |
21 | 16 | import org.graylog2.syslog4j.SyslogConfigIF; |
22 | 17 | import org.graylog2.syslog4j.SyslogIF; |
| 18 | +import org.graylog2.syslog4j.impl.message.processor.SyslogMessageProcessor; |
23 | 19 | import org.graylog2.syslog4j.impl.net.tcp.TCPNetSyslogConfig; |
24 | 20 | import org.graylog2.syslog4j.impl.net.tcp.ssl.SSLTCPNetSyslogConfig; |
25 | 21 | import org.graylog2.syslog4j.impl.net.udp.UDPNetSyslogConfig; |
26 | | -import org.graylog2.syslog4j.server.impl.net.tcp.ssl.SSLTCPNetSyslogServerConfig; |
27 | 22 |
|
28 | | -import com.google.common.collect.ImmutableMap; |
29 | | -import com.google.inject.assistedinject.Assisted; |
| 23 | +import javax.inject.Inject; |
| 24 | +import java.util.Date; |
| 25 | +import java.util.HashMap; |
| 26 | +import java.util.List; |
| 27 | +import java.util.Map; |
| 28 | +import java.util.logging.Logger; |
30 | 29 |
|
31 | 30 |
|
32 | 31 | /** |
@@ -54,7 +53,7 @@ public static MessageSender createSender(String fmt, Configuration conf) { |
54 | 53 | return new PlainSender(); |
55 | 54 | } else |
56 | 55 | if (fmt == null || fmt.equalsIgnoreCase("transparent")) { |
57 | | - return new TrasparentSyslogSender(conf); |
| 56 | + return new TransparentSyslogSender(conf); |
58 | 57 | } else |
59 | 58 | if (fmt == null || fmt.equalsIgnoreCase("snare")) { |
60 | 59 | return new SnareWindowsSender(); |
@@ -144,11 +143,26 @@ public SyslogOutput(@Assisted Stream stream, @Assisted Configuration conf) { |
144 | 143 | syslog = Syslog.exists(hash) ? Syslog.getInstance(hash) : Syslog.createInstance(hash, config); |
145 | 144 |
|
146 | 145 | sender = createSender(format, conf); |
| 146 | + |
| 147 | + if (sender instanceof TransparentSyslogSender) { |
| 148 | + // Always send empty header, which we will construct ourselves |
| 149 | + syslog.setMessageProcessor(new SyslogMessageProcessor() { |
| 150 | + @Override |
| 151 | + public String createSyslogHeader(int facility, int level, String localName, boolean sendLocalName, Date datetime) { |
| 152 | + return ""; |
| 153 | + } |
| 154 | + |
| 155 | + @Override |
| 156 | + public String createSyslogHeader(int facility, int level, String localName, boolean sendLocalTimestamp, boolean sendLocalName) { |
| 157 | + return ""; |
| 158 | + } |
| 159 | + }); |
| 160 | + } |
| 161 | + |
147 | 162 | if (sender instanceof StructuredSender) { |
148 | 163 | // Always send via structured data |
149 | 164 | syslog.getConfig().setUseStructuredData(true); |
150 | | - } else |
151 | | - if (sender instanceof PlainSender || sender instanceof CEFSender) { |
| 165 | + } else if (sender instanceof PlainSender || sender instanceof CEFSender) { |
152 | 166 | // Will write this fields manually |
153 | 167 | syslog.getConfig().setSendLocalName(false); |
154 | 168 | syslog.getConfig().setSendLocalTimestamp(false); |
@@ -255,30 +269,30 @@ public ConfigurationRequest getRequestedConfiguration() { |
255 | 269 | configurationRequest.addField(new TextField("host", "Syslog host", "localhost", "Remote host to send syslog messages to.", ConfigurationField.Optional.NOT_OPTIONAL)); |
256 | 270 | configurationRequest.addField(new TextField("port", "Syslog port", "514", "Syslog port on the remote host. Default is 514.", ConfigurationField.Optional.NOT_OPTIONAL)); |
257 | 271 |
|
258 | | - HashMap<String, String> types = new HashMap<String,String>(); |
259 | | - types.put("plain", "plain"); |
260 | | - types.put("structured", "structured"); |
261 | | - types.put("cef", "cef"); |
262 | | - types.put("full", "full"); |
263 | | - types.put("transparent", "transparent"); |
264 | | - types.put("snare", "snare"); |
| 272 | + HashMap<String, String> types = new HashMap<String, String>(); |
| 273 | + types.put("plain", "plain"); |
| 274 | + types.put("structured", "structured"); |
| 275 | + types.put("cef", "cef"); |
| 276 | + types.put("full", "full"); |
| 277 | + types.put("transparent", "transparent"); |
| 278 | + types.put("snare", "snare"); |
265 | 279 |
|
266 | 280 | final Map<String, String> formats = ImmutableMap.copyOf(types); |
267 | 281 | configurationRequest.addField(new DropdownField( |
268 | 282 | "format", "Message format", "plain", formats, |
269 | 283 | "Message format. For detailed explanation, see https://github.com/wizecore/graylog2-output-syslog", |
270 | 284 | ConfigurationField.Optional.NOT_OPTIONAL) |
271 | 285 | ); |
272 | | - configurationRequest.addField(new BooleanField("transparentFormatRemoveHeader", "Remove header (only for transparent)", false, "Do not insert timestamp header when it forwards the message content.")); |
| 286 | + configurationRequest.addField(new BooleanField("transparentFormatRemoveHeader", "Remove header (only for transparent)", false, "Do not insert header when it forwards the message content.")); |
273 | 287 |
|
274 | 288 | configurationRequest.addField(new TextField("maxlen", "Maximum message length", "", "Maximum message (body) length. Longer messages will be truncated. If not specified defaults to 16384 bytes.", ConfigurationField.Optional.OPTIONAL)); |
275 | | - |
| 289 | + |
276 | 290 | configurationRequest.addField(new TextField("keystore", "Key store", "", "Path to Java keystore (required for SSL over TCP). Must contain private key and cert for this client.", ConfigurationField.Optional.OPTIONAL)); |
277 | 291 | configurationRequest.addField(new TextField("keystorePassword", "Key store password", "", "", ConfigurationField.Optional.OPTIONAL)); |
278 | | - |
| 292 | + |
279 | 293 | configurationRequest.addField(new TextField("truststore", "Trust store", "", "Path to Java keystore (required for SSL over TCP). Optional (if not set, equals to key store). Must contain peers we trust connecting to.", ConfigurationField.Optional.OPTIONAL)); |
280 | 294 | configurationRequest.addField(new TextField("truststorePassword", "Trust store password", "", "", ConfigurationField.Optional.OPTIONAL)); |
281 | | - |
| 295 | + |
282 | 296 | return configurationRequest; |
283 | 297 | } |
284 | 298 | } |
|
0 commit comments