Beispiel #1
0
        protected override IEnumerable <CollectedItem> collectDataForSystemItem(ItemType systemItem)
        {
            this.CreateSMFCollectorInstance();

            var smfItem = (smf_item)systemItem;

            try
            {
                var collectedSmf = this.TryToCollectSMF(smfItem.fmri.Value);
                smfItem.service_name  = OvalHelper.CreateItemEntityWithStringValue(collectedSmf.ServiceName);
                smfItem.service_state = new EntityItemSmfServiceStateType()
                {
                    Value = collectedSmf.ServiceState
                };
                smfItem.protocol = new EntityItemSmfProtocolType()
                {
                    Value = collectedSmf.Protocol
                };
                smfItem.server_executable = OvalHelper.CreateItemEntityWithStringValue(collectedSmf.ServerExecutable);
                smfItem.server_arguements = OvalHelper.CreateItemEntityWithStringValue(collectedSmf.ServerArgs);
                smfItem.exec_as_user      = OvalHelper.CreateItemEntityWithStringValue(collectedSmf.ExecAsUser);
            }
            catch (NoSMFDataException)
            {
                ExecutionLogBuilder.AddInfo("An error occurred while trying to collect smf_object");
                smfItem.status      = StatusEnumeration.error;
                smfItem.message     = MessageType.FromErrorString("The fmri format is invalid.");
                smfItem.fmri.status = StatusEnumeration.error;
            }

            return(new ItemTypeHelper().CreateCollectedItemsWithOneItem(smfItem, BuildExecutionLog()));
        }
        private void SetStartInstrumentationLog(ExecutionLogBuilder executionLog, DateTime startTime, string probeName)
        {
            String INSTRUMENTATION_LOG_MSG_FORMAT = "The collect of [{0}] probe was start at {1}";
            var    intrumentationLogMsg           = string.Format(INSTRUMENTATION_LOG_MSG_FORMAT, probeName, startTime.ToLocalTime());

            executionLog.AddInfo(intrumentationLogMsg);
        }
Beispiel #3
0
        public override void PrepareCollectionOfObjects(IEnumerable <ObjectType> allItemsToCollect, VariablesEvaluated variables)
        {
            base.PrepareCollectionOfObjects(allItemsToCollect, variables);
            if (allItemsToCollect.Count() > 0)
            {
                var variableEvaluator = new VariableEntityEvaluator(variables);

                var allSapObjects = allItemsToCollect.OfType <sapcode_object>().ToList();
                var issues        = allSapObjects.SelectMany(x => variableEvaluator.EvaluateVariableForEntity(((EntitySimpleBaseType)(x.Items[x.ItemsElementName.ToList().IndexOf(SapCodeObjectItemsChoices.issue)])))).Distinct();
                var systemNames   = allSapObjects.SelectMany(x => variableEvaluator.EvaluateVariableForEntity(((EntitySimpleBaseType)x.Items[x.ItemsElementName.ToList().IndexOf(SapCodeObjectItemsChoices.system_name)]))).Distinct();

                var systemIds = systemNames.Select(x => Convert.ToInt32(x));
                if (systemIds.Count() > 1)
                {
                    throw new NotSupportedException("Only concurrent collections of a single system is supported!");
                }

                ExecutionLogBuilder.AddInfo(string.Format("Authenticating at code control with user '{0}'.", AuthUser));
                var authResult = connectionProvider.authenticate(AuthUser, AuthPassword);
                if (authResult.error)
                {
                    ExecutionLogBuilder.AnErrorOccurred(string.Format("Error authenticating at code control : {0}.", authResult.errorMessage));
                }
                else
                {
                    ExecutionLogBuilder.AddInfo(string.Format("Successfully authenticated.", AuthUser));
                    int nSystem   = systemIds.Single();
                    var allIssues = issues.Select(x => (long)Convert.ToInt32(x)).ToArray();
                    ExecutionLogBuilder.AddInfo(
                        string.Format("Starting scan request for system {0} and issues '{1}'.", nSystem, string.Join(",", allIssues)));
                    issueResult = connectionProvider.scanIssueListBySystem(authResult.token, nSystem, allIssues);

                    var scanCriteria = new ScanCriteriaDTO()
                    {
                        scanIdList = new[] { issueResult.scanId ?? 0 }
                    };

                    var waitTime = 0L;
                    //const int timeOut = 3600000; // 1 hour
                    //const int timeOut = 10800000; // 3 hs
                    const int timeOut = 18000000;
                    while (((issueResult.status == "AWAITING") || (issueResult.status == "PROCESSING")) &&
                           (waitTime <= timeOut)
                           )
                    {
                        Thread.Sleep(40000);
                        issueResult = connectionProvider.findScan(authResult.token, scanCriteria).FirstOrDefault();
                        // Wait time is desconsidering remote call duration,
                        // should be done with a stop watch
                        waitTime += 40000;
                    }
                }
            }
        }
        private void SetEndInstrumentationLog(ExecutionLogBuilder executionLog, DateTime initialTimeStamp, string probeName)
        {
            String INSTRUMENTATION_LOG_MSG_FORMAT = "The collect of [{0}] probe was finished at {1} (in {2} secs)";

            var endTimeStamp       = DateTime.Now;
            var totalTimeInSeconds = Convert.ToInt32(endTimeStamp.Subtract(initialTimeStamp).TotalSeconds);

            var executionLogMsg = string.Format(INSTRUMENTATION_LOG_MSG_FORMAT, probeName, endTimeStamp, totalTimeInSeconds);

            executionLog.AddInfo(executionLogMsg);
        }