示例#1
0
 private void ApplyConfigToControls()
 {
     cmdConfigure.Enabled = editingNotifierEntry == null;
     cboAttendedOptionOverride.SelectedIndex = 0;
     if (editingNotifierEntry != null)
     {
         txtName.Text       = editingNotifierEntry.Name;
         chkEnabled.Checked = editingNotifierEntry.Enabled;
         RegisteredAgent ar = RegisteredAgentCache.GetRegisteredAgentByClassName(editingNotifierEntry.NotifierRegistrationName, false);
         if (ar != null)
         {
             llblNotifierType.Text = ar.DisplayName;
         }
         cboAlertLevel.SelectedIndex  = (int)editingNotifierEntry.AlertLevel;
         cboDetailLevel.SelectedIndex = (int)editingNotifierEntry.DetailLevel;
         if (editingNotifierEntry.Notifier != null && editingNotifierEntry.Notifier.AgentConfig != null)
         {
             INotifierConfig config = (INotifierConfig)editingNotifierEntry.Notifier.AgentConfig;
             lblConfigSummary.Text = config.ConfigSummary;
             if (editingNotifierEntry.Notifier.AttendedRunOption != AttendedOption.AttendedAndUnAttended)
             {
                 editingNotifierEntry.AttendedOptionOverride = editingNotifierEntry.Notifier.AttendedRunOption;
                 cboAttendedOptionOverride.Enabled           = false;
             }
             else
             {
                 cboAttendedOptionOverride.Enabled = true;
             }
         }
         cboAttendedOptionOverride.SelectedIndex = (int)editingNotifierEntry.AttendedOptionOverride;
         SetAlertForCollectors();
         linkLabelServiceWindows.Text = editingNotifierEntry.ServiceWindows.ToString();
         CheckOkEnable();
     }
 }
