Ejemplo n.º 1
0
        private void ConfigureItemTypeAsErrorItem(ItemType systemItem, string exceptionMessage)
        {
            var messageValue = string.Format(ITEM_COULD_NOT_BE_COLLECTED, ObjectCollectorName, exceptionMessage);

            systemItem.message = MessageType.FromErrorString(messageValue);
            systemItem.status  = StatusEnumeration.error;
        }
Ejemplo n.º 2
0
 public IEnumerable <CollectedItem> CreateCollectedItemsWithOneErrorItem(
     ItemType itemType, IEnumerable <ProbeLogItem> logItems, string errorMessage)
 {
     itemType.message = MessageType.FromErrorString(errorMessage);
     itemType.status  = StatusEnumeration.error;
     return(CreateCollectedItems(itemType, logItems));
 }
Ejemplo n.º 3
0
 protected override ItemType CreateItemTypeWithErrorStatus(string errorMessage)
 {
     return(new sapcode_item()
     {
         status = StatusEnumeration.error, message = MessageType.FromErrorString(errorMessage)
     });
 }
Ejemplo n.º 4
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()));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// This method executes the process of  a setElement in the ObjectType.
        /// For the objectType that has a setElement the process is a some different.
        /// Actually, the setElement uses the objectType already was  collected.
        /// In this process the setElement process uses a systemCharacteristics for the get a reference for the objectType
        /// collected and makes the references are used in the new CollectedObject of the process.
        /// </summary>
        /// <param name="ovalObject">The Oval Object.</param>
        /// <param name="collectInfo">The collect info.</param>
        /// <returns></returns>
        private CollectedObject ProcessSet(Definitions.ObjectType ovalObject, CollectInfo collectInfo)
        {
            CollectedObject collectedObject = null;

            try
            {
                var setElement       = this.GetSetElement(ovalObject);
                var setEvaluator     = new SetEvaluator(collectInfo.SystemCharacteristics, collectInfo.States, collectInfo.Variables);
                var resultOfSet      = setEvaluator.Evaluate(setElement);
                var objectReferences = resultOfSet.Result;

                if (objectReferences.Count() > 0)
                {
                    collectedObject = new CollectedObject(ovalObject.id);
                    foreach (string reference in objectReferences)
                    {
                        var itemType = collectInfo.SystemCharacteristics.GetSystemDataByReferenceId(reference);
                        collectedObject.AddItemToSystemData(itemType);
                    }

                    collectedObject.SetEspecificObjectStatus(resultOfSet.ObjectFlag);
                }

                return(collectedObject);
            }
            catch (Exception ex)
            {
                collectedObject = new CollectedObject(ovalObject.id);
                collectedObject.SetEspecificObjectStatus(FlagEnumeration.error);
                collectedObject.ObjectType.message = MessageType.FromErrorString(String.Format("An error occurred while set processing: '{0}'", ex.Message));
                return(collectedObject);
            }
        }
        private IEnumerable <ItemType> processOperationInRegistryObject(RegistryObject registryObject)
        {
            List <string> hives = new List <string>()
            {
                registryObject.Hive
            };
            RegistryItemTypeFactory itemTypeFactory = new RegistryItemTypeFactory();

            List <ItemType> items = new List <ItemType>();
            List <string>   keys  = new List <string>();
            List <string>   names = new List <string>();

            try
            {
                var registryNameValue = registryObject.GetValueOfEntity("name");
                keys.AddRange(this.processOperationInEntity(registry_object_ItemsChoices.key, registryObject));

                var derivedRegistryObjects =
                    RegistryObjectFactory.CreateRegistryObjectsByCombinationOfEntitiesFrom(hives, keys, new string[] { registryNameValue }, registryObject);

                if (registryObject.GetNameOperation() != OperationEnumeration.equals)
                {
                    foreach (var newRegistryObject in derivedRegistryObjects)
                    {
                        if (!string.IsNullOrEmpty(registryNameValue))
                        {
                            names = this.processOperationInEntity(registry_object_ItemsChoices.name, newRegistryObject).ToList();
                            items.AddRange(itemTypeFactory.CreateRegistryItemTypesByCombinationOfEntitiesFrom(hives, new string[] { newRegistryObject.Key }, names, registryObject));
                        }
                    }
                }
                else
                {
                    names.AddRange(this.processOperationInEntity(registry_object_ItemsChoices.name, registryObject));
                    items.AddRange(itemTypeFactory.CreateRegistryItemTypesByCombinationOfEntitiesFrom(hives, keys, names, registryObject));
                }
            }
            catch (RegistryKeyNotFoundException)
            {
                items = itemTypeFactory.CreateRegistryItemTypesByCombinationOfEntitiesFrom(hives, null, null, registryObject).ToList();
            }
            catch (RegistryItemNotFoundException)
            {
                items = new List <ItemType>()
                {
                    itemTypeFactory.CreateRegistryItem("", "", "", StatusEnumeration.doesnotexist)
                };
            }
            catch (Exception ex)
            {
                registry_item registry = itemTypeFactory.CreateRegistryItem(registryObject.Hive, registryObject.Key, registryObject.Name, StatusEnumeration.error);
                registry.message = MessageType.FromErrorString(ex.Message);
                items            = new List <ItemType>()
                {
                    registry
                };
            }

            return(items);
        }
