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"));
}
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;
}
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;
}
Aggregations