Ejemplo n.º 1
0
        public void SaveTarget(DbccTargetInfo target, int userId)
        {
            var originalTarget = GetTarget(target.Id);
            var now            = DateTime.UtcNow;

            _sqlRepository.UpdateDbccTarget(target.Id, target.Database, target.IsActive);

            var audits = new List <ConfigurationAudit>();

            if (!originalTarget.Database.Equals(target.Database))
            {
                audits.Add(new ConfigurationAudit
                {
                    ServerName = target.Server,
                    FieldName  = ConfigurationAuditFields.MonitoringTargetDatabase,
                    OldValue   = originalTarget.Database,
                    NewValue   = target.Database,
                    UserId     = userId,
                    CreatedOn  = now
                });
            }
            if (!originalTarget.IsActive.Equals(target.IsActive))
            {
                audits.Add(new ConfigurationAudit
                {
                    ServerName = target.Server,
                    FieldName  = ConfigurationAuditFields.MonitoringEnabled,
                    OldValue   = originalTarget.IsActive.ToString(),
                    NewValue   = target.IsActive.ToString(),
                    UserId     = userId,
                    CreatedOn  = now
                });
            }

            //If there are no more active targets, disable view-based monitoring
            if (_sqlRepository.ListDbccTargets().All(x => !x.IsActive))
            {
                var useViewBasedMonitoring = Convert.ToBoolean(_sqlRepository.ConfigurationRepository.ReadConfigurationValue(ConfigurationKeys.Section, ConfigurationKeys.UseDbccViewMonitoring) ?? "False");
                if (useViewBasedMonitoring)
                {
                    audits.Add(new ConfigurationAudit
                    {
                        FieldName = ConfigurationAuditFields.EnableViewBasedMonitoring,
                        OldValue  = "True",
                        NewValue  = "False",
                        UserId    = userId,
                        CreatedOn = now
                    });
                }

                _sqlRepository.ConfigurationRepository.SetConfigurationValue(ConfigurationKeys.Section, ConfigurationKeys.UseDbccViewMonitoring, "False");
            }

            //Track audit history
            var triggerAlert = Convert.ToBoolean(_sqlRepository.ConfigurationRepository.ReadConfigurationValue(ConfigurationKeys.Section, ConfigurationKeys.SendConfigurationChangeNotifications) ?? "False");

            _sqlRepository.AuditConfigurationChanges(audits, triggerAlert);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Indicates whether the target server-database pair is valid by attempting to connect as eddsdbo
        /// </summary>
        /// <param name="server"></param>
        /// <param name="database"></param>
        /// <returns></returns>
        public ValidationResult ValidateTarget(DbccTargetInfo target)
        {
            var result = new ValidationResult();

            try
            {
                _sqlRepository.TestConnection(target.Database, target.Server);
            }
            catch (SqlException ex)
            {
                result.Valid   = false;
                result.Details =
                    $"The connection test for the specified target database {{{target.Database}}} failed. The server {{{target.Server}}} could be unreachable, the database may not exist, or eddsdbo might not have permission to access it.  Additional Details: {ex}";
                return(result);
            }

            try
            {
                _sqlRepository.DeployDbccLogView(target.Database, target.Server);
            }
            catch (Exception e)
            {
                result.Valid   = false;
                result.Details = string.Format("The eddsdbo.QoS_DBCCLog view does not exist in the target database. Additionally, an exception occurred while attempting to deploy the standard view: {0}",
                                               e.Message);
                return(result);
            }

            try
            {
                _sqlRepository.TestDbccLogView(target.Database, target.Server);
            }
            catch (Exception e)
            {
                result.Valid   = false;
                result.Details = string.Format("The eddsdbo.QoS_DBCCLog view exists, but eddsdbo has insufficient permissions to use it or the output columns are incorrect. The following exception occurred: {0}",
                                               e.Message);
                return(result);
            }

            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Save form data to the configuration table if it's valid
        /// Indicate a response on the client side
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void SaveSettings(object sender, EventArgs e)
        {
            postCount.Value = (int.Parse(postCount.Value) + 1).ToString();
            var target = new DbccTargetInfo
            {
                Id       = int.Parse(targetId.Value),
                Server   = serverName.Value.Trim(),
                Database = databaseName.Value.Trim(),
                IsActive = isActive.Checked
            };

            //Validate settings
            var result = _service.ValidateTarget(target);

            if (!result.Valid)
            {
                validationMessage.InnerText = result.Details;

                //Display warning pane for validation message
                displayWarningMessage.Visible = true;

                if (!ClientScript.IsStartupScriptRegistered("ExecuteOnWarning"))
                {
                    Page.ClientScript.RegisterStartupScript(GetType(), "ExecuteOnWarning", "ExecuteOnWarning();", true);
                }
                return;
            }

            //Passed validation - save settings as this user
            var userId = _authService.GetUserId();

            _service.SaveTarget(target, userId);

            //Settings saved - display success pane
            displaySuccessMessage.Visible = true;
            successMessage.InnerText      = String.Format("Target details for {0} have been saved.", target.Server);
            if (!ClientScript.IsStartupScriptRegistered("ExecuteOnSuccess"))
            {
                Page.ClientScript.RegisterStartupScript(GetType(), "ExecuteOnSuccess", "ExecuteOnSuccess();", true);
            }
            RefreshTargetList();
        }
        public List <DbccTargetInfo> ListDbccTargets()
        {
            var targets = new List <DbccTargetInfo>();

            using (var conn = this.connectionFactory.GetEddsPerformanceConnection())
            {
                using (var reader = conn.ExecuteReader(Resources.ListDbccTargets))
                {
                    while (reader.Read())
                    {
                        var info = new DbccTargetInfo();
                        info.Id       = reader.GetInt32(0);
                        info.Server   = reader.GetString(1).ToUpper();
                        info.Database = reader.GetString(2);
                        info.IsActive = reader.GetBoolean(3);
                        targets.Add(info);
                    }
                }
            }
            return(targets);
        }