arpadboda commented on a change in pull request #648: WIP: Minificpp 1025 -- 
add metadata
URL: https://github.com/apache/nifi-minifi-cpp/pull/648#discussion_r329133250
 
 

 ##########
 File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
 ##########
 @@ -127,23 +146,61 @@ ConsumeWindowsEventLog::~ConsumeWindowsEventLog() {
 
 void ConsumeWindowsEventLog::initialize() {
   //! Set the supported properties
-  setSupportedProperties({Channel, Query, MaxBufferSize, 
InactiveDurationToReconnect, IdentifierMatcher, IdentifierFunction, 
ResolveAsAttributes });
+  setSupportedProperties({Channel, Query, MaxBufferSize, 
InactiveDurationToReconnect, IdentifierMatcher, IdentifierFunction, 
ResolveAsAttributes, EventHeaderDelimiter, EventHeader });
 
   //! Set the supported relationships
   setSupportedRelationships({Success});
 }
 
+bool ConsumeWindowsEventLog::insertHeaderName(wel::METADATA_NAMES &header, 
const std::string &key, const std::string & value) {
+       
+       wel::METADATA name = 
wel::WindowsEventLogMetadata::getMetadataFromString(key);
+               
+       if (name != wel::METADATA::UNKNOWN) {
+               header.emplace_back(std::make_pair(name, value));
+               return true;
+       }
+       else {
+               return false;
+       }
+}
+
 void ConsumeWindowsEventLog::onSchedule(const 
std::shared_ptr<core::ProcessContext> &context, const 
std::shared_ptr<core::ProcessSessionFactory> &sessionFactory) {
        context->getProperty(IdentifierMatcher.getName(), regex_);
        context->getProperty(ResolveAsAttributes.getName(), 
resolve_as_attributes_);
        context->getProperty(IdentifierFunction.getName(), 
apply_identifier_function_);
+       context->getProperty(EventHeaderDelimiter.getName(), header_delimiter_);
+
+       std::string header;
+       context->getProperty(EventHeader.getName(), header);
+       
+       auto keyValueSplit = utils::StringUtils::split(header, ",");
+       for (const auto &kv : keyValueSplit) {
+               auto splitKeyAndValue = utils::StringUtils::split(kv, "=");
+               if (splitKeyAndValue.size() == 2) {
+                       auto key = 
utils::StringUtils::trim(splitKeyAndValue.at(0));
+                       auto value = 
utils::StringUtils::trim(splitKeyAndValue.at(1));
+                       if (!insertHeaderName(header_names_, key, value)) {
+                               logger_->log_debug("%s is an invalid key for 
the header map", key);
+                       }
+               }
+               else if (splitKeyAndValue.size() == 1) {
+                       auto key = 
utils::StringUtils::trim(splitKeyAndValue.at(0));
+                       if (!insertHeaderName(header_names_, key, "")) {
+                               logger_->log_debug("%s is an invalid key for 
the header map", key);
+                       }
+               }
+
 
 Review comment:
   Are we sure this can't happen? Either a comment here or some error handling 
that at least logs malformed headers would be nice. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to