Пример #1
0
        public AddServer(String monitorName, String remoteIpOrHostName, FullMonitorType tab,
                         MonitorBaseType baseTab, IEnumerable<CAlert> defaultAlerts)
        {
            InitializeComponent();
            perfCounterPCTypeDdl.Visible = false;
            perfCounterCategoryWaitLabel.Visible = true;
            perfCounterCounterNameDdl.Visible = false;
            perfCounterCounterNameWaitLabel.Visible = true;
            perfCounterInstanceNameDdl.Visible = false;
            perfCounterInstanceNameWaitLabel.Visible = true;

            foreach(CAlert c in defaultAlerts)
            {
                switch(c.Type)
                {
                    case AlertType.Email:
                        addServerAlertEmailTextBox.Text = c.Info;
                        break;
                    case AlertType.Phone:
                        addServerAlertSmsTextBox.Text = c.Info;
                        break;
                }

            }
            //NOTE:MonitorName should be the hostname if for some reason HostName isn't populated
            //_hostName = (hostName == "" ? Environment.MachineName : (hostName != "" ? hostName : monitorName));
            IpOrHostName = remoteIpOrHostName == "" ? Environment.MachineName : remoteIpOrHostName;
            FriendlyName = monitorName == "" ? Environment.MachineName + " " + tab : monitorName;

            switch (tab)
            {
                #region cases

                default:
                case FullMonitorType.None:
                case FullMonitorType.PerformanceCounter:
                    _perfCounterPopulation = new Thread(GetPerfCounterTypes) {Name = "PerformanceCounter Start"};
                    _perfCounterPopulation.Start();
                    addServerBaseTabControl.SelectedIndex = (int) baseTab;
                    addServerTabControl.SelectedIndex = (int) tab;
                    break;
                case FullMonitorType.Service:
                    _serviceMonitorPopulation = new Thread(GetServices) {Name = "ServiceMonitor Start"};
                    _serviceMonitorPopulation.Start();
                    addServerBaseTabControl.SelectedIndex = (int) baseTab;
                    addServerTabControl.SelectedIndex = (int) tab;
                    break;
                case FullMonitorType.EventLog:
                    _eventMonitorPopulation = new Thread(GetEvents) {Name = "EventMonitor Start"};
                    _eventMonitorPopulation.Start();
                    addServerBaseTabControl.SelectedIndex = (int) baseTab;
                    addServerTabControl.SelectedIndex = (int) tab;
                    break;
                case FullMonitorType.Basic:
                    //_basicMonitorPopulation = new Thread(GetBasics) {Name = "BasicMonitor Start"};
                    //_basicMonitorPopulation.Start();
                    addServerBaseTabControl.SelectedIndex = (int) baseTab;
                    //addServerTabControl.SelectedIndex = (int) tab;
                    break;
                case FullMonitorType.Common:
                    //commonBaseTab.Focus();
                    //commonBaseTab.Select();
                    _commonMonitorPopulation = new Thread(GetCommon) {Name = "CommonMonitor Start"};
                    _commonMonitorPopulation.Start();
                    addServerBaseTabControl.SelectedIndex = (int) baseTab;
                    break;
                #endregion
            }

            ReturnValue = FullMonitorType.None;
        }