示例#2
0
        private void cmdOK_Click(object sender, EventArgs e)
        {
            if (lvwAgentType.SelectedItems.Count == 1)
            {
                string configToUse = "";
                if (selectingMonitorPacks)
                {
                    #region Monitor pack
                    if (lvwAgentType.SelectedItems[0].Tag is string)
                    {
                        configToUse = lvwAgentType.SelectedItems[0].Tag.ToString();
                    }
                    else if (lvwAgentType.SelectedItems[0].Tag is QuickMonTemplate)
                    {
                        QuickMonTemplate selectedTemplate = (QuickMonTemplate)(lvwAgentType.SelectedItems[0].Tag);
                        configToUse = selectedTemplate.Config;
                    }
                    if (chkShowCustomConfig.Checked)
                    {
                        RAWXmlEditor editor = new RAWXmlEditor();
                        editor.SelectedMarkup = configToUse;
                        if (editor.ShowDialog() == DialogResult.OK)
                        {
                            configToUse = editor.SelectedMarkup;
                        }
                    }
                    configToUse = FormatTemplateVariables(configToUse);
                    if (configToUse.Length == 0)
                    {
                        return;
                    }

                    MonitorPack mp = new MonitorPack();
                    mp.LoadXml(configToUse);
                    SelectedMonitorPack = mp;
                    #endregion
                }
                else if (selectingCollectorHosts)
                {
                    #region Collector hosts
                    if (lvwAgentType.SelectedItems[0].Tag is CollectorHost)
                    {
                        CollectorHost newCH = (CollectorHost)lvwAgentType.SelectedItems[0].Tag;
                        newCH.UniqueId = "";
                        configToUse    = newCH.ToXml();
                    }
                    else if (lvwAgentType.SelectedItems[0].Tag is QuickMonTemplate)
                    {
                        QuickMonTemplate selectedTemplate = (QuickMonTemplate)(lvwAgentType.SelectedItems[0].Tag);
                        configToUse = selectedTemplate.Config;
                    }
                    if (chkShowCustomConfig.Checked)
                    {
                        RAWXmlEditor editor = new RAWXmlEditor();
                        editor.SelectedMarkup = configToUse;
                        if (editor.ShowDialog() == DialogResult.OK)
                        {
                            configToUse = editor.SelectedMarkup;
                        }
                    }

                    configToUse = FormatTemplateVariables(configToUse);
                    if (configToUse.Length == 0)
                    {
                        return;
                    }

                    CollectorHost cls = CollectorHost.FromXml(configToUse);
                    if (cls != null)
                    {
                        SelectedCollectorHost = cls;
                    }
                    else
                    {
                        MessageBox.Show("The configuration for this template is invalid! Please correct and try again.", "Template", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                    #endregion
                }
                else if (selectingCollectorAgents || selectingNotifierAgents)
                {
                    #region Collector agents
                    RegisteredAgent ra = null;
                    if (lvwAgentType.SelectedItems[0].Tag is RegisteredAgent)
                    {
                        ra = (RegisteredAgent)lvwAgentType.SelectedItems[0].Tag;
                    }
                    else if (lvwAgentType.SelectedItems[0].Tag is QuickMonTemplate)
                    {
                        QuickMonTemplate template = (QuickMonTemplate)lvwAgentType.SelectedItems[0].Tag;
                        ra          = RegisteredAgentCache.GetRegisteredAgentByClassName(template.ForClass, selectingCollectorAgents);
                        configToUse = template.Config;
                    }
                    if (ra != null)
                    {
                        if (System.IO.File.Exists(ra.AssemblyPath))
                        {
                            Assembly collectorEntryAssembly = Assembly.LoadFile(ra.AssemblyPath);
                            SelectedAgent = (IAgent)collectorEntryAssembly.CreateInstance(ra.ClassName);
                            SelectedAgent.AgentClassName        = ra.ClassName;
                            SelectedAgent.AgentClassDisplayName = ra.DisplayName;
                            if (configToUse.Length == 0)
                            {
                                configToUse = SelectedAgent.AgentConfig.GetDefaultOrEmptyXml();
                            }
                            if (chkShowCustomConfig.Checked)
                            {
                                RAWXmlEditor editor = new RAWXmlEditor();
                                editor.SelectedMarkup = configToUse;
                                if (editor.ShowDialog() == DialogResult.OK)
                                {
                                    configToUse = editor.SelectedMarkup;
                                }
                            }
                            try
                            {
                                if ((selectingCollectorAgents && configToUse.StartsWith("<collectorAgent")) || (selectingNotifierAgents && configToUse.StartsWith("<notifierAgent")))
                                {
                                    System.Xml.XmlDocument collectorAgentDoc = new System.Xml.XmlDocument();
                                    collectorAgentDoc.LoadXml(configToUse);
                                    System.Xml.XmlNode configNode = collectorAgentDoc.DocumentElement.SelectSingleNode("config");
                                    if (configNode != null)
                                    {
                                        configToUse = configNode.OuterXml;
                                    }
                                }

                                configToUse = FormatTemplateVariables(configToUse);
                                if (configToUse.Length == 0)
                                {
                                    return;
                                }

                                SelectedAgent.AgentConfig.FromXml(configToUse);
                                DialogResult = DialogResult.OK;
                                Close();
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show("An error occured while processing the config!\r\n" + ex.Message, "Edit config", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                        }
                    }
                    #endregion
                }
                else if (selectingNotifierHosts)
                {
                    #region Notifier hosts
                    if (lvwAgentType.SelectedItems[0].Tag is NotifierHost)
                    {
                        configToUse = ((NotifierHost)lvwAgentType.SelectedItems[0].Tag).ToXml();
                    }
                    else if (lvwAgentType.SelectedItems[0].Tag is QuickMonTemplate)
                    {
                        QuickMonTemplate selectedTemplate = (QuickMonTemplate)(lvwAgentType.SelectedItems[0].Tag);
                        configToUse = selectedTemplate.Config;
                    }

                    if (chkShowCustomConfig.Checked)
                    {
                        RAWXmlEditor editor = new RAWXmlEditor();
                        editor.SelectedMarkup = configToUse;
                        if (editor.ShowDialog() == DialogResult.OK)
                        {
                            configToUse = editor.SelectedMarkup;
                        }
                    }

                    configToUse = FormatTemplateVariables(configToUse);
                    if (configToUse.Length == 0)
                    {
                        return;
                    }

                    NotifierHost cls = NotifierHost.FromXml(configToUse);
                    if (cls != null)
                    {
                        SelectedNotifierHost = cls;
                    }
                    else
                    {
                        MessageBox.Show("The configuration for this template is invalid! Please correct and try again.", "Template", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                    #endregion
                }
                EditAfterCreation = chkEditAfterCreate.Checked;
                DialogResult      = DialogResult.OK;
                Close();
            }
        }
示例#3
0
        private void cmdOK_Click(object sender, EventArgs e)
        {
            if (SelectedEntry == null)
            {
                SelectedEntry = new CollectorEntry();
            }

            SelectedEntry.Name          = txtName.Text;
            SelectedEntry.Enabled       = chkEnabled.Checked;
            SelectedEntry.ExpandOnStart = chkExpandOnStart.Checked;
            SelectedEntry.IsFolder      = currentEditingEntry.IsFolder;
            if (cboParentCollector.SelectedIndex > 0)
            {
                CollectorEntryDisplay ced = (CollectorEntryDisplay)cboParentCollector.SelectedItem;
                SelectedEntry.ParentCollectorId = ced.CE.UniqueId;
            }
            else
            {
                SelectedEntry.ParentCollectorId = "";
            }
            SelectedEntry.CollectOnParentWarning = chkCollectOnParentWarning.Checked && !SelectedEntry.IsFolder;

            //Collector type
            SelectedEntry.CollectorRegistrationName        = currentEditingEntry.CollectorRegistrationName;
            SelectedEntry.CollectorRegistrationDisplayName = currentEditingEntry.CollectorRegistrationDisplayName;

            //Remote agents
            SelectedEntry.EnableRemoteExecute = chkRemoteAgentEnabled.Checked;
            SelectedEntry.ForceRemoteExcuteOnChildCollectors = chkForceRemoteExcuteOnChildCollectors.Checked;
            SelectedEntry.RemoteAgentHostAddress             = txtRemoteAgentServer.Text;
            SelectedEntry.RemoteAgentHostPort = (int)remoteportNumericUpDown.Value;
            SelectedEntry.BlockParentOverrideRemoteAgentHostSettings = chkBlockParentRHOverride.Checked && !chkRemoteAgentEnabled.Checked;
            SelectedEntry.RunLocalOnRemoteHostConnectionFailure      = chkRunLocalOnRemoteHostConnectionFailure.Checked;
            if (chkRemoteAgentEnabled.Checked && SelectedEntry.RemoteAgentHostAddress.Length > 0)
            {
                if (KnownRemoteHosts == null)
                {
                    KnownRemoteHosts = new List <string>();
                }
                if ((from string rh in KnownRemoteHosts
                     where rh.ToLower() == SelectedEntry.RemoteAgentHostAddress.ToLower() + ":" + SelectedEntry.RemoteAgentHostPort.ToString()
                     select rh).Count() == 0
                    )
                {
                    KnownRemoteHosts.Add(SelectedEntry.RemoteAgentHostAddress + ":" + SelectedEntry.RemoteAgentHostPort.ToString());
                }
            }

            //Polling overrides
            if (onlyAllowUpdateOncePerXSecNumericUpDown.Value >= pollSlideFrequencyAfterFirstRepeatSecNumericUpDown.Value)
            {
                pollSlideFrequencyAfterFirstRepeatSecNumericUpDown.Value = onlyAllowUpdateOncePerXSecNumericUpDown.Value + 1;
            }
            if (pollSlideFrequencyAfterFirstRepeatSecNumericUpDown.Value >= pollSlideFrequencyAfterSecondRepeatSecNumericUpDown.Value)
            {
                pollSlideFrequencyAfterSecondRepeatSecNumericUpDown.Value = pollSlideFrequencyAfterFirstRepeatSecNumericUpDown.Value + 1;
            }
            if (pollSlideFrequencyAfterSecondRepeatSecNumericUpDown.Value >= pollSlideFrequencyAfterThirdRepeatSecNumericUpDown.Value)
            {
                pollSlideFrequencyAfterThirdRepeatSecNumericUpDown.Value = pollSlideFrequencyAfterSecondRepeatSecNumericUpDown.Value + 1;
            }

            SelectedEntry.EnabledPollingOverride                 = chkEnablePollingOverride.Checked;
            SelectedEntry.OnlyAllowUpdateOncePerXSec             = (int)onlyAllowUpdateOncePerXSecNumericUpDown.Value;
            SelectedEntry.EnablePollFrequencySliding             = chkEnablePollingFrequencySliding.Checked;
            SelectedEntry.PollSlideFrequencyAfterFirstRepeatSec  = (int)pollSlideFrequencyAfterFirstRepeatSecNumericUpDown.Value;
            SelectedEntry.PollSlideFrequencyAfterSecondRepeatSec = (int)pollSlideFrequencyAfterSecondRepeatSecNumericUpDown.Value;
            SelectedEntry.PollSlideFrequencyAfterThirdRepeatSec  = (int)pollSlideFrequencyAfterThirdRepeatSecNumericUpDown.Value;

            //Alert suppresion
            SelectedEntry.AlertsPaused               = chkAlertsPaused.Checked;
            SelectedEntry.RepeatAlertInXMin          = (int)numericUpDownRepeatAlertInXMin.Value;
            SelectedEntry.RepeatAlertInXPolls        = (int)numericUpDownRepeatAlertInXPolls.Value;
            SelectedEntry.AlertOnceInXMin            = (int)AlertOnceInXMinNumericUpDown.Value;
            SelectedEntry.AlertOnceInXPolls          = (int)AlertOnceInXPollsNumericUpDown.Value;
            SelectedEntry.DelayErrWarnAlertForXSec   = (int)delayAlertSecNumericUpDown.Value;
            SelectedEntry.DelayErrWarnAlertForXPolls = (int)delayAlertPollsNumericUpDown.Value;
            //Corrective scripts
            SelectedEntry.CorrectiveScriptDisabled           = chkCorrectiveScriptDisabled.Checked;
            SelectedEntry.CorrectiveScriptOnWarningPath      = txtCorrectiveScriptOnWarning.Text;
            SelectedEntry.CorrectiveScriptOnErrorPath        = txtCorrectiveScriptOnError.Text;
            SelectedEntry.RestorationScriptPath              = txtRestorationScript.Text;
            SelectedEntry.CorrectiveScriptsOnlyOnStateChange = chkOnlyRunCorrectiveScriptsOnStateChange.Checked;
            //Service windows
            SelectedEntry.ServiceWindows.CreateFromConfig(currentEditingEntry.ServiceWindows.ToConfig());
            SelectedEntry.ConfigVariables = new List <ConfigVariable>();
            SelectedEntry.ConfigVariables.AddRange((from ConfigVariable cv in currentEditingEntry.ConfigVariables
                                                    select cv.Clone()).ToArray());

            if (SelectedEntry.IsFolder)
            {
                SelectedEntry.Collector = null;
            }
            else
            {
                SelectedEntry.InitialConfiguration = currentEditingEntry.InitialConfiguration;
                RegisteredAgent currentRA = null;
                currentRA = RegisteredAgentCache.GetRegisteredAgentByClassName("." + SelectedEntry.CollectorRegistrationName);
                if (currentRA != null)
                {
                    try
                    {
                        SelectedEntry.CreateAndConfigureEntry(currentRA, monitorPack.ConfigVariables);
                    }
                    catch (Exception ex)
                    {
                        SelectedEntry.LastMonitorState.State = CollectorState.ConfigurationError;
                        SelectedEntry.Enabled = false;
                        SelectedEntry.LastMonitorState.RawDetails = ex.Message;
                    }
                }
                else
                {
                    SelectedEntry.LastMonitorState.State = CollectorState.ConfigurationError;
                    SelectedEntry.Enabled = false;
                    SelectedEntry.LastMonitorState.RawDetails = string.Format("Collector '{0}' cannot be loaded as the type '{1}' is not registered!", SelectedEntry.Name, SelectedEntry.CollectorRegistrationName);
                }
            }

            DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }
示例#4
0
 private void cmdOK_Click(object sender, EventArgs e)
 {
     if (lvwAgentType.SelectedItems.Count == 1)
     {
         RegisteredAgent ra          = null;
         string          configToUse = "";
         if (lvwAgentType.SelectedItems[0].Tag is RegisteredAgent)
         {
             ra           = (RegisteredAgent)lvwAgentType.SelectedItems[0].Tag;
             TemplateUsed = false;
         }
         else if (lvwAgentType.SelectedItems[0].Tag is QuickMonTemplate)
         {
             QuickMonTemplate template = (QuickMonTemplate)lvwAgentType.SelectedItems[0].Tag;
             ra           = RegisteredAgentCache.GetRegisteredAgentByClassName(template.ForClass, selectingCollectors);
             configToUse  = template.Config;
             TemplateUsed = true;
         }
         if (ra != null)
         {
             if (System.IO.File.Exists(ra.AssemblyPath))
             {
                 Assembly collectorEntryAssembly = Assembly.LoadFile(ra.AssemblyPath);
                 SelectedAgent = (IAgent)collectorEntryAssembly.CreateInstance(ra.ClassName);
                 SelectedAgent.AgentClassName        = ra.ClassName.Replace("QuickMon.Collectors.", "").Replace("QuickMon.Notifiers.", "");
                 SelectedAgent.AgentClassDisplayName = ra.DisplayName;
                 if (configToUse.Length == 0)
                 {
                     configToUse = SelectedAgent.AgentConfig.GetDefaultOrEmptyXml();
                 }
                 if (chkShowCustomConfig.Checked)
                 {
                     RAWXmlEditor editor = new RAWXmlEditor();
                     editor.SelectedMarkup = configToUse;
                     if (editor.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                     {
                         configToUse = editor.SelectedMarkup;
                     }
                 }
                 try
                 {
                     if (selectingCollectors && configToUse.StartsWith("<collectorAgent"))
                     {
                         SelectedAgent = CollectorHost.GetCollectorAgentFromString(configToUse);
                     }
                     else if (!selectingCollectors && configToUse.StartsWith("<notifierAgent"))
                     {
                         SelectedAgent = NotifierHost.GetNotifierAgentFromString(configToUse);
                     }
                     else
                     {
                         SelectedAgent.AgentConfig.FromXml(configToUse);
                     }
                     DialogResult = System.Windows.Forms.DialogResult.OK;
                     Close();
                 }
                 catch (Exception ex)
                 {
                     MessageBox.Show("An error occured while processing the config!\r\n" + ex.Message, "Edit config", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                 }
             }
         }
     }
 }