Github user mattyb149 commented on a diff in the pull request:
https://github.com/apache/nifi/pull/1650#discussion_r113247007
--- Diff:
nifi-nar-bundles/nifi-enrich-bundle/nifi-enrich-processors/src/main/java/org/apache/nifi/processors/ISPEnrichIP.java
---
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors;
+
+import com.maxmind.geoip2.exception.GeoIp2Exception;
+import com.maxmind.geoip2.model.IspResponse;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.nifi.annotation.behavior.EventDriven;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.InputRequirement.Requirement;
+import org.apache.nifi.annotation.behavior.SideEffectFree;
+import org.apache.nifi.annotation.behavior.SupportsBatching;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.behavior.WritesAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processors.maxmind.DatabaseReader;
+import org.apache.nifi.util.StopWatch;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+@EventDriven
+@SideEffectFree
+@SupportsBatching
+@Tags({"ISP", "enrich", "ip", "maxmind"})
+@InputRequirement(Requirement.INPUT_REQUIRED)
+@CapabilityDescription("Looks up ISP information for an IP address and
adds the information to FlowFile attributes. The "
+ + "ISP data is provided as a MaxMind database. The attribute that
contains the IP address to lookup is provided by the "
+ + "'IP Address Attribute' property. If the name of the attribute
provided is 'X', then the the attributes added by enrichment "
+ + "will take the form X.isp.<fieldName>")
+@WritesAttributes({
+ @WritesAttribute(attribute = "X.isp.lookup.micros", description = "The
number of microseconds that the geo lookup took"),
+ @WritesAttribute(attribute = "X.isp.asn", description = "The
Autonomous System Number (ASN) identified for the IP address"),
+ @WritesAttribute(attribute = "X.isp.asn.organization", description =
"The Organization Associated with the ASN identified"),
+ @WritesAttribute(attribute = "X.isp.name", description = "The name of
the ISP associated with the IP address provided"),
+ @WritesAttribute(attribute = "X.isp.organization", description = "The
Organization associated with the IP address provided"),})
+public class ISPEnrichIP extends AbstractEnrichIP {
+
+ @Override
+ public void onTrigger(final ProcessContext context, final
ProcessSession session) throws ProcessException {
+ FlowFile flowFile = session.get();
+ if (flowFile == null) {
+ return;
+ }
+
+ final DatabaseReader dbReader = databaseReaderRef.get();
+ final String ipAttributeName =
context.getProperty(IP_ADDRESS_ATTRIBUTE).evaluateAttributeExpressions(flowFile).getValue();
+ final String ipAttributeValue =
flowFile.getAttribute(ipAttributeName);
+ if (StringUtils.isEmpty(ipAttributeName)) { //TODO need to add
additional validation - should look like an IPv4 or IPv6 addr for instance
--- End diff --
Although this is a copy of the TODO from GeoEnrichIP, is this a good time
to add additional validation?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---