Пример #2
0
        public AddServer(String monitorName, String remoteIpOrHostName, FullMonitorType tab,
                         MonitorBaseType baseTab, IEnumerable<CAlert> defaultAlerts, IMonitor repopulateMonitor)
        {
            InitializeComponent();
            perfCounterPCTypeDdl.Visible = false;
            perfCounterCategoryWaitLabel.Visible = true;
            perfCounterCounterNameDdl.Visible = false;
            perfCounterCounterNameWaitLabel.Visible = true;
            perfCounterInstanceNameDdl.Visible = false;
            perfCounterInstanceNameWaitLabel.Visible = true;

            foreach (CAlert c in defaultAlerts)
            {
                switch (c.Type)
                {
                    case AlertType.Email:
                        addServerAlertEmailTextBox.Text = c.Info;
                        break;
                    case AlertType.Phone:
                        addServerAlertSmsTextBox.Text = c.Info;
                        break;
                }

            }
            //NOTE:MonitorName should be the hostname if for some reason HostName isn't populated
            //_hostName = (hostName == "" ? Environment.MachineName : (hostName != "" ? hostName : monitorName));
            IpOrHostName = remoteIpOrHostName == "" ? Environment.MachineName : remoteIpOrHostName;
            FriendlyName = monitorName == "" ? Environment.MachineName + " " + tab : monitorName;

            switch (repopulateMonitor.Type)
            {
                #region cases
                case FullMonitorType.PerformanceCounter:
                    addServerBaseTabControl.SelectedIndex = (int)baseTab;
                    addServerTabControl.SelectedIndex = (int)tab;
                    if (repopulateMonitor.Common)
                    {
                        CommonRepopulate(repopulateMonitor);
                        ReturnValue = FullMonitorType.Common;
                    }
                    else
                    {
                        ReturnValue = repopulateMonitor.Type;
                        PerfCounterRepopulate((PfcMonitor)repopulateMonitor);
                    }
                    break;
                case FullMonitorType.Service:
                    addServerBaseTabControl.SelectedIndex = (int)baseTab;
                    addServerTabControl.SelectedIndex = (int)tab;
                    if (repopulateMonitor.Common)
                    {
                        CommonRepopulate(repopulateMonitor);
                        ReturnValue = FullMonitorType.Common;
                    }
                    else
                    {
                        ReturnValue = repopulateMonitor.Type;
                        ServiceRepopulate((ServiceMonitor)repopulateMonitor);
                    }
                    break;
                case FullMonitorType.EventLog:
                    addServerBaseTabControl.SelectedIndex = (int)baseTab;
                    addServerTabControl.SelectedIndex = (int)tab;
                    if (repopulateMonitor.Common)
                    {
                        CommonRepopulate(repopulateMonitor);
                        ReturnValue = FullMonitorType.Common;
                    }
                    else
                    {
                        ReturnValue = repopulateMonitor.Type;
                        EventRepopulate((EventMonitor) repopulateMonitor);
                    }
                    break;
                case FullMonitorType.Basic:
                    addServerBaseTabControl.SelectedIndex = (int)baseTab;
                    BasicRepopulate((BasicMonitor)repopulateMonitor);
                    ReturnValue = repopulateMonitor.Type;
                    break;
                case FullMonitorType.Common:
                    addServerBaseTabControl.SelectedIndex = (int)baseTab;
                    if (repopulateMonitor.Common)
                    {
                        CommonRepopulate(repopulateMonitor);
                        ReturnValue = FullMonitorType.Common;
                    }
                    else
                        ReturnValue = repopulateMonitor.Type;
                    break;
                case FullMonitorType.Wmi:
                    addServerBaseTabControl.SelectedIndex = (int)baseTab;
                    if (repopulateMonitor.Common)
                    {
                        CommonRepopulate(repopulateMonitor);
                        ReturnValue = FullMonitorType.Common;
                    }
                    else
                        ReturnValue = repopulateMonitor.Type;
                    break;
                default:
                case FullMonitorType.None:
                    Logger.Instance.Log(this.GetType(), LogType.Debug, "AddServer: Unable to match Monitor Type");
                    this.Close();
                    break;
                    #endregion
            }
        }
Пример #3
0
 private void AddNewServerShow(FullMonitorType tab, MonitorBaseType baseTab)
 {
     AddServer addserver = new AddServer(String.Empty, String.Empty, tab, baseTab, configurationData.Settings.DefaultAlerts);
     AddOwnedForm(addserver);
     addserver.Show();
 }
Пример #4
0
 private void AddSelServerShow(FullMonitorType tab, MonitorBaseType baseTab)
 {
     AddServer addserver = new AddServer(serverBrowser.SelectedNode.Text, serverBrowser.SelectedNode.Text, tab,
                                         baseTab, configurationData.Settings.DefaultAlerts);
     AddOwnedForm(addserver);
     addserver.Show();
 }
