org.graylog.plugins.threatintel.whois.ip.WhoisDataAdapter Maven / Gradle / Ivy
/*
* Copyright (C) 2020 Graylog, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* .
*/
package org.graylog.plugins.threatintel.whois.ip;
import com.codahale.metrics.MetricRegistry;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Multimap;
import com.google.inject.assistedinject.Assisted;
import org.graylog.autovalue.WithBeanGetter;
import org.graylog2.plugin.lookup.LookupCachePurge;
import org.graylog2.plugin.lookup.LookupDataAdapter;
import org.graylog2.plugin.lookup.LookupDataAdapterConfiguration;
import org.graylog2.plugin.lookup.LookupResult;
import org.joda.time.Duration;
import javax.inject.Inject;
import java.util.Map;
import java.util.Optional;
public class WhoisDataAdapter extends LookupDataAdapter {
public static final String NAME = "whois";
public static final String ORGANIZATION_FIELD = "organization";
public static final String COUNTRY_CODE_FIELD = "country_code";
private final WhoisIpLookup whoisIpLookup;
@Inject
public WhoisDataAdapter(@Assisted("id") String id,
@Assisted("name") String name,
@Assisted LookupDataAdapterConfiguration config,
MetricRegistry metricRegistry) {
super(id, name, config, metricRegistry);
this.whoisIpLookup = new WhoisIpLookup((Config) config, metricRegistry);
}
@Override
protected void doStart() throws Exception {
}
@Override
protected void doStop() throws Exception {
}
@Override
public Duration refreshInterval() {
return Duration.ZERO;
}
@Override
protected void doRefresh(LookupCachePurge cachePurge) throws Exception {
}
@Override
protected LookupResult doGet(Object key) {
try {
final WhoisIpLookupResult result = this.whoisIpLookup.run(key.toString());
if (!WhoisIpLookupResult.empty().equals(result)) {
final Map
© 2015 - 2024 Weber Informatics LLC | Privacy Policy