Пример #1
0
        public void RecordStream(PoshJob poshJob, object sender, DataAddedEventArgs e)
        {
            var type = sender.GetType();
            LogPostParameters   logPostParameters = new LogPostParameters();
            InformationalRecord record;

            if (type == typeof(PSDataCollection <VerboseRecord>))
            {
                record = ((PSDataCollection <VerboseRecord>)sender)[e.Index];
                logPostParameters.message = record.Message;
                logPostParameters.level   = JobLogLevelEnum.Verbose;
            }
            if (type == typeof(PSDataCollection <DebugRecord>))
            {
                record = ((PSDataCollection <DebugRecord>)sender)[e.Index];
                logPostParameters.message = record.Message;
                logPostParameters.level   = JobLogLevelEnum.Debug;
            }
            if (type == typeof(PSDataCollection <ErrorRecord>))
            {
                FaultJob(poshJob.JobUID);
                logPostParameters.level = JobLogLevelEnum.Error;
                var errorRecord = ((PSDataCollection <ErrorRecord>)sender)[e.Index];
                logPostParameters.Exception = errorRecord.Exception.Message;
                logPostParameters.message   = errorRecord.ScriptStackTrace; //this is where the error occured. Not sure if there is a better message for error streams
            }
            if (type == typeof(PSDataCollection <WarningRecord>))
            {
                logPostParameters.level = JobLogLevelEnum.Warning;
                record = ((PSDataCollection <WarningRecord>)sender)[e.Index];
                logPostParameters.message = record.Message;
            }
            logPostParameters.jobUid = poshJob.JobUID;
            LogPoshMessage(logPostParameters);
        }
Пример #2
0
        public void ProcessRunningJobs()
        {
            foreach (var runningJob in runningJobs)
            {
                var jobTask      = runningJob.Value.RunningJob;
                var poshInstance = runningJob.Value.PoshInstance;
                if (jobTask.Status == TaskStatus.RanToCompletion)
                {
                    _poshManager.RetirePowerShell(poshInstance);
                    RemoveRunningJob(runningJob);
                    string withErrors = "";
                    bool   hasErrored = false;
                    jobsWithErrors.TryRemove(runningJob.Key, out hasErrored);
                    if (hasErrored)
                    {
                        withErrors = " with errors";
                    }
                    Log.Information($"Job {runningJob.Key} has completed{withErrors}.");

                    string url = automationHelper.GetUrl() + $"/api/Job/{runningJob.Value.JobUID}/Finish?error={hasErrored.ToString()}";
                    automationHelper.PostWebCall(url, null);
                }
                if (jobTask.Status == TaskStatus.Faulted)
                {
                    string url = automationHelper.GetUrl() + $"/api/Job/{runningJob.Value.JobUID}/Finish?Errored=True";
                    automationHelper.PostWebCall(url, null);
                    Log.Warning($"Job {runningJob.Key} faulted.");
                    LogPostParameters lpp = new LogPostParameters();
                    lpp.Exception = jobTask.Exception.Message;
                    lpp.jobUid    = runningJob.Value.JobUID;
                    lpp.message   = $"Job faulted. See Exception for details.";
                    lpp.level     = JobLogLevelEnum.Error;
                    LogPoshMessage(lpp);
                    RemoveRunningJob(runningJob);
                }
            }
        }
Пример #3
0
        private void LogPoshMessage(LogPostParameters logPostParameters)
        {
            string url = automationHelper.GetUrl() + $"/api/Log/";

            automationHelper.PostWebCall(url, logPostParameters);
        }
Пример #4
0
 public void New([FromBody] LogPostParameters postParams)
 {
     _jobManager.LogAsync(postParams.jobUid, postParams.message, postParams.level, postParams.Exception);
 }