async public static void AddMonitoringData(MonitoringSessionState monitoringState, string modifiedTime, string computerName, bool monitorEnd) { WriteLogFile("Monitoring timer was triggered, reading task sequence environment data"); try { //' Determine unique id for deployment string uniqueId = TSEnvironment.GetTSVariable(Properties.Settings.Default.UniqueMonitoringTSVariableName); if (String.IsNullOrEmpty(uniqueId)) { uniqueId = Guid.NewGuid().ToString(); TSEnvironment.SetTSVariable(Properties.Settings.Default.UniqueMonitoringTSVariableName, uniqueId); } try { //' Read additional task sequence information if the environment is reachable bool tsEnvironment = TSEnvironment.TestTSEnvironment(); if (tsEnvironment == true) { if (!String.IsNullOrEmpty(sequenceType)) { if (sequenceType == "2") { //' Read task sequence variable for deployment ID value deploymentId = TSEnvironment.GetTSVariable("_SMSTSAdvertID"); if (String.IsNullOrEmpty(deploymentId)) { deploymentId = null; } //' Read task sequence variable for current step name value stepName = TSEnvironment.GetTSVariable("_SMSTSCurrentActionName"); if (String.IsNullOrEmpty(stepName)) { stepName = null; } //' Read task sequence variable for current step value currentStep = TSEnvironment.GetTSVariable("_SMSTSNextInstructionPointer"); if (String.IsNullOrEmpty(currentStep)) { currentStep = null; } //' Read task sequence variable for total steps value totalSteps = TSEnvironment.GetTSVariable("_SMSTSInstructionTableSize"); if (String.IsNullOrEmpty(totalSteps)) { totalSteps = null; } } } } } catch (System.Exception ex) { WriteLogFile(String.Format("An warning occurred while reading additional task sequence data, this exception happened within the add monitoring method and was unexpected. Error: {0}", ex.Message)); } //' Determine details message parameter switch (monitoringState) { case MonitoringSessionState.Running: details = "Task sequence is running"; severity = 1; break; case MonitoringSessionState.Reboot: details = "Computer is being restarted"; severity = 1; break; case MonitoringSessionState.NotStarted: details = "Task sequence has not started"; severity = 1; break; case MonitoringSessionState.Failed: details = "Deployment failed"; severity = 2; break; case MonitoringSessionState.Completed: details = "Deployment completed"; severity = 1; break; default: severity = 1; break; } //' Determine if end time should be set if (monitorEnd == true) { endTime = GetTimeNow(); } try { //' Add monitoring data through web service call AddCMOSDMonitorDataResponse monitorResponse = await webService.AddCMOSDMonitorDataAsync(Properties.Settings.Default.WebServiceSecretKey, uniqueId, computerName, uuid, macAddress, severity, modifiedTime, deploymentId, stepName, currentStep, totalSteps, startTime, endTime, details, dartIp, dartPort, dartTicket); WriteLogFile("Successfully posted monitoring data to web service"); } catch (System.Exception ex) { WriteLogFile(String.Format("An error occurred while attempting to post monitoring data to web service. Error: {0}", ex.Message)); } } catch (System.Exception ex) { WriteLogFile(String.Format("An error occurred while collecting data for web service post. Will be retried in the next cycle. Error: {0}", ex.Message)); } }