use of org.graylog2.plugin.ResolvableInetSocketAddress in project graylog2-server by Graylog2.
the class SyslogCodec method decode.
@Nullable
@Override
public Message decode(@Nonnull RawMessage rawMessage) {
final String msg = new String(rawMessage.getPayload(), StandardCharsets.UTF_8);
try (Timer.Context ignored = this.decodeTime.time()) {
final ResolvableInetSocketAddress address = rawMessage.getRemoteAddress();
final InetSocketAddress remoteAddress;
if (address == null) {
remoteAddress = null;
} else {
remoteAddress = address.getInetSocketAddress();
}
return parse(msg, remoteAddress == null ? null : remoteAddress.getAddress(), rawMessage.getTimestamp());
}
}
use of org.graylog2.plugin.ResolvableInetSocketAddress in project graylog2-server by Graylog2.
the class RawMessage method getRemoteAddress.
@Nullable
public ResolvableInetSocketAddress getRemoteAddress() {
if (msgBuilder.hasRemote()) {
final JournalMessages.RemoteAddress address = msgBuilder.getRemote();
final InetAddress inetAddr;
try {
inetAddr = InetAddress.getByAddress(address.getResolved(), address.getAddress().toByteArray());
} catch (UnknownHostException e) {
log.warn("Malformed InetAddress for message {}, expected 4 or 16 bytes, but got {} bytes", id, address.getAddress().toByteArray());
return null;
}
final int port = address.hasPort() ? address.getPort() : 0;
// TODO PERFORMANCE object creation
return ResolvableInetSocketAddress.wrap(new InetSocketAddress(inetAddr, port));
}
return null;
}
use of org.graylog2.plugin.ResolvableInetSocketAddress in project graylog2-server by Graylog2.
the class ResolvableInetSocketAddressTest method testReverseLookup.
@Test
@SuppressForbidden("Intentional invocation of InetSocketAddress#getHostName()")
public void testReverseLookup() throws Exception {
final InetSocketAddress inetSocketAddress = new InetSocketAddress(Inet4Address.getLoopbackAddress(), 12345);
final ResolvableInetSocketAddress address = new ResolvableInetSocketAddress(inetSocketAddress);
assertThat(address.isReverseLookedUp()).isFalse();
assertThat(address.reverseLookup()).isEqualTo(inetSocketAddress.getHostName());
assertThat(address.isReverseLookedUp()).isTrue();
}
use of org.graylog2.plugin.ResolvableInetSocketAddress in project graylog2-server by Graylog2.
the class ResolvableInetSocketAddressTest method testGetHostName.
@Test
@SuppressForbidden("Intentional invocation of InetSocketAddress#getHostName()")
public void testGetHostName() throws Exception {
final InetSocketAddress inetSocketAddress = new InetSocketAddress(Inet4Address.getLoopbackAddress(), 12345);
final ResolvableInetSocketAddress address = new ResolvableInetSocketAddress(inetSocketAddress);
assertThat(address.getHostName()).isNull();
address.reverseLookup();
assertThat(address.getHostName()).isEqualTo(inetSocketAddress.getHostName());
}
use of org.graylog2.plugin.ResolvableInetSocketAddress in project graylog2-server by Graylog2.
the class DecodingProcessor method postProcessMessage.
@Nullable
private Message postProcessMessage(RawMessage raw, Codec codec, String inputIdOnCurrentNode, String baseMetricName, Message message, long decodeTime) {
if (message == null) {
metricRegistry.meter(name(baseMetricName, "failures")).mark();
return null;
}
if (!message.isComplete()) {
metricRegistry.meter(name(baseMetricName, "incomplete")).mark();
if (LOG.isDebugEnabled()) {
LOG.debug("Dropping incomplete message {} on input <{}>. Parsed fields: [{}]", raw, inputIdOnCurrentNode, message.getFields());
}
return null;
}
message.setJournalOffset(raw.getJournalOffset());
message.recordTiming(serverStatus, "parse", decodeTime);
metricRegistry.timer(name(baseMetricName, "parseTime")).update(decodeTime, TimeUnit.NANOSECONDS);
for (final RawMessage.SourceNode node : raw.getSourceNodes()) {
switch(node.type) {
case SERVER:
// Always use the last source node.
if (message.getField("gl2_source_input") != null) {
LOG.debug("Multiple server nodes ({} {}) set for message id {}", message.getField("gl2_source_input"), node.nodeId, message.getId());
}
message.addField("gl2_source_input", node.inputId);
message.addField("gl2_source_node", node.nodeId);
break;
// TODO Due to be removed in Graylog 3.x
case RADIO:
// Always use the last source node.
if (message.getField("gl2_source_radio_input") != null) {
LOG.debug("Multiple radio nodes ({} {}) set for message id {}", message.getField("gl2_source_radio_input"), node.nodeId, message.getId());
}
message.addField("gl2_source_radio_input", node.inputId);
message.addField("gl2_source_radio", node.nodeId);
break;
}
}
if (inputIdOnCurrentNode != null) {
try {
message.setSourceInputId(inputIdOnCurrentNode);
} catch (RuntimeException e) {
LOG.warn("Unable to find input with id " + inputIdOnCurrentNode + ", not setting input id in this message.", e);
}
}
final ResolvableInetSocketAddress remoteAddress = raw.getRemoteAddress();
if (remoteAddress != null) {
final String addrString = InetAddresses.toAddrString(remoteAddress.getAddress());
message.addField("gl2_remote_ip", addrString);
if (remoteAddress.getPort() > 0) {
message.addField("gl2_remote_port", remoteAddress.getPort());
}
if (remoteAddress.isReverseLookedUp()) {
// avoid reverse lookup if the hostname is available
message.addField("gl2_remote_hostname", remoteAddress.getHostName());
}
if (Strings.isNullOrEmpty(message.getSource())) {
message.setSource(addrString);
}
}
if (codec.getConfiguration() != null && codec.getConfiguration().stringIsSet(Codec.Config.CK_OVERRIDE_SOURCE)) {
message.setSource(codec.getConfiguration().getString(Codec.Config.CK_OVERRIDE_SOURCE));
}
// Make sure that there is a value for the source field.
if (Strings.isNullOrEmpty(message.getSource())) {
message.setSource("unknown");
}
metricRegistry.meter(name(baseMetricName, "processedMessages")).mark();
return message;
}
Aggregations