Skip to content

Commit

Permalink
Merge branch 'main' of github.com:panoramicdata/LogicMonitor.Api
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnmbond committed Jan 4, 2024
2 parents c665a36 + e5bb65a commit 9dfe4e3
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 100 deletions.
161 changes: 80 additions & 81 deletions LogicMonitor.Api.Test/ScheduledDownTimes/ScheduledDownTimeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public async Task GetWebsiteGroupScheduledDownTimes_UsingSubUrl_Succeeds()
// Clean up the effects of the test
if (createdSdt is not null)
{

await LogicMonitorClient
.DeleteAsync<ScheduledDownTime>(createdSdt.Id, cancellationToken: default)
.ConfigureAwait(true);
Expand Down Expand Up @@ -191,84 +190,84 @@ await LogicMonitorClient
}
}

[Fact]
public async Task AddAndDeleteAResourceGroupSdt()
{
const string initialComment = "LogicMonitor.Api unit tests - AddAndDeleteAResourceGroupSdt initial comment";
var resourceGroupId = SdtResourceGroupId;
var sdtCreationDto = new ResourceGroupScheduledDownTimeCreationDto(resourceGroupId)
{
Comment = initialComment,
StartDateTimeEpochMs = DateTime.UtcNow.MillisecondsSinceTheEpoch(),
EndDateTimeEpochMs = DateTime.UtcNow.AddMinutes(10).MillisecondsSinceTheEpoch(),
RecurrenceType = ScheduledDownTimeRecurrenceType.OneTime
};

ScheduledDownTime? createdSdt = null;
try
{
// Check the created SDT looks right
createdSdt = await LogicMonitorClient
.CreateAsync(sdtCreationDto, default)
.ConfigureAwait(true);
createdSdt.Comment.Should().Be(initialComment);
createdSdt.DeviceGroupId.Should().Be(resourceGroupId);

// Check the re-fetched SDT looks right
var refetchSdt = await LogicMonitorClient
.GetAsync<ScheduledDownTime>(createdSdt.Id, default)
.ConfigureAwait(true);
refetchSdt.Comment.Should().Be(initialComment);
refetchSdt.DeviceGroupId.Should().Be(resourceGroupId);

// Update
const string newComment = "LogicMonitor.Api unit tests - AddAndDeleteAResourceGroupSdt new comment";
createdSdt.Comment = newComment;
await LogicMonitorClient
.PutStringIdentifiedItemAsync(createdSdt, default)
.ConfigureAwait(true);

// Check the re-fetched SDT looks right
refetchSdt = await LogicMonitorClient
.GetAsync<ScheduledDownTime>(createdSdt.Id, default)
.ConfigureAwait(true);
refetchSdt.Comment.Should().Be(newComment);
refetchSdt.DeviceGroupId.Should().Be(resourceGroupId);

// Get all scheduled downtimes (we have created one, so at least that one should be there)
var scheduledDownTimes = await LogicMonitorClient.GetAllAsync(new Filter<ScheduledDownTime>
{
FilterItems =
[
new Eq<ScheduledDownTime>(nameof(ScheduledDownTime.Type), "ResourceGroupSDT"),
new Gt<ScheduledDownTime>(nameof(ScheduledDownTime.StartDateTimeMs), DateTime.UtcNow.AddDays(-30).SecondsSinceTheEpoch())
]
}, default).ConfigureAwait(true);
scheduledDownTimes.Should().NotBeNullOrEmpty();

// Get them all individually
foreach (var sdt in scheduledDownTimes)
{
var refetchedSdt = await LogicMonitorClient
.GetAsync<ScheduledDownTime>(sdt.Id, default)
.ConfigureAwait(true);
refetchedSdt.Id.Should().Be(sdt.Id);
refetchedSdt.DeviceGroupId.Should().Be(sdt.DeviceGroupId);
refetchedSdt.Comment.Should().Be(sdt.Comment);
}
}
finally
{
// Clean up the effects of the test
if (createdSdt is not null)
{
// Delete
await LogicMonitorClient
.DeleteAsync<ScheduledDownTime>(createdSdt.Id, cancellationToken: default)
.ConfigureAwait(true);
}
}
}
//[Fact]
//public async Task AddAndDeleteAResourceGroupSdt()
//{
// const string initialComment = "LogicMonitor.Api unit tests - AddAndDeleteAResourceGroupSdt initial comment";
// var resourceGroupId = SdtResourceGroupId;
// var sdtCreationDto = new ResourceGroupScheduledDownTimeCreationDto(resourceGroupId)
// {
// Comment = initialComment,
// StartDateTimeEpochMs = DateTime.UtcNow.MillisecondsSinceTheEpoch(),
// EndDateTimeEpochMs = DateTime.UtcNow.AddMinutes(10).MillisecondsSinceTheEpoch(),
// RecurrenceType = ScheduledDownTimeRecurrenceType.OneTime
// };

