Search in sources :

Example 6 with IspResponse

use of com.maxmind.geoip2.model.IspResponse in project nifi by apache.

the class TestISPEnrichIP method evaluatingExpressionLanguageShouldAndFindingIpFieldWithSuccessfulLookUpShouldFlowToFoundRelationship.

@Test
public void evaluatingExpressionLanguageShouldAndFindingIpFieldWithSuccessfulLookUpShouldFlowToFoundRelationship() throws Exception {
    testRunner.setProperty(ISPEnrichIP.GEO_DATABASE_FILE, "./");
    testRunner.setProperty(ISPEnrichIP.IP_ADDRESS_ATTRIBUTE, "${ip.fields:substringBefore(',')}");
    final IspResponse ispResponse = getIspResponse();
    when(databaseReader.isp(InetAddress.getByName("1.2.3.4"))).thenReturn(ispResponse);
    final Map<String, String> attributes = new HashMap<>();
    attributes.put("ip.fields", "ip0,ip1,ip2");
    attributes.put("ip0", "1.2.3.4");
    testRunner.enqueue(new byte[0], attributes);
    testRunner.run();
    List<MockFlowFile> notFound = testRunner.getFlowFilesForRelationship(ISPEnrichIP.REL_NOT_FOUND);
    List<MockFlowFile> found = testRunner.getFlowFilesForRelationship(ISPEnrichIP.REL_FOUND);
    assertEquals(0, notFound.size());
    assertEquals(1, found.size());
    FlowFile finishedFound = found.get(0);
    assertNotNull(finishedFound.getAttribute("ip0.isp.lookup.micros"));
    assertEquals("Apache NiFi - Test ISP", finishedFound.getAttribute("ip0.isp.name"));
    assertEquals("Apache NiFi - Test Organization", finishedFound.getAttribute("ip0.isp.organization"));
    assertEquals("1337", finishedFound.getAttribute("ip0.isp.asn"));
    assertEquals("Apache NiFi - Test Chocolate", finishedFound.getAttribute("ip0.isp.asn.organization"));
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) IspResponse(com.maxmind.geoip2.model.IspResponse) FlowFile(org.apache.nifi.flowfile.FlowFile) MockFlowFile(org.apache.nifi.util.MockFlowFile) HashMap(java.util.HashMap) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with IspResponse

use of com.maxmind.geoip2.model.IspResponse in project nutch by apache.

the class GeoIPDocumentCreator method createDocFromIspDb.

public static NutchDocument createDocFromIspDb(String serverIp, NutchDocument doc, DatabaseReader reader) throws UnknownHostException, IOException, GeoIp2Exception {
    IspResponse response = reader.isp(InetAddress.getByName(serverIp));
    doc.add("ip", serverIp);
    doc.add("autonSystemNum", response.getAutonomousSystemNumber());
    doc.add("autonSystemOrg", response.getAutonomousSystemOrganization());
    doc.add("isp", response.getIsp());
    doc.add("org", response.getOrganization());
    return doc;
}
Also used : IspResponse(com.maxmind.geoip2.model.IspResponse)

Example 8 with IspResponse

use of com.maxmind.geoip2.model.IspResponse in project XRTB by benmfaul.

the class MMDB method solve.

public String solve(String key) {
    String value = null;
    try {
        String[] parts = key.split("/");
        if (parts.length < 3)
            return null;
        String sip = parts[2];
        InetAddress ip = InetAddress.getByName(sip);
        IspResponse r = reader.isp(ip);
        switch(parts[1]) {
            case "org":
                return r.getOrganization();
            case "isp":
                return r.getIsp();
            case "json":
                return r.toJson();
            default:
                return null;
        }
    } catch (Exception e) {
    }
    return value;
}
Also used : IspResponse(com.maxmind.geoip2.model.IspResponse) InetAddress(java.net.InetAddress)

Aggregations

IspResponse (com.maxmind.geoip2.model.IspResponse)8 InetAddress (java.net.InetAddress)4 HashMap (java.util.HashMap)4 FlowFile (org.apache.nifi.flowfile.FlowFile)4 MockFlowFile (org.apache.nifi.util.MockFlowFile)3 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 IOException (java.io.IOException)2 InvalidDatabaseException (com.maxmind.db.InvalidDatabaseException)1 GeoIp2Exception (com.maxmind.geoip2.exception.GeoIp2Exception)1 AnonymousIpResponse (com.maxmind.geoip2.model.AnonymousIpResponse)1 CityResponse (com.maxmind.geoip2.model.CityResponse)1 ConnectionTypeResponse (com.maxmind.geoip2.model.ConnectionTypeResponse)1 ConnectionType (com.maxmind.geoip2.model.ConnectionTypeResponse.ConnectionType)1 DomainResponse (com.maxmind.geoip2.model.DomainResponse)1 LookupFailureException (org.apache.nifi.lookup.LookupFailureException)1 DatabaseReader (org.apache.nifi.processors.maxmind.DatabaseReader)1 MapRecord (org.apache.nifi.serialization.record.MapRecord)1 Record (org.apache.nifi.serialization.record.Record)1 StopWatch (org.apache.nifi.util.StopWatch)1