Ejemplo n.º 1
0
        internal async Task <Tuple <bool, string> > ConfigureAgentAlert(
            string ownerUri,
            AgentAlertInfo alert,
            ConfigAction configAction,
            RunType runType)
        {
            return(await Task <Tuple <bool, string> > .Run(() =>
            {
                try
                {
                    ConnectionInfo connInfo;
                    ConnectionServiceInstance.TryFindConnection(ownerUri, out connInfo);
                    CDataContainer dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true);
                    STParameters param = new STParameters(dataContainer.Document);
                    param.SetParam("alert", alert.JobName);

                    if (alert != null && !string.IsNullOrWhiteSpace(alert.JobName))
                    {
                        using (AgentAlertActions agentAlert = new AgentAlertActions(dataContainer, alert, configAction))
                        {
                            var executionHandler = new ExecutonHandler(agentAlert);
                            executionHandler.RunNow(runType, this);
                        }
                    }

                    return new Tuple <bool, string>(true, string.Empty);
                }
                catch (Exception ex)
                {
                    return new Tuple <bool, string>(false, ex.ToString());
                }
            }));
        }
Ejemplo n.º 2
0
        internal static AgentAlertInfo[] ConvertToAgentAlertInfo(List <Alert> alerts)
        {
            var result = new List <AgentAlertInfo>();

            foreach (Alert alert in alerts)
            {
                AgentAlertInfo alertInfo = new AgentAlertInfo();
                alertInfo.Id   = alert.ID;
                alertInfo.Name = alert.Name;
                alertInfo.DelayBetweenResponses   = alert.DelayBetweenResponses;
                alertInfo.EventDescriptionKeyword = alert.EventDescriptionKeyword;
                alertInfo.EventSource             = alert.EventSource;
                alertInfo.HasNotification         = alert.HasNotification;
                alertInfo.IncludeEventDescription = (Contracts.NotifyMethods)alert.IncludeEventDescription;
                alertInfo.IsEnabled            = alert.IsEnabled;
                alertInfo.JobId                = alert.JobID.ToString();
                alertInfo.JobName              = alert.JobName;
                alertInfo.LastOccurrenceDate   = alert.LastOccurrenceDate.ToString();
                alertInfo.LastResponseDate     = alert.LastResponseDate.ToString();
                alertInfo.MessageId            = alert.MessageID;
                alertInfo.NotificationMessage  = alert.NotificationMessage;
                alertInfo.OccurrenceCount      = alert.OccurrenceCount;
                alertInfo.PerformanceCondition = alert.PerformanceCondition;
                alertInfo.Severity             = alert.Severity;
                alertInfo.DatabaseName         = alert.DatabaseName;
                alertInfo.CountResetDate       = alert.CountResetDate.ToString();
                alertInfo.CategoryName         = alert.CategoryName;
                alertInfo.AlertType            = (Contracts.AlertType)alert.AlertType;
                alertInfo.WmiEventNamespace    = alert.WmiEventNamespace;
                alertInfo.WmiEventQuery        = alert.WmiEventQuery;
                result.Add(alertInfo);
            }
            return(result.ToArray());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Handle request to delete an alert
        /// </summary>
        internal async Task HandleDeleteAgentAlertRequest(DeleteAgentAlertParams parameters, RequestContext <DeleteAgentAlertResult> requestContext)
        {
            await Task.Run(async() =>
            {
                var result = new DeleteAgentAlertResult();
                ConnectionInfo connInfo;
                ConnectionServiceInstance.TryFindConnection(
                    parameters.OwnerUri,
                    out connInfo);

                AgentAlertInfo alert = parameters.Alert;
                if (connInfo != null && ValidateAgentAlertInfo(alert))
                {
                    CDataContainer dataContainer = AdminService.CreateDataContainer(connInfo, databaseExists: true);
                    STParameters param           = new STParameters(dataContainer.Document);
                    param.SetParam("alert", alert.JobName);

                    using (AgentAlert agentAlert = new AgentAlert(dataContainer, alert))
                    {
                        agentAlert.Drop();
                    }
                }

                await requestContext.SendResult(result);
            });
        }
Ejemplo n.º 4
0
        internal async Task <Tuple <bool, string> > ConfigureAgentAlert(
            string ownerUri,
            string alertName,
            AgentAlertInfo alert,
            ConfigAction configAction,
            RunType runType)
        {
            return(await Task <Tuple <bool, string> > .Run(() =>
            {
                try
                {
                    ConnectionInfo connInfo;
                    ConnectionServiceInstance.TryFindConnection(ownerUri, out connInfo);
                    CDataContainer dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true);
                    STParameters param = new STParameters(dataContainer.Document);
                    param.SetParam("alert", alertName);

                    if (alert != null)
                    {
                        using (AgentAlertActions actions = new AgentAlertActions(dataContainer, alertName, alert, configAction))
                        {
                            ExecuteAction(actions, runType);
                        }
                    }

                    return new Tuple <bool, string>(true, string.Empty);
                }
                catch (Exception ex)
                {
                    return new Tuple <bool, string>(false, ex.ToString());
                }
            }));
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Default constructor that will be used to create dialog
 /// </summary>
 /// <param name="dataContainer"></param>
 public AgentAlertActions(
     CDataContainer dataContainer, string originalAlertName,
     AgentAlertInfo alertInfo, ConfigAction configAction)
 {
     this.originalAlertName = originalAlertName;
     this.alertInfo         = alertInfo;
     this.DataContainer     = dataContainer;
     this.configAction      = configAction;
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Handle request to get the alerts list
        /// </summary>
        internal async Task HandleAgentAlertsRequest(AgentAlertsParams parameters, RequestContext <AgentAlertsResult> requestContext)
        {
            await Task.Run(async() =>
            {
                var result = new AgentAlertsResult();
                try
                {
                    ConnectionInfo connInfo;
                    ConnectionServiceInstance.TryFindConnection(parameters.OwnerUri, out connInfo);
                    CDataContainer dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true);

                    int alertsCount = dataContainer.Server.JobServer.Alerts.Count;
                    var alerts      = new AgentAlertInfo[alertsCount];
                    for (int i = 0; i < alertsCount; ++i)
                    {
                        var alert = dataContainer.Server.JobServer.Alerts[i];
                        alerts[i] = new AgentAlertInfo
                        {
                            Id   = alert.ID,
                            Name = alert.Name,
                            DelayBetweenResponses   = alert.DelayBetweenResponses,
                            EventDescriptionKeyword = alert.EventDescriptionKeyword,
                            EventSource             = alert.EventSource,
                            HasNotification         = alert.HasNotification,
                            IncludeEventDescription = (Contracts.NotifyMethods)alert.IncludeEventDescription,
                            IsEnabled            = alert.IsEnabled,
                            JobId                = alert.JobID.ToString(),
                            JobName              = alert.JobName,
                            LastOccurrenceDate   = alert.LastOccurrenceDate.ToString(),
                            LastResponseDate     = alert.LastResponseDate.ToString(),
                            MessageId            = alert.MessageID,
                            NotificationMessage  = alert.NotificationMessage,
                            OccurrenceCount      = alert.OccurrenceCount,
                            PerformanceCondition = alert.PerformanceCondition,
                            Severity             = alert.Severity,
                            DatabaseName         = alert.DatabaseName,
                            CountResetDate       = alert.CountResetDate.ToString(),
                            CategoryName         = alert.CategoryName,
                            AlertType            = (Contracts.AlertType)alert.AlertType,
                            WmiEventNamespace    = alert.WmiEventNamespace,
                            WmiEventQuery        = alert.WmiEventQuery
                        };
                    }

                    result.Alerts  = alerts;
                    result.Success = true;
                }
                catch (Exception ex)
                {
                    result.Success      = false;
                    result.ErrorMessage = ex.ToString();
                }
                await requestContext.SendResult(result);
            });
        }
Ejemplo n.º 7
0
        private void CreateOrUpdateAgentAlert(ConnectionInfo connInfo, AgentAlertInfo alert)
        {
            if (connInfo != null && ValidateAgentAlertInfo(alert))
            {
                CDataContainer dataContainer = AdminService.CreateDataContainer(connInfo, databaseExists: true);
                STParameters   param         = new STParameters(dataContainer.Document);
                param.SetParam("alert", alert.JobName);

                using (AgentAlert agentAlert = new AgentAlert(dataContainer, alert))
                {
                    agentAlert.CreateOrUpdate();
                }
            }
        }
 /// <summary>
 /// Default constructor that will be used to create dialog
 /// </summary>
 /// <param name="dataContainer"></param>
 public AgentAlertActions(
     CDataContainer dataContainer, string originalAlertName,
     AgentAlertInfo alertInfo, ConfigAction configAction,
     JobData jobData = null)
 {
     this.originalAlertName = originalAlertName;
     this.alertInfo         = alertInfo;
     this.DataContainer     = dataContainer;
     this.configAction      = configAction;
     if (jobData != null)
     {
         this.jobData = jobData;
     }
 }
Ejemplo n.º 9
0
        public async Task TestHandleUpdateAgentAlertsRequest()
        {
            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
            {
                // setup
                var createContext = new Mock <RequestContext <CreateAgentAlertResult> >();
                var updateContext = new Mock <RequestContext <UpdateAgentAlertResult> >();
                var deleteContext = new Mock <RequestContext <ResultStatus> >();

                var service = new AgentService();
                var alert   = new AgentAlertInfo()
                {
                    JobName   = "test_update_job",
                    AlertType = AlertType.SqlServerEvent,
                    Severity  = 1
                };

                var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);

                await service.HandleDeleteAgentAlertRequest(new DeleteAgentAlertParams()
                {
                    OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
                    Alert    = alert
                }, deleteContext.Object);

                await service.HandleCreateAgentAlertRequest(new CreateAgentAlertParams
                {
                    OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
                    Alert    = alert
                }, createContext.Object);

                // test
                alert.Severity = 2;
                await service.HandleUpdateAgentAlertRequest(new UpdateAgentAlertParams()
                {
                    OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
                    Alert    = alert
                }, updateContext.Object);

                updateContext.VerifyAll();

                // cleanup
                await service.HandleDeleteAgentAlertRequest(new DeleteAgentAlertParams()
                {
                    OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
                    Alert    = alert
                }, deleteContext.Object);
            }
        }
