private Record createRecord(final AnonymousIpResponse anonymousIp) { if (anonymousIp == null) { return null; } final Map<String, Object> values = new HashMap<>(5); values.put(AnonymousIpSchema.ANONYMOUS.getFieldName(), anonymousIp.isAnonymous()); values.put(AnonymousIpSchema.ANONYMOUS_VPN.getFieldName(), anonymousIp.isAnonymousVpn()); values.put(AnonymousIpSchema.HOSTING_PROVIDER.getFieldName(), anonymousIp.isHostingProvider()); values.put(AnonymousIpSchema.PUBLIC_PROXY.getFieldName(), anonymousIp.isPublicProxy()); values.put(AnonymousIpSchema.TOR_EXIT_NODE.getFieldName(), anonymousIp.isTorExitNode()); return new MapRecord(AnonymousIpSchema.ANONYMOUS_IP_SCHEMA, values); }
private Record createRecord(final IspResponse isp) { if (isp == null) { return null; } final Map<String, Object> values = new HashMap<>(4); values.put(IspSchema.ASN.getFieldName(), isp.getAutonomousSystemNumber()); values.put(IspSchema.ASN_ORG.getFieldName(), isp.getAutonomousSystemOrganization()); values.put(IspSchema.NAME.getFieldName(), isp.getIsp()); values.put(IspSchema.ORG.getFieldName(), isp.getOrganization()); return new MapRecord(IspSchema.ISP_SCHEMA, values); }
final Location location = city.getLocation(); final Map<Object, Object> map = new HashMap<>(); map.put("city", city.getCity()); map.put("continent", city.getContinent()); map.put("country", city.getCountry()); map.put("location", location); map.put("postal", city.getPostal()); map.put("registered_country", city.getRegisteredCountry()); map.put("represented_country", city.getRepresentedCountry()); map.put("subdivisions", city.getSubdivisions()); map.put("traits", city.getTraits()); final Country country = countryResponse.getCountry(); final Map<Object, Object> map = new HashMap<>(); map.put("continent", countryResponse.getContinent()); map.put("country", country); map.put("registered_country", countryResponse.getRegisteredCountry()); map.put("represented_country", countryResponse.getRepresentedCountry()); map.put("traits", countryResponse.getTraits());
private Record createRecord(final CityResponse city) { if (city == null) { return null; } final Map<String, Object> values = new HashMap<>(); values.put(CitySchema.CITY.getFieldName(), city.getCity().getName()); final Location location = city.getLocation(); values.put(CitySchema.ACCURACY.getFieldName(), location.getAccuracyRadius()); values.put(CitySchema.METRO_CODE.getFieldName(), location.getMetroCode()); values.put(CitySchema.TIMEZONE.getFieldName(), location.getTimeZone()); values.put(CitySchema.LATITUDE.getFieldName(), location.getLatitude()); values.put(CitySchema.LONGITUDE.getFieldName(), location.getLongitude()); values.put(CitySchema.CONTINENT.getFieldName(), city.getContinent().getName()); values.put(CitySchema.POSTALCODE.getFieldName(), city.getPostal().getCode()); values.put(CitySchema.COUNTRY.getFieldName(), createRecord(city.getCountry())); final Object[] subdivisions = new Object[city.getSubdivisions().size()]; int i = 0; for (final Subdivision subdivision : city.getSubdivisions()) { subdivisions[i++] = createRecord(subdivision); } values.put(CitySchema.SUBDIVISIONS.getFieldName(), subdivisions); return new MapRecord(CitySchema.GEO_SCHEMA, values); }
private GeoInfo _getGeoInfo(String ipAddress) { GeoInfo geoInfo = new GeoInfo(); if (ipAddress == null) { return geoInfo; } try{ InetAddress inetAddress = InetAddress.getByName(ipAddress); CityResponse response = reader.city(inetAddress); Country country = response.getCountry(); Continent continent = response.getContinent(); City city = response.getCity(); Postal postal = response.getPostal(); Location location = response.getLocation(); Subdivision subdivision = response.getMostSpecificSubdivision(); geoInfo.setRegion(subdivision.getName()); geoInfo.setCountryIsoCode(country.getIsoCode()); geoInfo.setCountry(country.getName()); geoInfo.setContinent(continent.getCode()); geoInfo.setCity(city.getName()); geoInfo.setPostalCode(postal.getCode()); geoInfo.setLatitude(location.getLatitude()); geoInfo.setLongitude(location.getLongitude()); return geoInfo; } catch(Exception ex){ return null; } }
@VisibleForTesting Optional<GeoLocationInformation> extractGeoLocationInformation(Object fieldValue) { final InetAddress ipAddress; if (fieldValue instanceof InetAddress) { ipAddress = (InetAddress) fieldValue; } else if (fieldValue instanceof String) { ipAddress = getIpFromFieldValue((String) fieldValue); } else { ipAddress = null; } GeoLocationInformation geoLocationInformation = null; if (ipAddress != null) { try (Timer.Context ignored = resolveTime.time()) { final CityResponse response = databaseReader.city(ipAddress); final Location location = response.getLocation(); final Country country = response.getCountry(); final City city = response.getCity(); geoLocationInformation = GeoLocationInformation.create( location.getLatitude(), location.getLongitude(), country.getGeoNameId() != null ? country.getIsoCode() : "N/A", city.getGeoNameId() != null ? city.getName() : "N/A" // calling to .getName() may throw a NPE ); } catch (Exception e) { LOG.debug("Could not get location from IP {}", ipAddress.getHostAddress(), e); } } return Optional.ofNullable(geoLocationInformation); }
switch (attribute) { case "country_code": put(properties,"_country_code", city.getCountry().getIsoCode()); break; case "region": put(properties,"_region", city.getContinent().getName()); break; case "city": put(properties,"_city", city.getCity().getName()); break; case "latitude": put(properties,"_latitude", city.getLocation().getLatitude()); break; case "longitude": put(properties,"_longitude", city.getLocation().getLongitude()); break; case "timezone": put(properties,"_timezone", city.getLocation().getTimeZone()); break;
address.setCountry(response.getCountry().getIsoCode()); address.setPostalCode(response.getPostal().getCode()); address.setZone(response.getMostSpecificSubdivision().getIsoCode()); address.setCity(response.getCity().getName());
@Override public Object getValue(CityResponse response) { return response.getLocation().getTimeZone(); } },
final Omni lookup = geoLookup.omni(ip); dimensions.put("continent", lookup.getContinent().getName()); dimensions.put("country", lookup.getCountry().getName()); dimensions.put("region", lookup.getMostSpecificSubdivision().getName()); dimensions.put("city", lookup.getCity().getName());
@Override public Object getValue(CityResponse response) { return response.getPostal().getCode(); } },
protected void extractIspFields(final Parsable<?> parsable, final String inputname, IspResponse response) throws DissectionFailure { if (wantIspName) { parsable.addDissection(inputname, "STRING", "isp.name", response.getIsp()); } if (wantIspOrganization) { parsable.addDissection(inputname, "STRING", "isp.organization", response.getOrganization()); } }
private void setIsp(InetAddress address, GenericRecord properties) { IspResponse isp; try { isp = ispLookup.isp(address); } catch (AddressNotFoundException e) { return; } catch (Exception e) { LOGGER.error(e, "Error while searching for location information."); return; } put(properties,"_isp", isp.getIsp()); }
CountryResponse response = reader.country(InetAddress.getByName(rp.getRemoteAddr())); Country country = response.getCountry(); rp.setRemoteAddrLocale(new Locale("", country.getIsoCode())); } catch (AddressNotFoundException e) {
domainName = domainResponse == null ? null : domainResponse.getDomain(); } else { domainName = null; connectionType = null; } else { final ConnectionType type = connectionTypeResponse.getConnectionType(); connectionType = type == null ? null : type.name();
AsnResponse asnResponse = reader.asn(addr); HashMap<String, Object> asnInfo = new HashMap<>(); AsnProps.ASN.set(asnInfo, asnResponse.getAutonomousSystemNumber()); AsnProps.ASO .set(asnInfo, MaxMindDbUtilities.convertNullToEmptyString(asnResponse.getAutonomousSystemOrganization())); AsnProps.NETWORK .set(asnInfo, MaxMindDbUtilities.convertNullToEmptyString(asnResponse.getIpAddress()));
private void setConnectionType(InetAddress address, GenericRecord properties) { ConnectionTypeResponse connectionType; try { connectionType = connectionTypeLookup.connectionType(address); } catch (AddressNotFoundException e) { return; } catch (Exception e) { LOGGER.error(e, "Error while searching for location information."); return; } ConnectionTypeResponse.ConnectionType connType = connectionType.getConnectionType(); if (connType != null) { put(properties,"_connection_type", connType.name()); } }
attrs.put(new StringBuilder(ipAttributeName).append(".geo.city").toString(), response.getCity().getName()); final Double latitude = response.getLocation().getLatitude(); if (latitude != null) { attrs.put(new StringBuilder(ipAttributeName).append(".geo.latitude").toString(), latitude.toString()); final Double longitude = response.getLocation().getLongitude(); if (longitude != null) { attrs.put(new StringBuilder(ipAttributeName).append(".geo.longitude").toString(), longitude.toString()); final Integer accuracy = response.getLocation().getAccuracyRadius(); if (accuracy != null) { attrs.put(new StringBuilder(ipAttributeName).append(".accuracy").toString(), String.valueOf(accuracy)); for (final Subdivision subd : response.getSubdivisions()) { attrs.put(new StringBuilder(ipAttributeName).append(".geo.subdivision.").append(i).toString(), subd.getName()); attrs.put(new StringBuilder(ipAttributeName).append(".geo.subdivision.isocode.").append(i).toString(), subd.getIsoCode()); i++; attrs.put(new StringBuilder(ipAttributeName).append(".geo.country").toString(), response.getCountry().getName()); attrs.put(new StringBuilder(ipAttributeName).append(".geo.country.isocode").toString(), response.getCountry().getIsoCode()); attrs.put(new StringBuilder(ipAttributeName).append(".geo.postalcode").toString(), response.getPostal().getCode()); flowFile = session.putAllAttributes(flowFile, attrs);
if (!(response.getAutonomousSystemNumber() == null)) { attrs.put(new StringBuilder(ipAttributeName).append(".isp.asn").toString(), String.valueOf(response.getAutonomousSystemNumber())); final String asnOrg = response.getAutonomousSystemOrganization(); if (asnOrg != null) { attrs.put(new StringBuilder(ipAttributeName).append(".isp.asn.organization").toString(), asnOrg); final String ispName = response.getIsp(); if (ispName != null) { attrs.put(new StringBuilder(ipAttributeName).append(".isp.name").toString(), ispName); final String organisation = response.getOrganization(); if (organisation != null) { attrs.put(new StringBuilder(ipAttributeName).append(".isp.organization").toString(), organisation);
HashMap<String, String> geoInfo = new HashMap<>(); Country country = cityResponse.getCountry(); City city = cityResponse.getCity(); Postal postal = cityResponse.getPostal(); Location location = cityResponse.getLocation();