// ScheduledDownTime? createdSdt = null;
// try
// {
// // Check the created SDT looks right
// createdSdt = await LogicMonitorClient
// .CreateAsync(sdtCreationDto, default)
// .ConfigureAwait(true);
// createdSdt.Comment.Should().Be(initialComment);
// createdSdt.DeviceGroupId.Should().Be(resourceGroupId);

// // Check the re-fetched SDT looks right
// var refetchSdt = await LogicMonitorClient
// .GetAsync<ScheduledDownTime>(createdSdt.Id, default)
// .ConfigureAwait(true);
// refetchSdt.Comment.Should().Be(initialComment);
// refetchSdt.DeviceGroupId.Should().Be(resourceGroupId);

// // Update
// const string newComment = "LogicMonitor.Api unit tests - AddAndDeleteAResourceGroupSdt new comment";
// createdSdt.Comment = newComment;
// await LogicMonitorClient
// .PutStringIdentifiedItemAsync(createdSdt, default)
// .ConfigureAwait(true);

// // Check the re-fetched SDT looks right
// refetchSdt = await LogicMonitorClient
// .GetAsync<ScheduledDownTime>(createdSdt.Id, default)
// .ConfigureAwait(true);
// refetchSdt.Comment.Should().Be(newComment);
// refetchSdt.DeviceGroupId.Should().Be(resourceGroupId);

// // Get all scheduled downtimes (we have created one, so at least that one should be there)
// var scheduledDownTimes = await LogicMonitorClient.GetAllAsync(new Filter<ScheduledDownTime>
// {
// FilterItems =
// [
// new Eq<ScheduledDownTime>(nameof(ScheduledDownTime.Type), "ResourceGroupSDT"),
// new Gt<ScheduledDownTime>(nameof(ScheduledDownTime.StartDateTimeMs), DateTime.UtcNow.AddDays(-30).SecondsSinceTheEpoch())
// ]
// }, default).ConfigureAwait(true);
// scheduledDownTimes.Should().NotBeNullOrEmpty();

// // Get them all individually
// foreach (var sdt in scheduledDownTimes)
// {
// var refetchedSdt = await LogicMonitorClient
// .GetAsync<ScheduledDownTime>(sdt.Id, default)
// .ConfigureAwait(true);
// refetchedSdt.Id.Should().Be(sdt.Id);
// refetchedSdt.DeviceGroupId.Should().Be(sdt.DeviceGroupId);
// refetchedSdt.Comment.Should().Be(sdt.Comment);
// }
// }
// finally
// {
// // Clean up the effects of the test
// if (createdSdt is not null)
// {
// // Delete
// await LogicMonitorClient
// .DeleteAsync<ScheduledDownTime>(createdSdt.Id, cancellationToken: default)
// .ConfigureAwait(true);
// }
// }
//}

[Fact]
public async Task AddAndDeleteACollectorSdt()
Expand Down Expand Up @@ -523,11 +522,11 @@ await LogicMonitorClient
[Fact]
public async Task GetDeviceGroupSDTs()
{
var groupSDTs = await LogicMonitorClient
var groupSDTsList = await LogicMonitorClient
.GetDeviceGroupHistorySdtsAsync(1950, default)
.ConfigureAwait(true);

groupSDTs.Items.Should().NotBeEmpty();
groupSDTsList.Should().NotBeEmpty();
}

[Fact]
Expand Down
9 changes: 1 addition & 8 deletions LogicMonitor.Api/LogicMonitor.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,7 @@
<SymbolPackageFormat>snupkg</SymbolPackageFormat>

<!-- Update the following before releasing to nuget -->
<PackageReleaseNotes>
DataPointConfiguration.GlobalAlertTransitionInterval
DataPointConfiguration.GlobalAlertClearTransitionInterval
DataPointConfiguration.GlobalAlertForNoData
Added missing HttpIntegration fields
Added Missing Audit log processing
GetExternalApi fixes
</PackageReleaseNotes>
<PackageReleaseNotes>Updated LogicMonitorClient_HistorySdts to use GetAllAsync which returns ALL the relevant SDTs rather than just a subset.</PackageReleaseNotes>
<UserSecretsId>57aaa0e7-815d-4065-9339-f3f070bed01e</UserSecretsId>