Ejemplo n.º 7
0
 protected override ItemType CreateItemTypeWithErrorStatus(string errorMessage)
 {
     return(new Modulo.Collect.OVAL.SystemCharacteristics.Unix.file_item()
     {
         status = StatusEnumeration.error,
         message = MessageType.FromErrorString(errorMessage)
     });
 }
Ejemplo n.º 8
0
        public ItemType CreateFileItemTypesWithError(string path, string fileName, string trustee, string message, StatusEnumeration status)
        {
            ItemType itemType = this.CreateItemTypeForCollect(path, fileName, trustee);

            itemType.message = MessageType.FromErrorString(message);
            itemType.status  = status;
            return(itemType);
        }
        private ItemType CollectItem(Dictionary <string, object> collectParameters)
        {
            var filepath = collectParameters[SearchTextFileContentParameters.filepath.ToString()].ToString();
            var instance = (int)collectParameters[SearchTextFileContentParameters.instance.ToString()];
            var pattern  = collectParameters[SearchTextFileContentParameters.pattern.ToString()].ToString();

            try
            {
                var fileMatchLine = this.TextFileContentDataSource.GetValues(collectParameters).ToList();
                if (fileMatchLine.Count <= 0)
                {
                    return(CreateTextFileContentItemType(filepath, pattern, instance, null));
                }

                return(CreateTextFileContentItemType(filepath, pattern, instance, fileMatchLine.Single()));
            }
            //catch (FileNotFoundException)
            //{
            //    var collectedItem = (textfilecontent_item)CreateTextFileContentItemType(filepath, string.Empty, 0, string.Empty);
            //    collectedItem.status = StatusEnumeration.doesnotexist;
            //    CleanTextFileContentItem(collectedItem);
            //    return collectedItem;
            //}
            catch (Exception ex)
            {
                if (ex is FileNotFoundException || ex is DirectoryNotFoundException)
                {
                    var collectedItem = (textfilecontent_item)CreateTextFileContentItemType(filepath, string.Empty, 0, string.Empty);
                    collectedItem.status = StatusEnumeration.doesnotexist;
                    CleanTextFileContentItem(collectedItem);
                    return(collectedItem);
                }

                /* else if (ex is UnauthorizedAccessException)
                 * {
                 *  var collectedItem = (textfilecontent_item)CreateTextFileContentItemType(filepath, string.Empty, 0, string.Empty);
                 *  collectedItem.status = StatusEnumeration.notcollected;
                 *  CleanTextFileContentItem(collectedItem);
                 *  return collectedItem;
                 * } */
                else
                {
                    var errorMessage = string.Format(ERROR_MESSAGE, ex.GetType().Name + ": " + ex.Message);
                    return(new textfilecontent_item()
                    {
                        status = StatusEnumeration.error, message = MessageType.FromErrorString(errorMessage)
                    });
                }
            }
        }
Ejemplo n.º 10
0
        private IEnumerable <ItemType> CreateSmfItemWithErrorStatus(OVAL.Definitions.EntitySimpleBaseType fmriEntity)
        {
            var newItemWithErrorStatus = new smf_item()
            {
                status  = StatusEnumeration.error,
                message = MessageType.FromErrorString(String.Format(NOT_SUPPORTED_OPERATION_MESSAGE, fmriEntity.operation.ToString())),
                fmri    = new EntityItemStringType()
                {
                    status = StatusEnumeration.error
                }
            };


            return(new ItemType[] { newItemWithErrorStatus });
        }
Ejemplo n.º 11
0
 private void SetErrorStatusForItemType(ItemType systemItem, string exceptionMessage)
 {
     systemItem.status  = StatusEnumeration.error;
     systemItem.message = MessageType.FromErrorString(exceptionMessage);
 }