Пример #1
0
        private IMonitor PopulateConfigurationDataFromServerInfo(AddServer addServerForm)
        {
            List<CAlert> alerts = new List<CAlert>(2);
            //Boolean alertsExist = addServerForm.GetAlerts(out alerts);
            //alerts =
            if (addServerForm.addServerAlertEmailOption.CheckState == CheckState.Checked)
            {
                EmailAlert ealert = new EmailAlert { Info = addServerForm.addServerAlertEmailTextBox.Text };
                if (!configurationData.Settings.IsDefaultAlert(ealert))
                    alerts.Add(ealert);
            }
            if (addServerForm.addServerAlertSmsOption.CheckState == CheckState.Checked)
            {
                SmsAlert salert = new SmsAlert { Info = addServerForm.addServerAlertSmsTextBox.Text };
                if (!configurationData.Settings.IsDefaultAlert(salert))
                    alerts.Add(salert);
            }

            Boolean alertsExist = alerts.Count > 0 && (addServerForm.addServerAlertEmailOption.Checked | addServerForm.addServerAlertSmsOption.Checked);
            try
            {
                switch (addServerForm.ReturnValue)
                {
                    case FullMonitorType.Basic:
                        #region Basic
                        BasicMonitor basicMonitor = addServerForm.GetBasicMonitor();
                        if (alertsExist)
                        {
                            foreach (CAlert alert in alerts)
                            {
                                //if (!configurationData.Settings.IsDefaultAlert(alert))
                                //{
                                    basicMonitor.AlertInfo.Add(alert);
                                //}
                            }
                        }
                        //else
                        //{
                        //    basicMonitor.AlertInfo.AddRange(configurationData.Settings.DefaultAlerts);
                        //}
                        if (addServerForm.Tag == null)
                            configurationData.BasicMonitors.Add(basicMonitor);
                        else
                        {
                            configurationData.BasicMonitors.Remove(addServerForm.Tag.ToString());
                            configurationData.BasicMonitors.Add(basicMonitor);
                        }
                        configurationData.ExportToXml(_configPath);
                        MonitorScheduler.Scheduler.SetMonitors(configurationData);
                        return basicMonitor;
                        #endregion
                    case FullMonitorType.Common:
                        #region Common

                        /*
                         * - Hard Drive Usage (dropdown list of C:\, D:\, etc)
                         * - Memory Usage
                         * - Swap/page file usage
                         * - CPU Usage
                         * - Process State (e.g. explorer.exe)
                         * - Service State (e.g. Intelligent Background Transfer Service)
                         */
                        List<CAlert> validAlerts = new List<CAlert>(2);
                        if (alertsExist)
                        {
                            foreach (CAlert alert in alerts)
                            {
                                //if (!configurationData.Settings.IsDefaultAlert(alert))
                                //{
                                    validAlerts.Add(alert);
                                //}
                            }
                        }

                        switch (addServerForm.CommonType)
                        {
                            case CommonMonitorType.HddUsage: //Pfc
                                PfcMonitor hddUsage = (PfcMonitor) addServerForm.GetCommonMonitor();
                                hddUsage.AlertInfo.AddRange(validAlerts);
                                if (addServerForm.Tag == null)
                                    configurationData.PfcMonitors.Add(hddUsage);
                                else
                                {
                                    configurationData.PfcMonitors.Remove(addServerForm.Tag.ToString());
                                    configurationData.PfcMonitors.Add(hddUsage);
                                }
                                //if (!alertsExist)
                                //{
                                //    hddUsage.AlertInfo.AddRange(configurationData.Settings.DefaultAlerts);
                                //}
                                configurationData.ExportToXml(_configPath);
                                MonitorScheduler.Scheduler.SetMonitors(configurationData);
                                return hddUsage;
                            case CommonMonitorType.CpuUsage: //Pfc
                                PfcMonitor cpuUsage = (PfcMonitor) addServerForm.GetCommonMonitor();
                                cpuUsage.AlertInfo.AddRange(validAlerts);
                                if (addServerForm.Tag == null)
                                    configurationData.PfcMonitors.Add(cpuUsage);
                                else
                                {
                                    configurationData.PfcMonitors.Remove(addServerForm.Tag.ToString());
                                    configurationData.PfcMonitors.Add(cpuUsage);
                                }
                                //if (!alertsExist)
                                //{
                                //    cpuUsage.AlertInfo.AddRange(configurationData.Settings.DefaultAlerts);
                                //}
                                configurationData.ExportToXml(_configPath);
                                MonitorScheduler.Scheduler.SetMonitors(configurationData);
                                return cpuUsage;
                            case CommonMonitorType.MemoryUsage: //Wmi
                                WmiMonitor memoryUsage = (WmiMonitor) addServerForm.GetCommonMonitor();
                                memoryUsage.AlertInfo.AddRange(validAlerts);
                                if (addServerForm.Tag == null)
                                    configurationData.WmiMonitors.Add(memoryUsage);
                                else
                                {
                                    configurationData.WmiMonitors.Remove(addServerForm.Tag.ToString());
                                    configurationData.WmiMonitors.Add(memoryUsage);
                                }
                                //if (!alertsExist)
                                //{
                                //    memoryUsage.AlertInfo.AddRange(configurationData.Settings.DefaultAlerts);
                                //}
                                configurationData.ExportToXml(_configPath);
                                MonitorScheduler.Scheduler.SetMonitors(configurationData);
                                return memoryUsage;
                            case CommonMonitorType.ProcessState: //Pfc
                                PfcMonitor processState = (PfcMonitor) addServerForm.GetCommonMonitor();
                                processState.AlertInfo.AddRange(validAlerts);
                                if (addServerForm.Tag == null)
                                    configurationData.PfcMonitors.Add(processState);
                                else
                                {
                                    configurationData.PfcMonitors.Remove(addServerForm.Tag.ToString());
                                    configurationData.PfcMonitors.Add(processState);
                                }
                                //if (!alertsExist)
                                //{
                                //    processState.AlertInfo.AddRange(configurationData.Settings.DefaultAlerts);
                                //}
                                configurationData.ExportToXml(_configPath);
                                MonitorScheduler.Scheduler.SetMonitors(configurationData);
                                return processState;
                            case CommonMonitorType.ServiceState: //Service
                                ServiceMonitor serviceState = (ServiceMonitor) addServerForm.GetCommonMonitor();
                                serviceState.AlertInfo.AddRange(validAlerts);
                                if (addServerForm.Tag == null)
                                    configurationData.ServiceMonitors.Add(serviceState);
                                else
                                {
                                    configurationData.ServiceMonitors.Remove(addServerForm.Tag.ToString());
                                    configurationData.ServiceMonitors.Add(serviceState);
                                }
                                //if (!alertsExist)
                                //{
                                //    serviceState.AlertInfo.AddRange(configurationData.Settings.DefaultAlerts);
                                //}
                                configurationData.ExportToXml(_configPath);
                                MonitorScheduler.Scheduler.SetMonitors(configurationData);
                                return serviceState;
                            case CommonMonitorType.SwapFileUsage: //Pfc
                                PfcMonitor swapFileUsage = (PfcMonitor) addServerForm.GetCommonMonitor();
                                swapFileUsage.AlertInfo.AddRange(validAlerts);
                                if (addServerForm.Tag == null)
                                    configurationData.PfcMonitors.Add(swapFileUsage);
                                else
                                {
                                    configurationData.PfcMonitors.Remove(addServerForm.Tag.ToString());
                                    configurationData.PfcMonitors.Add(swapFileUsage);
                                }
                                //if (!alertsExist)
                                //{
                                //    swapFileUsage.AlertInfo.AddRange(configurationData.Settings.DefaultAlerts);
                                //}
                                configurationData.ExportToXml(_configPath);
                                MonitorScheduler.Scheduler.SetMonitors(configurationData);
                                return swapFileUsage;
                            case CommonMonitorType.None:
                            default:
                                Logger.Instance.Log(this.GetType(), LogType.Info,
                                                    "CommonType had an invalid value: unable to populate a Monitor correctly");
                                break;
                        }
                        return null;

                        #endregion
                    case FullMonitorType.EventLog:
                        #region Events
                        EventMonitor eventMonitor = addServerForm.GetEventMonitor();
                        if (alertsExist)
                        {
                            foreach (CAlert alert in alerts)
                            {
                                //if (!configurationData.Settings.IsDefaultAlert(alert))
                                //{
                                    eventMonitor.AlertInfo.Add(alert);
                                //}
                            }
                        }
                        //else
                        //{
                        //    eventMonitor.AlertInfo.AddRange(configurationData.Settings.DefaultAlerts);
                        //}
                        if (addServerForm.Tag == null)
                            configurationData.EventMonitors.Add(eventMonitor);
                        else
                        {
                            configurationData.EventMonitors.Remove(addServerForm.Tag.ToString());
                            configurationData.EventMonitors.Add(eventMonitor);
                        }
                        configurationData.ExportToXml(_configPath);
                        MonitorScheduler.Scheduler.SetMonitors(configurationData);
                        return eventMonitor;
                        #endregion
                    case FullMonitorType.PerformanceCounter:
                        #region PerfCounters

                        PfcMonitor pfcMonitor = addServerForm.GetPfcMonitor();
                        if (alertsExist)
                        {
                            foreach (CAlert alert in alerts)
                            {
                                //if (!configurationData.Settings.IsDefaultAlert(alert))
                                //{
                                    pfcMonitor.AlertInfo.Add(alert);
                                //}
                            }
                        }
                        //else
                        //{
                        //    pfcMonitor.AlertInfo.AddRange(configurationData.Settings.DefaultAlerts);
                        //}
                        if (addServerForm.Tag == null)
                            configurationData.PfcMonitors.Add(pfcMonitor);
                        else
                        {
                            configurationData.PfcMonitors.Remove(addServerForm.Tag.ToString());
                            configurationData.PfcMonitors.Add(pfcMonitor);
                        }
                        configurationData.ExportToXml(_configPath);
                        MonitorScheduler.Scheduler.SetMonitors(configurationData);
                        return pfcMonitor;

                        #endregion
                    case FullMonitorType.Service:
                        #region Services

                        ServiceMonitor serviceMonitor = addServerForm.GetServiceMonitor();
                        if (alertsExist)
                        {
                            foreach (CAlert alert in alerts)
                            {
                                //if (!configurationData.Settings.IsDefaultAlert(alert))
                                //{
                                    serviceMonitor.AlertInfo.Add(alert);
                                //}
                            }
                        }
                        //else
                        //{
                        //    serviceMonitor.AlertInfo.AddRange(configurationData.Settings.DefaultAlerts);
                        //}
                        if (addServerForm.Tag == null)
                            configurationData.ServiceMonitors.Add(serviceMonitor);
                        else
                        {
                            configurationData.ServiceMonitors.Remove(addServerForm.Tag.ToString());
                            configurationData.ServiceMonitors.Add(serviceMonitor);
                        }
                        configurationData.ExportToXml(_configPath);
                        MonitorScheduler.Scheduler.SetMonitors(configurationData);
                        return serviceMonitor;

                        #endregion
                    case FullMonitorType.Wmi:
                        #region Wmi (For future use)

                        WmiMonitor wmiMonitor = (WmiMonitor)addServerForm.GetCommonMonitor();
                        //NOTE: need a GetWmiMonitor() later on, potentially
                        if (alertsExist)
                        {
                            foreach (CAlert alert in alerts)
                            {
                                //if (!configurationData.Settings.IsDefaultAlert(alert))
                                //{
                                    wmiMonitor.AlertInfo.Add(alert);
                                //}
                            }
                        }
                        //else
                        //{
                        //    wmiMonitor.AlertInfo.AddRange(configurationData.Settings.DefaultAlerts);
                        //}
                        if (addServerForm.Tag == null)
                            configurationData.WmiMonitors.Add(wmiMonitor);
                        else
                        {
                            configurationData.WmiMonitors.Remove(addServerForm.Tag.ToString());
                            configurationData.WmiMonitors.Add(wmiMonitor);
                        }
                        configurationData.ExportToXml(_configPath);
                        MonitorScheduler.Scheduler.SetMonitors(configurationData);
                        return wmiMonitor;

                        #endregion
                    case FullMonitorType.None:
                    default:
                        return null;
                }

            }
            catch (Exception ex)
            {
                Logger.Instance.LogException(this.GetType(), ex);
                MessageBox.Show(this, "Unable to save the Monitor, please check the log for details.",
                                "Error Saving Monitor", MessageBoxButtons.OK);
                return null;
            }
        }
