Search in sources :

Example 1 with PtrDnsAnswer

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();
}
Also used : LookupResult(org.graylog2.plugin.lookup.LookupResult) PtrDnsAnswer(org.graylog2.lookup.adapters.dnslookup.PtrDnsAnswer) UnknownHostException(java.net.UnknownHostException) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

UnknownHostException (java.net.UnknownHostException)1 LinkedHashMap (java.util.LinkedHashMap)1 PtrDnsAnswer (org.graylog2.lookup.adapters.dnslookup.PtrDnsAnswer)1 LookupResult (org.graylog2.plugin.lookup.LookupResult)1