phrocker commented on a change in pull request #551: MINIFICPP-773 Implemented.
URL: https://github.com/apache/nifi-minifi-cpp/pull/551#discussion_r282309850
 
 

 ##########
 File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
 ##########
 @@ -0,0 +1,322 @@
+/**
+ * @file ConsumeWindowsEventLog.cpp
+ * ConsumeWindowsEventLog class declaration
+ *
+ * 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 "ConsumeWindowsEventLog.h"
+#include <vector>
+#include <queue>
+#include <map>
+#include <set>
+#include <sstream>
+#include <stdio.h>
+#include <string>
+#include <iostream>
+#include <memory>
+#include <codecvt>
+
+#include "io/DataStream.h"
+#include "core/ProcessContext.h"
+#include "core/ProcessSession.h"
+
+#pragma comment(lib, "wevtapi.lib")
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace processors {
+
+static const size_t MAX_RECORD_BUFFER_SIZE = 0x10000; // 64k
+const std::string 
ConsumeWindowsEventLog::ProcessorName("ConsumeWindowsEventLog");
+
+static const int DEFAULT_MAX_BUFFER = 1024 * 1024;
+
+core::Property ConsumeWindowsEventLog::Channel(
+  core::PropertyBuilder::createProperty("Channel")->
+  isRequired(true)->
+  withDefaultValue("System")->
+  withDescription("The Windows Event Log Channel to listen to.")->
+  supportsExpressionLanguage(true)->
+  build());
+
+core::Property ConsumeWindowsEventLog::Query(
+  core::PropertyBuilder::createProperty("Query")->
+  isRequired(true)->
+  withDefaultValue("*")->
+  withDescription("XPath Query to filter events. (See 
https://msdn.microsoft.com/en-us/library/windows/desktop/dd996910(v=vs.85).aspx 
for examples.)")->
+  supportsExpressionLanguage(true)->
+  build());
+
+core::Property ConsumeWindowsEventLog::MaxBufferSize(
+  core::PropertyBuilder::createProperty("Max Buffer Size")->
+  isRequired(true)->
+  withDefaultValue(std::to_string(1024 * 1024))->
+  withDescription(
+    "The individual Event Log XMLs are rendered to a buffer."
+    " This specifies the maximum size in bytes that the buffer will be allowed 
to grow to. (Limiting the maximum size of an individual Event XML.)")->
+  build());
+
+core::Property ConsumeWindowsEventLog::InactiveDurationToReconnect(
+  core::PropertyBuilder::createProperty("Inactive Duration To Reconnect")->
+  isRequired(true)->
+  withDefaultValue("10 mins")->
+  withDescription(
+    "If no new event logs are processed for the specified time period, "
+    " this processor will try reconnecting to recover from a state where any 
further messages cannot be consumed."
+    " Such situation can happen if Windows Event Log service is restarted, or 
ERROR_EVT_QUERY_RESULT_STALE (15011) is returned."
+    " Setting no duration, e.g. '0 ms' disables auto-reconnection.")->
+  build());
+
+core::Relationship ConsumeWindowsEventLog::Success("success", "Relationship 
for successfully consumed events.");
+
+ConsumeWindowsEventLog::ConsumeWindowsEventLog(const std::string& name, 
utils::Identifier uuid)
+  : core::Processor(name, uuid), 
logger_(logging::LoggerFactory<ConsumeWindowsEventLog>::getLogger()) {
+  char buff[MAX_COMPUTERNAME_LENGTH + 1];
+  DWORD size = sizeof(buff);
+  if (GetComputerName(buff, &size))
+  {
+    computerName_ = buff;
+  }
+  else
+  {
+    LogWindowsError();
+  }
+}
+
+void ConsumeWindowsEventLog::initialize() {
+  //! Set the supported properties
+  setSupportedProperties({Channel, Query, MaxBufferSize, 
InactiveDurationToReconnect});
+
+  //! Set the supported relationships
+  setSupportedRelationships({Success});
+}
+
+void ConsumeWindowsEventLog::onSchedule(const 
std::shared_ptr<core::ProcessContext> &context, const 
std::shared_ptr<core::ProcessSessionFactory> &sessionFactory) {
+  if (subscriptionHandle_) {
+    logger_->log_error("Processor already subscribed to Event Log, expected 
cleanup to unsubscribe.");
+  } else {
+    subscribe(context);
+  }
 
 Review comment:
   You brought up a good case in notifyStop. You should likely take a copy of 
the process session factory instead of session_, and create a new session when 
a stop notification arises. 

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