public void OnNewDataItems(DataItemBase[] dataItems, bool isLogicalllyGrouped, DataItemAcknowledgementCallback acknowledgeCallback, object acknowledgeState, DataItemProcessingCompleteCallback completionCallback, object completionState) { if ((acknowledgeCallback == null && completionCallback != null) || (acknowledgeCallback != null && completionCallback == null)) { throw new ArgumentOutOfRangeException(nameof(acknowledgeCallback), nameof(completionCallback)); } lock (_shutdownLock) { if (_shutdown) { return; } _logger.WriteLog(TraceEventType.Information, 450, $"Executing probe OnNewDataItems action"); TOutputDataType[] results = null; try { results = GetOutputData(dataItems); } catch (Exception ex) { _logger.WriteLog(TraceEventType.Critical, 500, $"Critical exception while trying to retrieve output data \n\n {ex}"); acknowledgeCallback?.Invoke(acknowledgeState); completionCallback?.Invoke(completionState); //QUESTION: Not sure if we need to request next dataItem ModuleHost.RequestNextDataItem(); throw new ModuleException(ex.Message, ex.InnerException); } acknowledgeCallback?.Invoke(acknowledgeState); completionCallback?.Invoke(completionState); //QUESTION: Should the state always be null? if (results.Length > 0) { ModuleHost.PostOutputDataItems(results, isLogicalllyGrouped, GetAcknowledgementCallback(), null); } _logger.WriteLog(TraceEventType.Information, 451, $"Requesting next data item"); ModuleHost.RequestNextDataItem(); } }
public void OnNewDataItems(DataItemBase[] dataitems, bool logicallyGrouped, DataItemAcknowledgementCallback acknowledgeCallback, object acknowledgedState, DataItemProcessingCompleteCallback completionCallback, object completionState) { Log($"Entering {nameof(OnNewDataItems)}; Managed thread: {Thread.CurrentThread.ManagedThreadId}\r\n"); Log($"Received {(dataitems == null ? 0 : dataitems.Length)} inbound data items of {(dataitems == null && dataitems.Length >=1 ? "<unknown>" : dataitems[0].DataItemTypeName)} type.\r\n"); lock (shutdownLock) { // don't start if shutdown is in progress if (shutdown) { return; } Log($"No shutdown in progress.\r\n"); PropertyBagDataItem[] ReturningResults = null; try { // put the actual monitoring code here: ReturningResults = <get result code> Log($"Competed output data item.\r\n"); } catch (Exception e) { Log($"Error while getting output data: {e.Message}.\r\n"); } if (ReturningResults != null && ReturningResults.Length != 0) { // send data back to SCOM Agent, if any if (ReturningResults.Length == 1) { ModuleHost.PostOutputDataItem(ReturningResults[0]); } else { ModuleHost.PostOutputDataItems(ReturningResults, logicallyGrouped); } Log($"Output data item(s) posted.\r\n"); } // completed the current run, ask for next ModuleHost.RequestNextDataItem(); Log($"Next data item requested.\r\n"); } }
protected void PostOutputData(TOutputDataType[] ReturningResults, DataItemAcknowledgementCallback AcknowledgementCallback, bool LogicallyGrouped) { lock (shutdownLock) { if (shutdown) { return; } } try { if (ReturningResults != null || ReturningResults.Length > 0) { if (AcknowledgementCallback == null) { if (ReturningResults.Length == 1) { ModuleHost.PostOutputDataItem(ReturningResults[0]); } else { ModuleHost.PostOutputDataItems(ReturningResults, LogicallyGrouped); } } else { if (ReturningResults.Length == 1) { ModuleHost.PostOutputDataItem(ReturningResults[0], AcknowledgementCallback, null); } else { ModuleHost.PostOutputDataItems(ReturningResults, LogicallyGrouped, AcknowledgementCallback, null); } } } } catch (Exception e) { ModuleHost.NotifyError(ModuleErrorSeverity.DataLoss, e); } }
public void QueueCallback() { // this method can access shared static resource, because QueueManager ensures, that other queued actions called sequentially. try { bool NeedAcknowledge = (_acknowledgeCallback != null); lock (shutdownLock) { if (shutdown) { return; } TOutputDataType[] ReturningResults; try { ReturningResults = GetOutputData(); } catch (Exception e) { try { if (NeedAcknowledge) { _acknowledgeCallback(_acknowledgedState); _completionCallback(_completionState); } } catch (Exception ae) { Global.logWriteException("Failed to acknowledge action completion.", ae, this); } ModuleHost.RequestNextDataItem(); throw new ModuleException(e.Message, e); } if (ReturningResults == null || ReturningResults.Length == 0) { if (NeedAcknowledge) { _acknowledgeCallback(_acknowledgedState); _completionCallback(_completionState); } ModuleHost.RequestNextDataItem(); } else if (NeedAcknowledge) { void AcknowledgeBypass(object ackState) { lock (shutdownLock) { if (shutdown) { return; } _acknowledgeCallback(_acknowledgedState); _completionCallback(_completionState); ModuleHost.RequestNextDataItem(); } } if (ReturningResults.Length == 1) { ModuleHost.PostOutputDataItem(ReturningResults[0], AcknowledgeBypass, null); } else { ModuleHost.PostOutputDataItems(ReturningResults, _logicallyGrouped, AcknowledgeBypass, null); } } else { if (ReturningResults.Length == 1) { ModuleHost.PostOutputDataItem(ReturningResults[0]); } else { ModuleHost.PostOutputDataItems(ReturningResults, _logicallyGrouped); } ModuleHost.RequestNextDataItem(); } } } finally { enqueuedSemaphore.Release(); } }
public void OnNewDataItems(DataItemBase[] dataItems, bool logicallyGrouped, DataItemAcknowledgementCallback acknowledgeCallback, object acknowledgedState, DataItemProcessingCompleteCallback completionCallback, object completionState) { if ((acknowledgeCallback == null && completionCallback != null) || (acknowledgeCallback != null && completionCallback == null)) { throw new ArgumentOutOfRangeException("acknowledgeCallback, completionCallback"); } bool NeedAcknowledge = (acknowledgeCallback != null); lock (shutdownLock) { if (shutdown) { return; } TOutputDataType[] ReturningResults; try { ReturningResults = GetOutputData(dataItems); } catch (Exception e) { if (NeedAcknowledge) { acknowledgeCallback(acknowledgedState); completionCallback(completionState); } ModuleHost.RequestNextDataItem(); throw new ModuleException(e.Message, e); } if (ReturningResults == null || ReturningResults.Length == 0) { if (NeedAcknowledge) { acknowledgeCallback(acknowledgedState); completionCallback(completionState); } ModuleHost.RequestNextDataItem(); } else if (NeedAcknowledge) { void AcknowledgeBypass(object ackState) { lock (shutdownLock) { if (shutdown) { return; } acknowledgeCallback(acknowledgedState); completionCallback(completionState); ModuleHost.RequestNextDataItem(); } } if (ReturningResults.Length == 1) { ModuleHost.PostOutputDataItem(ReturningResults[0], AcknowledgeBypass, null); } else { ModuleHost.PostOutputDataItems(ReturningResults, logicallyGrouped, AcknowledgeBypass, null); } } else { if (ReturningResults.Length == 1) { ModuleHost.PostOutputDataItem(ReturningResults[0]); } else { ModuleHost.PostOutputDataItems(ReturningResults, logicallyGrouped); } ModuleHost.RequestNextDataItem(); } } }
public void OnNewDataItems(DataItemBase[] dataItems, bool logicalSet, DataItemAcknowledgementCallback acknowledgedCallback, object acknowledgedState, DataItemProcessingCompleteCallback completionCallback, object completionState) { // Either both delegates are null or neither should be. if ((acknowledgedCallback == null && completionCallback != null) || (acknowledgedCallback != null && completionCallback == null)) { throw new ArgumentOutOfRangeException("acknowledgedCallback, completionCallback"); } var ackNeeded = acknowledgedCallback != null; lock (shutdownLock) { if (shutdown) { return; } var outputDataItems = new List <MOMPerfDataItem>(); var timeStamp = DateTime.UtcNow; foreach (var dataItem in dataItems) { var bag = dataItem is PropertyBagDataItem ? (PropertyBagDataItem)dataItem : new PropertyBagDataItem(dataItem.GetItemXml()); foreach (var collection in bag.Collections) { foreach (var record in collection.Value) { double value; if (record.Value == null || !double.TryParse(record.Value.ToString(), out value)) { continue; } var mapping = config.Mappings.FirstOrDefault(m => m.PropertyName.Equals(record.Key, StringComparison.InvariantCultureIgnoreCase)); if (mapping == null) { continue; } var perfDataItem = new MOMPerfDataItem( timeStamp, mapping.ObjectName, mapping.CounterName, mapping.InstanceName, false, value, config.ManagedEntityId, config.RuleId); outputDataItems.Add(perfDataItem); } } } // Handle output if (outputDataItems == null || outputDataItems.Count == 0) { return; } if (ackNeeded) { DataItemAcknowledgementCallback ackDelegate = delegate(object ackState) { lock (shutdownLock) { if (shutdown) { return; } acknowledgedCallback(acknowledgedState); completionCallback(completionState); ModuleHost.RequestNextDataItem(); } }; ModuleHost.PostOutputDataItems(outputDataItems.ToArray(), true /*logicalSet*/, ackDelegate, null); } else { ModuleHost.PostOutputDataItems(outputDataItems.ToArray(), true /*logicalSet*/); ModuleHost.RequestNextDataItem(); } } }