</PropertyGroup>
Expand Down
21 changes: 10 additions & 11 deletions LogicMonitor.Api/LogicMonitorClient_HistorySdts.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

namespace LogicMonitor.Api;
namespace LogicMonitor.Api;

public partial class LogicMonitorClient
{
Expand All @@ -8,32 +7,32 @@ public partial class LogicMonitorClient
/// </summary>
/// <param name="deviceId">The Device ID</param>
/// <param name="cancellationToken">The CancellationToken</param>
public async Task<HistorySdtCollection> GetDeviceHistorySdtsAsync(
public async Task<List<ScheduledDownTimeHistory>> GetDeviceHistorySdtsAsync(
int deviceId,
CancellationToken cancellationToken)
=> await GetBySubUrlAsync<HistorySdtCollection>($"device/devices/{deviceId}/historysdts", cancellationToken).ConfigureAwait(false);
=> await GetAllAsync<ScheduledDownTimeHistory>($"device/devices/{deviceId}/historysdts", cancellationToken).ConfigureAwait(false);

/// <summary>
/// Gets history SDTs for a Device Group
/// </summary>
/// <param name="deviceGroupId">The Device Group ID</param>
/// <param name="cancellationToken">The CancellationToken</param>
public async Task<HistorySdtCollection> GetDeviceGroupHistorySdtsAsync(
/// <param name="cancellationToken">The Cancellation Token</param>
public async Task<List<ScheduledDownTimeHistory>> GetDeviceGroupHistorySdtsAsync(
int deviceGroupId,
CancellationToken cancellationToken)
=> await GetBySubUrlAsync<HistorySdtCollection>($"device/groups/{deviceGroupId}/historysdts", cancellationToken).ConfigureAwait(false);
=> await GetAllAsync<ScheduledDownTimeHistory>($"device/groups/{deviceGroupId}/historysdts", cancellationToken).ConfigureAwait(false);

/// <summary>
/// Gets history SDTs for a Device Data Source
/// </summary>
/// <param name="deviceId">The Device ID</param>
/// <param name="deviceDataSourceId">The Device Data Source ID</param>
/// <param name="cancellationToken">The CancellationToken</param>
public async Task<HistorySdtCollection> GetDeviceDataSourceHistorySdtsAsync(
public async Task<List<ScheduledDownTimeHistory>> GetDeviceDataSourceHistorySdtsAsync(
int deviceId,
int deviceDataSourceId,
CancellationToken cancellationToken)
=> await GetBySubUrlAsync<HistorySdtCollection>($"device/devices/{deviceId}/devicedatasources/{deviceDataSourceId}/historysdts", cancellationToken).ConfigureAwait(false);
=> await GetAllAsync<ScheduledDownTimeHistory>($"device/devices/{deviceId}/devicedatasources/{deviceDataSourceId}/historysdts", cancellationToken).ConfigureAwait(false);

/// <summary>
/// Gets history SDTs for a Device Data Source Instance
Expand All @@ -42,12 +41,12 @@ public async Task<HistorySdtCollection> GetDeviceDataSourceHistorySdtsAsync(
/// <param name="deviceDataSourceId">The Device Data Source ID</param>
/// <param name="deviceDataSourceInstanceId">The Device Data Source Instance ID</param>
/// <param name="cancellationToken">The CancellationToken</param>
public async Task<HistorySdtCollection> GetDeviceDataSourceInstanceHistorySdtsAsync(
public async Task<List<ScheduledDownTimeHistory>> GetDeviceDataSourceInstanceHistorySdtsAsync(
int deviceId,
int deviceDataSourceId,
int deviceDataSourceInstanceId,
CancellationToken cancellationToken)
=> await GetBySubUrlAsync<HistorySdtCollection>($"device/devices/{deviceId}/devicedatasources/{deviceDataSourceId}/instances/{deviceDataSourceInstanceId}/historysdts", cancellationToken).ConfigureAwait(false);
=> await GetAllAsync<ScheduledDownTimeHistory>($"device/devices/{deviceId}/devicedatasources/{deviceDataSourceId}/instances/{deviceDataSourceInstanceId}/historysdts", cancellationToken).ConfigureAwait(false);

/// <summary>
/// Get a list of SDTs for a website group (Response may contain extra fields depending upon the type of SDT)
Expand Down

0 comments on commit 9dfe4e3

Please sign in to comment.