Exemplo n.º 1
0
 private void cmdOK_Click(object sender, EventArgs e)
 {
     try
     {
         if (SelectedEntry == null)
         {
             SelectedEntry = new NotifierEntry();
         }
         SelectedEntry.Name        = txtName.Text;
         SelectedEntry.Enabled     = chkEnabled.Checked;
         SelectedEntry.AlertLevel  = (AlertLevel)cboAlertLevel.SelectedIndex;
         SelectedEntry.DetailLevel = (DetailLevel)cboDetailLevel.SelectedIndex;
         SelectedEntry.NotifierRegistrationName = editingNotifierEntry.NotifierRegistrationName;
         SelectedEntry.InitialConfiguration     = editingNotifierEntry.InitialConfiguration;
         SelectedEntry.AlertForCollectors.Clear();
         if (editingNotifierEntry.AlertForCollectors != null && editingNotifierEntry.AlertForCollectors.Count > 0)
         {
             SelectedEntry.AlertForCollectors.AddRange(editingNotifierEntry.AlertForCollectors.ToArray());
         }
         SelectedEntry.AttendedOptionOverride = (AttendedOption)cboAttendedOptionOverride.SelectedIndex;
         SelectedEntry.ServiceWindows.CreateFromConfig(editingNotifierEntry.ServiceWindows.ToConfig());
         SelectedEntry.ConfigVariables = new List <ConfigVariable>();
         SelectedEntry.ConfigVariables.AddRange((from ConfigVariable cv in editingNotifierEntry.ConfigVariables
                                                 select cv.Clone()).ToArray());
         SelectedEntry.CreateAndConfigureEntry(SelectedEntry.NotifierRegistrationName);
         DialogResult = System.Windows.Forms.DialogResult.OK;
         Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Exemplo n.º 2
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();
        }