You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2022/12/21 14:18:58 UTC

[GitHub] [nifi-minifi-cpp] szaszm commented on a diff in pull request #1482: MINIFICPP-2009 - CWEL should add resolved attributes with json output…

szaszm commented on code in PR #1482:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1482#discussion_r1054439110


##########
extensions/windows-event-log/tests/ConsumeWindowsEventLogTests.cpp:
##########
@@ -236,6 +236,14 @@ TEST_CASE("ConsumeWindowsEventLog extracts some attributes by default", "[onTrig
   auto logger_processor = test_plan->addProcessor("LogAttribute", "logger", Success, true);
   test_plan->setProperty(logger_processor, LogAttribute::FlowFilesToLog.getName(), "0");
 
+  SECTION("XML output") {
+    CHECK(test_plan->setProperty(cwel_processor, ConsumeWindowsEventLog ::OutputFormat.getName(), "XML"));
+  }
+
+  SECTION("Json output") {
+    CHECK(test_plan->setProperty(cwel_processor, ConsumeWindowsEventLog ::OutputFormat.getName(), "JSON"));
+  }

Review Comment:
   Are there tests that cover the content replacement case? I'm hoping this fix doesn't break that.



##########
extensions/windows-event-log/ConsumeWindowsEventLog.cpp:
##########
@@ -696,32 +696,30 @@ void ConsumeWindowsEventLog::putEventRenderFlowFileToSession(const EventRender&
   };
 
   if (output_.xml) {
-    auto flowFile = session.create();
     logger_->log_trace("Writing rendered XML to a flow file");
-
-    for (const auto &fieldMapping : eventRender.matched_fields) {
-      if (!fieldMapping.second.empty()) {
-        session.putAttribute(flowFile, fieldMapping.first, fieldMapping.second);
-      }
-    }
-
-    commitFlowFile(flowFile, eventRender.xml, "application/xml");
+    auto flow_file = session.create();
+    addMatchedFieldsAsAttributes(eventRender, session, flow_file);
+    commitFlowFile(flow_file, eventRender.xml, "application/xml");
   }
 
   if (output_.plaintext) {
     logger_->log_trace("Writing rendered plain text to a flow file");
     commitFlowFile(session.create(), eventRender.plaintext, "text/plain");
   }
 
-  if (output_.json.type == JSONType::Raw) {
-    logger_->log_trace("Writing rendered raw JSON to a flow file");
-    commitFlowFile(session.create(), eventRender.json, "application/json");
-  } else if (output_.json.type == JSONType::Simple) {
-    logger_->log_trace("Writing rendered simple JSON to a flow file");
-    commitFlowFile(session.create(), eventRender.json, "application/json");
-  } else if (output_.json.type == JSONType::Flattened) {
-    logger_->log_trace("Writing rendered flattened JSON to a flow file");
-    commitFlowFile(session.create(), eventRender.json, "application/json");
+  if (output_.json.type != JSONType::None) {
+    logger_->log_trace("Writing rendered %s JSON to a flow file", output_.json.type.toString());
+    auto flow_file = session.create();
+    addMatchedFieldsAsAttributes(eventRender, session, flow_file);

Review Comment:
   I think it would make sense to add the attributes in all cases, including plaintext.



-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org