[ https://issues.apache.org/jira/browse/MINIFI-159?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15752325#comment-15752325 ]
ASF GitHub Bot commented on MINIFI-159: --------------------------------------- Github user apiri commented on a diff in the pull request: https://github.com/apache/nifi-minifi-cpp/pull/27#discussion_r92678796 --- Diff: libminifi/src/AppendHostInfo.cpp --- @@ -0,0 +1,89 @@ +/** + * @file AppendHostInfo.cpp + * AppendHostInfo class implementation + * + * 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. + */ +#include <set> +#include <sys/time.h> +#include <string.h> +#include "AppendHostInfo.h" +#include "ProcessContext.h" +#include "ProcessSession.h" + +#include <netdb.h> +#include <netinet/in.h> +#include <sys/socket.h> +#include <sys/ioctl.h> +#include <net/if.h> +#include <arpa/inet.h> + +const std::string AppendHostInfo::ProcessorName("AppendHostInfo"); +Property AppendHostInfo::InterfaceName("Network Interface Name", "Network interface from which to read an IP v4 address", "eth0"); +Property AppendHostInfo::HostAttribute("Hostname Attribute", "Flowfile attribute to used to record the agent's hostname", "source.hostname"); +Property AppendHostInfo::IPAttribute("IP Attribute", "Flowfile attribute to used to record the agent's IP address", "source.ipv4"); +Relationship AppendHostInfo::Success("success", "success operational on the flow record"); + +void AppendHostInfo::initialize() +{ + //! Set the supported properties + std::set<Property> properties; + properties.insert(InterfaceName); + properties.insert(HostAttribute); + properties.insert(IPAttribute); + setSupportedProperties(properties); + + //! Set the supported relationships + std::set<Relationship> relationships; + relationships.insert(Success); + setSupportedRelationships(relationships); +} + +void AppendHostInfo::onTrigger(ProcessContext *context, ProcessSession *session) +{ + FlowFileRecord *flow = session->get(); + if (!flow) + return; + + //Get Hostname + char hostname[1024]; --- End diff -- Is there a reason 1024 is used? By spec, it is no more than 255 but may be lower depending on OS implementation. limits.h has a HOST_NAME_MAX that contains this to get more precision on this instantiation > Create AppendHostInfo processor > ------------------------------- > > Key: MINIFI-159 > URL: https://issues.apache.org/jira/browse/MINIFI-159 > Project: Apache NiFi MiNiFi > Issue Type: Bug > Components: C++, Extensions > Reporter: Randy Gelhausen > > Downstream consumers of data produced by nifi-minifi agents often need to > route FlowFiles based on hostname or IP of the machine running the agent. > nifi-minifi-cpp needs an AppendHostInfo processor which reads its' hostname > and IPv4 address for a specified network interface. -- This message was sent by Atlassian JIRA (v6.3.4#6332)