use of org.graylog2.lookup.adapters.dnslookup.PtrDnsAnswer in project graylog2-server by Graylog2.
the class DnsLookupDataAdapter method performReverseLookup.
private LookupResult performReverseLookup(Object key) {
final PtrDnsAnswer dnsResponse;
try {
dnsResponse = dnsClient.reverseLookup(key.toString());
} catch (Exception e) {
LOG.error("Could not perform reverse DNS lookup for [{}]. Cause [{}]", key, ExceptionUtils.getRootCauseOrMessage(e));
errorCounter.inc();
return getErrorResult();
}
if (dnsResponse != null) {
if (!Strings.isNullOrEmpty(dnsResponse.fullDomain())) {
// Include answer in both single and multiValue fields.
final Map<Object, Object> multiValueResults = new LinkedHashMap<>();
multiValueResults.put(PtrDnsAnswer.FIELD_DOMAIN, dnsResponse.domain());
multiValueResults.put(PtrDnsAnswer.FIELD_FULL_DOMAIN, dnsResponse.fullDomain());
multiValueResults.put(PtrDnsAnswer.FIELD_DNS_TTL, dnsResponse.dnsTTL());
final LookupResult.Builder builder = LookupResult.builder().single(dnsResponse.fullDomain()).multiValue(multiValueResults).stringListValue(ImmutableList.of(dnsResponse.fullDomain()));
if (config.hasOverrideTTL()) {
builder.cacheTTL(config.getCacheTTLOverrideMillis());
} else {
builder.cacheTTL(dnsResponse.dnsTTL() * 1000);
}
return builder.build();
}
}
LOG.debug("Could not perform reverse lookup on IP address [{}]. No PTR record was found.", key);
return getEmptyResult();
}
Aggregations