예제 #1
0
        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));
            }
        }
예제 #2
0
        public void Timer_Tick(object sender, EventArgs e)
        {
            try
            {
                //' Determine if a task sequence for operating system deployment is running
                if (sequenceType == "2")
                {
                    //' Set monitoring session state
                    monitoringState = MonitoringSessionState.Running;

                    try
                    {
                        //' When deployment has started, set start time variable if not already set
                        if (String.IsNullOrEmpty(TSEnvironment.DeploymentStartTime))
                        {
                            startTime = GetTimeNow();
                            TSEnvironment.DeploymentStartTime = startTime;
                        }
                        else
                        {
                            startTime = TSEnvironment.DeploymentStartTime;
                        }
                    }
                    catch (System.Exception ex)
                    {
                        WriteLogFile(String.Format("An error occurred while reading task sequence environment, this exception happened while reading deployment started variable and was unexpected. Error: {0}", ex.Message));
                    }

                    //' Determine if the last task sequence step succeeded
                    bool lastSuccess;
                    Boolean.TryParse(TSEnvironment.GetTSVariable("_SMSTSLastActionSucceeded"), out lastSuccess);
                    if (lastSuccess == false)
                    {
                        WriteLogFile("Determined that the task sequence has failed, changing monitoring session state");
                        monitoringState = MonitoringSessionState.Failed;
                    }
                }
                else
                {
                    try
                    {
                        sequenceType = TSEnvironment.GetTSVariable("_SMSTSType");
                    }
                    catch (System.Exception ex)
                    {
                        WriteLogFile(String.Format("An warning occurred while reading task sequence environment, this was expected and should not happen again. Error: {0}", ex.Message));
                    }

                    //' Set monitoring session state
                    monitoringState = MonitoringSessionState.NotStarted;
                }

                //' Read task sequence variable for computer name value
                computerName = TSEnvironment.GetTSVariable("OSDComputerName");
                if (String.IsNullOrEmpty(computerName))
                {
                    computerName = "Unknown";
                }

                //' Get current date time for modified time parameter input
                modifiedTime = GetTimeNow();

                //' Add monitoring data
                AddMonitoringData(monitoringState, modifiedTime, computerName, false);
            }
            catch (System.Exception ex)
            {
                WriteLogFile(String.Format("An warning occurred while reading task sequence environment, this exception happened within the timer tick and was unexpected. Error: {0}", ex.Message));
            }
        }