Пример #2
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();
 }
Пример #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 ServerMonitorListCellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0)
                return;

            String hash = serverMonitorList.Rows[e.RowIndex].Tag.ToString();
            _gridViewIndex = e.RowIndex;
            IMonitor monitor = configurationData[hash];
            switch (monitor.Type)
            {
                case FullMonitorType.Basic:
                    #region Basic
                    BasicMonitor basic = (BasicMonitor)monitor;
                    AddServer basicAddServer;
                    if (basic.Common)
                    {

                        if (basic.AlertInfo.Count > 0)
                            basicAddServer = new AddServer(basic.FriendlyName, String.Empty, FullMonitorType.Basic,
                                                         MonitorBaseType.Basic, basic.AlertInfo, basic);
                        else
                            basicAddServer = new AddServer(basic.FriendlyName, String.Empty, FullMonitorType.Basic,
                                                         MonitorBaseType.Basic,
                                                         configurationData.Settings.DefaultAlerts, basic);
                    }
                    else
                    {
                        if (basic.AlertInfo.Count > 0)
                            basicAddServer = new AddServer(basic.FriendlyName, String.Empty, FullMonitorType.Basic,
                                                           MonitorBaseType.Basic, basic.AlertInfo);
                        else
                            basicAddServer = new AddServer(basic.FriendlyName, String.Empty, FullMonitorType.Basic,
                                                           MonitorBaseType.Basic,
                                                           configurationData.Settings.DefaultAlerts, basic);
                    }
                    basicAddServer.Tag = hash;
                    RepopulateSelServer(basicAddServer);
                    break;
                    #endregion
                case FullMonitorType.EventLog:
                    #region EventLog
                    EventMonitor events = (EventMonitor)monitor;
                    AddServer eventAddServer;
                    if (events.Common)
                    {
                        if (events.AlertInfo.Count > 0)
                            eventAddServer = new AddServer(events.FriendlyName, events.Server, FullMonitorType.EventLog,
                                                         MonitorBaseType.Advanced, events.AlertInfo, events);
                        else
                            eventAddServer = new AddServer(events.FriendlyName, events.Server, FullMonitorType.EventLog,
                                                         MonitorBaseType.Advanced,
                                                         configurationData.Settings.DefaultAlerts, events);
                    }
                    else
                    {
                        if (events.AlertInfo.Count > 0)
                            eventAddServer = new AddServer(events.FriendlyName, events.Server, FullMonitorType.EventLog,
                                                           MonitorBaseType.Advanced, events.AlertInfo, events);
                        else
                            eventAddServer = new AddServer(events.FriendlyName, events.Server, FullMonitorType.EventLog,
                                                           MonitorBaseType.Advanced,
                                                           configurationData.Settings.DefaultAlerts, events);
                    }
                    eventAddServer.Tag = hash;
                    RepopulateSelServer(eventAddServer);
                    break;
                    #endregion
                case FullMonitorType.PerformanceCounter:
                    #region PerformanceCounter
                    PfcMonitor pfc = (PfcMonitor)monitor;
                    AddServer pfcAddServer;
                    if (pfc.Common)
                    {
                        if (pfc.AlertInfo.Count > 0)
                            pfcAddServer = new AddServer(pfc.FriendlyName, pfc.Server, FullMonitorType.PerformanceCounter,
                                                         MonitorBaseType.Common, pfc.AlertInfo, pfc);
                        else
                            pfcAddServer = new AddServer(pfc.FriendlyName, pfc.Server, FullMonitorType.PerformanceCounter,
                                                         MonitorBaseType.Common,
                                                         configurationData.Settings.DefaultAlerts, pfc);
                    }
                    else
                    {
                        if (pfc.AlertInfo.Count > 0)
                            pfcAddServer = new AddServer(pfc.FriendlyName, pfc.Server,
                                                         FullMonitorType.PerformanceCounter,
                                                         MonitorBaseType.Advanced, pfc.AlertInfo, pfc);
                        else
                            pfcAddServer = new AddServer(pfc.FriendlyName, pfc.Server,
                                                         FullMonitorType.PerformanceCounter,
                                                         MonitorBaseType.Advanced,
                                                         configurationData.Settings.DefaultAlerts, pfc);
                    }
                    pfcAddServer.Tag = hash;
                    RepopulateSelServer(pfcAddServer);
                    break;
                    #endregion
                case FullMonitorType.Service:
                    #region Service
                    ServiceMonitor service = (ServiceMonitor)monitor;
                    AddServer serviceAddServer;
                    if (service.Common)
                    {
                        if (service.AlertInfo.Count > 0)
                            serviceAddServer = new AddServer(service.FriendlyName, service.Server,
                                                             FullMonitorType.Service,
                                                             MonitorBaseType.Common, service.AlertInfo, service);
                        else
                            serviceAddServer = new AddServer(service.FriendlyName, service.Server,
                                                             FullMonitorType.Service,
                                                             MonitorBaseType.Common,
                                                             configurationData.Settings.DefaultAlerts, service);
                    }
                    else
                    {
                        if (service.AlertInfo.Count > 0)
                            serviceAddServer = new AddServer(service.FriendlyName, service.Server,
                                                             FullMonitorType.Service,
                                                             MonitorBaseType.Advanced, service.AlertInfo, service);
                        else
                            serviceAddServer = new AddServer(service.FriendlyName, service.Server,
                                                             FullMonitorType.Service,
                                                             MonitorBaseType.Advanced,
                                                             configurationData.Settings.DefaultAlerts, service);
                    }
                    serviceAddServer.Tag = hash;
                    RepopulateSelServer(serviceAddServer);
                    break;
                    #endregion
                case FullMonitorType.Wmi:
                    #region Wmi
                    WmiMonitor wmi = (WmiMonitor)monitor;
                    AddServer wmiAddServer;
                    if (wmi.Common)
                    {
                        if (wmi.AlertInfo.Count > 0)
                            wmiAddServer = new AddServer(wmi.FriendlyName, wmi.Server, FullMonitorType.Wmi,
                                                         MonitorBaseType.Common, wmi.AlertInfo, wmi);
                        else
                            wmiAddServer = new AddServer(wmi.FriendlyName, wmi.Server, FullMonitorType.Wmi,
                                                         MonitorBaseType.Common,
                                                         configurationData.Settings.DefaultAlerts, wmi);
                    }
                    else
                    {
                        if (wmi.AlertInfo.Count > 0)
                            wmiAddServer = new AddServer(wmi.FriendlyName, wmi.Server, FullMonitorType.Wmi,
                                                         MonitorBaseType.Common, wmi.AlertInfo, wmi);
                        else
                            wmiAddServer = new AddServer(wmi.FriendlyName, wmi.Server, FullMonitorType.Wmi,
                                                         MonitorBaseType.Common,
                                                         configurationData.Settings.DefaultAlerts, wmi);
                    }
                    wmiAddServer.Tag = hash;
                    RepopulateSelServer(wmiAddServer);
                    break;
                    #endregion
            }
        }
Пример #5
0
 private void RepopulateSelServer(AddServer addserver)
 {
     AddOwnedForm(addserver);
     addserver.Show();
 }
Пример #6
0
        public void RepopulateSelServerResult(AddServer addserver)
        {
            if (addserver.DialogResult == DialogResult.OK)
            {
                IMonitor monitor = PopulateConfigurationDataFromServerInfo(addserver);
                PopulateGridViewFromServerInfo(addserver.ReturnValue, monitor, addserver.Tag != null ? true : false);
                _gridViewIndex = -1;
            }

            if (addserver.ToLog != "")
                Log(addserver.ToLog.TrimEnd(new[] { '\r', '\n' }));
        }