mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
Add Get Alerts and Get Operators handlers (#648)
* Stage changes * stage changes 2 * WIP 3 * Add Get Alerts and Get Operators handlers * Add Get Proxy request handler
This commit is contained in:
@@ -410,17 +410,52 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
var result = new AgentAlertsResult();
|
||||
result.Alerts = new List<AgentAlertInfo>().ToArray();
|
||||
|
||||
ConnectionInfo connInfo;
|
||||
ConnectionServiceInstance.TryFindConnection(parameters.OwnerUri, out connInfo);
|
||||
|
||||
if (connInfo != null)
|
||||
try
|
||||
{
|
||||
ConnectionInfo connInfo;
|
||||
ConnectionServiceInstance.TryFindConnection(parameters.OwnerUri, out connInfo);
|
||||
CDataContainer dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true);
|
||||
AlertCollection alerts = dataContainer.Server.JobServer.Alerts;
|
||||
}
|
||||
|
||||
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,
|
||||
DelayBetweenResponses = alert.DelayBetweenResponses,
|
||||
EventDescriptionKeyword = alert.EventDescriptionKeyword,
|
||||
EventSource = alert.EventSource,
|
||||
HasNotification = alert.HasNotification,
|
||||
IncludeEventDescription = (Contracts.NotifyMethods)alert.IncludeEventDescription,
|
||||
IsEnabled = alert.IsEnabled,
|
||||
JobId = alert.JobID != null ? alert.JobID.ToString() : null,
|
||||
JobName = alert.JobName,
|
||||
LastOccurrenceDate = alert.LastOccurrenceDate != null ? alert.LastOccurrenceDate.ToString() : null,
|
||||
LastResponseDate = alert.LastResponseDate != null ? alert.LastResponseDate.ToString() : null,
|
||||
MessageId = alert.MessageID,
|
||||
NotificationMessage = alert.NotificationMessage,
|
||||
OccurrenceCount = alert.OccurrenceCount,
|
||||
PerformanceCondition = alert.PerformanceCondition,
|
||||
Severity = alert.Severity,
|
||||
DatabaseName = alert.DatabaseName,
|
||||
CountResetDate = alert.CountResetDate != null ? alert.CountResetDate.ToString() : null,
|
||||
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);
|
||||
});
|
||||
}
|
||||
@@ -485,8 +520,53 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
|
||||
internal async Task HandleAgentOperatorsRequest(AgentOperatorsParams parameters, RequestContext<AgentOperatorsResult> requestContext)
|
||||
{
|
||||
await requestContext.SendResult(null);
|
||||
}
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
var result = new AgentOperatorsResult();
|
||||
try
|
||||
{
|
||||
ConnectionInfo connInfo;
|
||||
ConnectionServiceInstance.TryFindConnection(parameters.OwnerUri, out connInfo);
|
||||
CDataContainer dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true);
|
||||
|
||||
int operatorCount = dataContainer.Server.JobServer.Operators.Count;
|
||||
var operators = new AgentOperatorInfo[operatorCount];
|
||||
for (int i = 0; i < operatorCount; ++i)
|
||||
{
|
||||
var item = dataContainer.Server.JobServer.Operators[i];
|
||||
operators[i] = new AgentOperatorInfo
|
||||
{
|
||||
Name = item.Name,
|
||||
Id = item.ID,
|
||||
EmailAddress = item.EmailAddress,
|
||||
Enabled = item.Enabled,
|
||||
LastEmailDate = item.LastEmailDate.ToString(),
|
||||
LastNetSendDate = item.LastNetSendDate.ToString(),
|
||||
LastPagerDate = item.LastPagerDate.ToString(),
|
||||
PagerAddress = item.PagerAddress,
|
||||
CategoryName = item.CategoryName,
|
||||
PagerDays = (Contracts.WeekDays)item.PagerDays,
|
||||
SaturdayPagerEndTime = item.SaturdayPagerEndTime.ToString(),
|
||||
SaturdayPagerStartTime = item.SaturdayPagerEndTime.ToString(),
|
||||
SundayPagerEndTime = item.SundayPagerEndTime.ToString(),
|
||||
SundayPagerStartTime = item.SundayPagerStartTime.ToString(),
|
||||
NetSendAddress = item.NetSendAddress,
|
||||
WeekdayPagerStartTime = item.WeekdayPagerStartTime.ToString(),
|
||||
WeekdayPagerEndTime = item.WeekdayPagerEndTime.ToString()
|
||||
};
|
||||
}
|
||||
|
||||
result.Operators = operators;
|
||||
result.Success = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result.Success = false;
|
||||
result.ErrorMessage = ex.ToString();
|
||||
}
|
||||
await requestContext.SendResult(result);
|
||||
});
|
||||
}
|
||||
|
||||
internal async Task HandleCreateAgentOperatorRequest(
|
||||
CreateAgentOperatorParams parameters,
|
||||
@@ -548,7 +628,42 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
|
||||
internal async Task HandleAgentProxiesRequest(AgentProxiesParams parameters, RequestContext<AgentProxiesResult> requestContext)
|
||||
{
|
||||
await requestContext.SendResult(null);
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
var result = new AgentProxiesResult();
|
||||
try
|
||||
{
|
||||
ConnectionInfo connInfo;
|
||||
ConnectionServiceInstance.TryFindConnection(parameters.OwnerUri, out connInfo);
|
||||
CDataContainer dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true);
|
||||
|
||||
int proxyCount = dataContainer.Server.JobServer.ProxyAccounts.Count;
|
||||
var proxies = new AgentProxyInfo[proxyCount];
|
||||
for (int i = 0; i < proxyCount; ++i)
|
||||
{
|
||||
var proxy = dataContainer.Server.JobServer.ProxyAccounts[i];
|
||||
proxies[i] = new AgentProxyInfo
|
||||
{
|
||||
Id = proxy.ID,
|
||||
AccountName = proxy.Name,
|
||||
Description = proxy.Description,
|
||||
CredentialName = proxy.CredentialName,
|
||||
CredentialIdentity = proxy.CredentialIdentity,
|
||||
CredentialId = proxy.CredentialID,
|
||||
IsEnabled = proxy.IsEnabled,
|
||||
};
|
||||
}
|
||||
result.Proxies = proxies;
|
||||
result.Success = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result.Success = false;
|
||||
result.ErrorMessage = ex.ToString();
|
||||
}
|
||||
|
||||
await requestContext.SendResult(result);
|
||||
});
|
||||
}
|
||||
|
||||
internal async Task HandleCreateAgentProxyRequest(CreateAgentProxyParams parameters, RequestContext<AgentProxyResult> requestContext)
|
||||
|
||||
@@ -39,17 +39,17 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent.Contracts
|
||||
public int HasNotification { get; set; }
|
||||
public NotifyMethods IncludeEventDescription { get; set; }
|
||||
public bool IsEnabled { get; set; }
|
||||
public Guid JobId { get; set; }
|
||||
public string JobId { get; set; }
|
||||
public string JobName { get; set; }
|
||||
public DateTime LastOccurrenceDate { get; set; }
|
||||
public DateTime LastResponseDate { get; set; }
|
||||
public string LastOccurrenceDate { get; set; }
|
||||
public string LastResponseDate { get; set; }
|
||||
public int MessageId { get; set; }
|
||||
public string NotificationMessage { get; set; }
|
||||
public int OccurrenceCount { get; set; }
|
||||
public string PerformanceCondition { get; set; }
|
||||
public int Severity { get; set; }
|
||||
public string DatabaseName { get; set; }
|
||||
public DateTime CountResetDate { get; set; }
|
||||
public string CountResetDate { get; set; }
|
||||
public string CategoryName { get; set; }
|
||||
public AlertType AlertType { get; set; }
|
||||
public string WmiEventNamespace { get; set; }
|
||||
|
||||
@@ -33,18 +33,18 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent.Contracts
|
||||
public int Id { get; set; }
|
||||
public string EmailAddress { get; set; }
|
||||
public bool Enabled { get; set; }
|
||||
public DateTime LastEmailDate { get; set; }
|
||||
public DateTime LastNetSendDate { get; set; }
|
||||
public DateTime LastPagerDate { get; set; }
|
||||
public string LastEmailDate { get; set; }
|
||||
public string LastNetSendDate { get; set; }
|
||||
public string LastPagerDate { get; set; }
|
||||
public string PagerAddress { get; set; }
|
||||
public string CategoryName { get; set; }
|
||||
public WeekDays PagerDays { get; set; }
|
||||
public TimeSpan SaturdayPagerEndTime { get; set; }
|
||||
public TimeSpan SaturdayPagerStartTime { get; set; }
|
||||
public TimeSpan SundayPagerEndTime { get; set; }
|
||||
public TimeSpan SundayPagerStartTime { get; set; }
|
||||
public string SaturdayPagerEndTime { get; set; }
|
||||
public string SaturdayPagerStartTime { get; set; }
|
||||
public string SundayPagerEndTime { get; set; }
|
||||
public string SundayPagerStartTime { get; set; }
|
||||
public string NetSendAddress { get; set; }
|
||||
public TimeSpan WeekdayPagerStartTime { get; set; }
|
||||
public TimeSpan WeekdayPagerEndTime { get; set; }
|
||||
public string WeekdayPagerStartTime { get; set; }
|
||||
public string WeekdayPagerEndTime { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -585,20 +585,56 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
|
||||
if ((operatorInfo.PagerDays & Contracts.WeekDays.WeekDays) > 0)
|
||||
{
|
||||
currentOperator.WeekdayPagerStartTime = operatorInfo.WeekdayPagerStartTime;
|
||||
currentOperator.WeekdayPagerEndTime = operatorInfo.WeekdayPagerEndTime;
|
||||
TimeSpan weekdayPagerStartTime = default(TimeSpan);
|
||||
if (!string.IsNullOrWhiteSpace(operatorInfo.WeekdayPagerStartTime))
|
||||
{
|
||||
weekdayPagerStartTime = TimeSpan.Parse(operatorInfo.WeekdayPagerStartTime);
|
||||
}
|
||||
|
||||
TimeSpan weekdayPagerEndTime = default(TimeSpan);
|
||||
if (!string.IsNullOrWhiteSpace(operatorInfo.WeekdayPagerEndTime))
|
||||
{
|
||||
weekdayPagerEndTime = TimeSpan.Parse(operatorInfo.WeekdayPagerEndTime);
|
||||
}
|
||||
|
||||
currentOperator.WeekdayPagerStartTime = weekdayPagerStartTime;
|
||||
currentOperator.WeekdayPagerEndTime = weekdayPagerEndTime;
|
||||
}
|
||||
|
||||
if ((operatorInfo.PagerDays & Contracts.WeekDays.Saturday) > 0)
|
||||
{
|
||||
currentOperator.SaturdayPagerStartTime = operatorInfo.SaturdayPagerStartTime;
|
||||
currentOperator.SaturdayPagerEndTime = operatorInfo.SaturdayPagerEndTime;
|
||||
TimeSpan saturdayPagerStartTime = default(TimeSpan);
|
||||
if (!string.IsNullOrWhiteSpace(operatorInfo.SaturdayPagerStartTime))
|
||||
{
|
||||
saturdayPagerStartTime = TimeSpan.Parse(operatorInfo.SaturdayPagerStartTime);
|
||||
}
|
||||
|
||||
TimeSpan saturdayPagerEndTime = default(TimeSpan);
|
||||
if (!string.IsNullOrWhiteSpace(operatorInfo.SaturdayPagerEndTime))
|
||||
{
|
||||
saturdayPagerEndTime = TimeSpan.Parse(operatorInfo.SaturdayPagerEndTime);
|
||||
}
|
||||
|
||||
currentOperator.SaturdayPagerStartTime = saturdayPagerStartTime;
|
||||
currentOperator.SaturdayPagerEndTime = saturdayPagerEndTime;
|
||||
}
|
||||
|
||||
if ((operatorInfo.PagerDays & Contracts.WeekDays.Sunday) > 0)
|
||||
{
|
||||
currentOperator.SundayPagerStartTime = operatorInfo.SundayPagerStartTime;
|
||||
currentOperator.SundayPagerEndTime = operatorInfo.SundayPagerEndTime;
|
||||
TimeSpan sundayPagerStartTime = default(TimeSpan);
|
||||
if (!string.IsNullOrWhiteSpace(operatorInfo.SundayPagerStartTime))
|
||||
{
|
||||
sundayPagerStartTime = TimeSpan.Parse(operatorInfo.SundayPagerStartTime);
|
||||
}
|
||||
|
||||
TimeSpan sundayPagerEndTime = default(TimeSpan);
|
||||
if (!string.IsNullOrWhiteSpace(operatorInfo.SundayPagerEndTime))
|
||||
{
|
||||
sundayPagerEndTime = TimeSpan.Parse(operatorInfo.SundayPagerEndTime);
|
||||
}
|
||||
|
||||
currentOperator.SundayPagerStartTime = sundayPagerStartTime;
|
||||
currentOperator.SundayPagerEndTime = sundayPagerEndTime;
|
||||
}
|
||||
|
||||
if (this.createMode)
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Agent
|
||||
/// <summary>
|
||||
/// Verify default agent/alerts handlers
|
||||
/// </summary>
|
||||
//[Fact]
|
||||
[Fact]
|
||||
public async Task TestHandleAgentAlertsRequest()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
@@ -33,11 +33,10 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Agent
|
||||
};
|
||||
|
||||
var requestContext = new Mock<RequestContext<AgentAlertsResult>>();
|
||||
|
||||
AgentService service = new AgentService();
|
||||
await service.HandleAgentAlertsRequest(requestParams, requestContext.Object);
|
||||
requestContext.VerifyAll();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -16,6 +16,28 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Agent
|
||||
{
|
||||
public class AgentOperatorTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Verify default agent/operators handlers
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task TestHandleAgentOperatorsRequest()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
{
|
||||
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
|
||||
|
||||
var requestParams = new AgentOperatorsParams()
|
||||
{
|
||||
OwnerUri = connectionResult.ConnectionInfo.OwnerUri
|
||||
};
|
||||
|
||||
var requestContext = new Mock<RequestContext<AgentOperatorsResult>>();
|
||||
AgentService service = new AgentService();
|
||||
await service.HandleAgentOperatorsRequest(requestParams, requestContext.Object);
|
||||
requestContext.VerifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify the default "create agent alert" request handler with valid parameters
|
||||
/// </summary>
|
||||
|
||||
@@ -21,6 +21,27 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Agent
|
||||
{
|
||||
public class AgentProxyTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Verify default agent/proxies handlers
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task TestHandleAgentProxiesRequest()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
{
|
||||
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
|
||||
var requestParams = new AgentProxiesParams()
|
||||
{
|
||||
OwnerUri = connectionResult.ConnectionInfo.OwnerUri
|
||||
};
|
||||
|
||||
var requestContext = new Mock<RequestContext<AgentProxiesResult>>();
|
||||
AgentService service = new AgentService();
|
||||
await service.HandleAgentProxiesRequest(requestParams, requestContext.Object);
|
||||
requestContext.VerifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// TestHandleCreateAgentProxyRequest
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user