Exemple #1
0
        public static CollectorEntry CreateNewCollector(CollectorEntry parentCollectorEntry = null)
        {
            CollectorEntry     newCollectorEntry  = null;
            SelectNewAgentType selectNewAgentType = new SelectNewAgentType();

            selectNewAgentType.InitialRegistrationName = "";
            if (selectNewAgentType.ShowCollectorSelection() == System.Windows.Forms.DialogResult.OK)
            {
                LastLaunchAddEntryOption     = selectNewAgentType.SelectedPreset == null;
                LastShowRawEditOnStartOption = selectNewAgentType.ImportConfigAfterSelect;
                newCollectorEntry            = new CollectorEntry();
                if (parentCollectorEntry != null)
                {
                    newCollectorEntry.ParentCollectorId = parentCollectorEntry.UniqueId;
                }
                RegisteredAgent ar = null;
                if (selectNewAgentType.SelectedPreset != null)
                {
                    ar = RegisteredAgentCache.GetRegisteredAgentByClassName(selectNewAgentType.SelectedPreset.AgentClassName);
                }
                else if (selectNewAgentType.SelectedAgent != null)
                {
                    ar = selectNewAgentType.SelectedAgent;
                }
                else
                {
                    return(null);
                }

                if (ar == null) //in case agent is not loaded or available
                {
                    return(null);
                }
                else if (ar.ClassName != "QuickMon.Collectors.Folder")
                {
                    string initialConfig = "";
                    if (selectNewAgentType.SelectedPreset != null)
                    {
                        initialConfig          = MacroVariables.FormatVariables(selectNewAgentType.SelectedPreset.Config);
                        newCollectorEntry.Name = selectNewAgentType.SelectedPreset.Description;
                    }
                    newCollectorEntry.CreateAndConfigureEntry(ar.ClassName, initialConfig, true, false);
                }
                else
                {
                    newCollectorEntry.IsFolder = true;
                    newCollectorEntry.CollectorRegistrationDisplayName = ar.DisplayName;
                    newCollectorEntry.CollectorRegistrationName        = ar.Name;
                }
            }
            return(newCollectorEntry);
        }
Exemple #2
0
        public static List <CollectorEntry> GetCollectorEntriesFromString(string xmlString, bool preloadCollectorInstances = false, List <ConfigVariable> monitorPackVars = null)
        {
            List <CollectorEntry> collectors        = new List <CollectorEntry>();
            XmlDocument           collectorEntryXml = new XmlDocument();

            collectorEntryXml.LoadXml(xmlString);
            XmlElement root = collectorEntryXml.DocumentElement;

            foreach (XmlElement xmlCollectorEntry in root.SelectNodes("collectorEntry"))
            {
                CollectorEntry newCollectorEntry = CollectorEntry.FromConfig(xmlCollectorEntry);
                if (preloadCollectorInstances && !newCollectorEntry.IsFolder)
                {
                    RegisteredAgent currentRA = RegisteredAgentCache.GetRegisteredAgentByClassName("." + newCollectorEntry.CollectorRegistrationName);
                    if (currentRA != null)
                    {
                        newCollectorEntry.CreateAndConfigureEntry(currentRA, monitorPackVars);
                    }
                }
                collectors.Add(newCollectorEntry);
            }
            return(collectors);
        }