Пример #5
0
        private void PopulateGridViewFromServerInfo(FullMonitorType returnValue, IMonitor monitor, Boolean repopulate)
        {
            if (monitor == null)
                return;
            Int32 row = 0;

            if (!repopulate)
            {
                if (serverMonitorList.InvokeRequired)
                {
                    Invoke(new MethodInvoker(() => row = serverMonitorList.Rows.Add()));
                }
                else
                    row = serverMonitorList.Rows.Add();
                _gridViewIndex = row;
            }
            else
                row = _gridViewIndex;

            switch (returnValue)
            {
                case FullMonitorType.Basic:
                    #region Basic
                    BasicMonitor basicMonitor = (BasicMonitor)monitor;
                    if (serverMonitorList.InvokeRequired)
                    {
                        Invoke(new MethodInvoker(() =>
                                                     {
                                                         serverMonitorList.Rows[row].Tag = basicMonitor.Hash;
                                                         serverMonitorList.Rows[row].SetValues(new Object[]
                                                                                                   {
                                                                                                       basicMonitor.Server,
                                                                                                       basicMonitor.FriendlyName,
                                                                                                       "Basic",
                                                                                                       "OK",
                                                                                                       "0",
                                                                                                       basicMonitor.ToString()
                                                                                                   });
                                                     }));
                    }
                    else
                    {
                        serverMonitorList.Rows[row].Tag = basicMonitor.Hash;
                        serverMonitorList.Rows[row].SetValues(new Object[]
                                                              {
                                                                  basicMonitor.Server,
                                                                  basicMonitor.FriendlyName,
                                                                  "Basic",
                                                                  "OK",
                                                                  "0",
                                                                  basicMonitor.ToString()
                                                              });
                    }
                    break;
                    #endregion
                case FullMonitorType.Common:
                    #region Common
                    if (monitor.Type != FullMonitorType.Common) //NOTE: Don't want infinite loop somehow
                        PopulateGridViewFromServerInfo(monitor.Type, monitor, true);
                    else
                        Logger.Instance.Log(this.GetType(), LogType.Info, "Monitor Type was unindentifiable for monitor: " + monitor.ToString());
                    break;
                    #endregion
                case FullMonitorType.EventLog:
                    #region Events
                    EventMonitor eventMonitor = (EventMonitor)monitor;
                    if (serverMonitorList.InvokeRequired)
                    {
                        Invoke(new MethodInvoker(() =>
                                                     {
                                                         serverMonitorList.Rows[row].Tag = eventMonitor.Hash;
                                                         serverMonitorList.Rows[row].SetValues(new Object[]
                                                                                                   {
                                                                                                       eventMonitor.Server,
                                                                                                       eventMonitor.FriendlyName,
                                                                                                       "Event Log",
                                                                                                       "OK",
                                                                                                       "0",
                                                                                                       eventMonitor.ToString()
                                                                                                   });
                                                     }));
                    }
                    else
                    {
                        serverMonitorList.Rows[row].Tag = eventMonitor.Hash;
                        serverMonitorList.Rows[row].SetValues(new Object[]
                                                                  {
                                                                      eventMonitor.Server,
                                                                      eventMonitor.FriendlyName,
                                                                      "Event Log",
                                                                      "OK",
                                                                      "0",
                                                                      eventMonitor.ToString()
                                                                  });
                    }
                    break;
                    #endregion
                case FullMonitorType.PerformanceCounter:
                    #region PerfCounters
                    PfcMonitor pfcMonitor = (PfcMonitor)monitor;
                    if (serverMonitorList.InvokeRequired)
                    {
                        Invoke(new MethodInvoker(() =>
                                                     {
                                                         serverMonitorList.Rows[row].Tag = pfcMonitor.Hash;
                                                         serverMonitorList.Rows[row].SetValues(new Object[]
                                                                                                   {
                                                                                                       pfcMonitor.Server,
                                                                                                       pfcMonitor.FriendlyName,
                                                                                                       "Performance Counter",
                                                                                                       "OK",
                                                                                                       "0",
                                                                                                       pfcMonitor.ToString()
                                                                                                   });
                                                     }));
                    }
                    else
                    {
                        serverMonitorList.Rows[row].Tag = pfcMonitor.Hash;
                        serverMonitorList.Rows[row].SetValues(new Object[]
                                                                  {
                                                                      pfcMonitor.Server,
                                                                      pfcMonitor.FriendlyName,
                                                                      "Performance Counter",
                                                                      "OK",
                                                                      "0",
                                                                      pfcMonitor.ToString()
                                                                  });
                    }
                    break;
                    #endregion
                case FullMonitorType.Service:
                    #region Services
                    ServiceMonitor services = (ServiceMonitor)monitor;
                    if (serverMonitorList.InvokeRequired)
                    {
                        Invoke(new MethodInvoker(() =>
                                                     {
                                                         serverMonitorList.Rows[row].Tag = services.Hash;
                                                         serverMonitorList.Rows[row].SetValues(new Object[]
                                                                                                   {
                                                                                                       services.Server,
                                                                                                       services.FriendlyName,
                                                                                                       "Service",
                                                                                                       "OK",
                                                                                                       "0",
                                                                                                       services.ToString()
                                                                                                   });
                                                     }));
                    }
                    else
                    {
                        serverMonitorList.Rows[row].Tag = services.Hash;
                        serverMonitorList.Rows[row].SetValues(new Object[]
                                                                  {
                                                                      services.Server,
                                                                      services.FriendlyName,
                                                                      "Service",
                                                                      "OK",
                                                                      "0",
                                                                      services.ToString()
                                                                  });
                    }
                    break;
                    #endregion
                case FullMonitorType.Wmi:
                    #region Wmi
                    WmiMonitor wmiMonitor = (WmiMonitor)monitor;
                    if (serverMonitorList.InvokeRequired)
                    {
                        Invoke(new MethodInvoker(() =>
                                                     {
                                                         serverMonitorList.Rows[row].Tag = wmiMonitor.Hash;
                                                         serverMonitorList.Rows[row].SetValues(new Object[]
                                                                                                   {
                                                                                                       wmiMonitor.Server,
                                                                                                       wmiMonitor.FriendlyName,
                                                                                                       "Wmi",
                                                                                                       "OK",
                                                                                                       "0",
                                                                                                       wmiMonitor.ToString()
                                                                                                   });
                                                     }));
                    }
                    else
                    {
                        serverMonitorList.Rows[row].Tag = wmiMonitor.Hash;
                        serverMonitorList.Rows[row].SetValues(new Object[]
                                                                  {
                                                                      wmiMonitor.Server,
                                                                      wmiMonitor.FriendlyName,
                                                                      "Wmi",
                                                                      "OK",
                                                                      "0",
                                                                      wmiMonitor.ToString()
                                                                  });
                    }
                    break;
                    #endregion
                case FullMonitorType.None:
                default:
                    break;
            }
        }