Ejemplo n.º 10
0
        internal async Task <Tuple <bool, string> > ConfigureAgentAlert(
            string ownerUri,
            string alertName,
            AgentAlertInfo alert,
            ConfigAction configAction,
            RunType runType)
        {
            return(await Task <Tuple <bool, string> > .Run(() =>
            {
                try
                {
                    CDataContainer dataContainer;
                    JobData jobData = null;
                    // If the alert is being created outside of a job
                    if (string.IsNullOrWhiteSpace(alert.JobName))
                    {
                        ConnectionInfo connInfo;
                        ConnectionServiceInstance.TryFindConnection(ownerUri, out connInfo);
                        dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true);
                    }
                    else
                    {
                        // If the alert is being created inside a job
                        CreateJobData(ownerUri, alert.JobName, out dataContainer, out jobData);
                    }
                    STParameters param = new STParameters(dataContainer.Document);
                    param.SetParam("alert", alertName);
                    if (alert != null)
                    {
                        using (AgentAlertActions actions = new AgentAlertActions(dataContainer, alertName, alert, configAction, jobData))
                        {
                            ExecuteAction(actions, runType);
                        }
                    }

                    return new Tuple <bool, string>(true, string.Empty);
                }
                catch (Exception ex)
                {
                    return new Tuple <bool, string>(false, ex.ToString());
                }
            }));
        }
Ejemplo n.º 11
0
 private bool ValidateAgentAlertInfo(AgentAlertInfo alert)
 {
     return(alert != null &&
            !string.IsNullOrWhiteSpace(alert.JobName));
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Default constructor that will be used to create dialog
 /// </summary>
 /// <param name="dataContainer"></param>
 public AgentAlert(CDataContainer dataContainer, AgentAlertInfo alertInfo)
 {
     this.alertInfo     = alertInfo;
     this.DataContainer = dataContainer;
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Default constructor that will be used to create dialog
 /// </summary>
 /// <param name="dataContainer"></param>
 public AgentAlertActions(CDataContainer dataContainer, AgentAlertInfo alertInfo, ConfigAction configAction)
 {
     this.alertInfo     = alertInfo;
     this.DataContainer = dataContainer;
     this.configAction  = configAction;
 }