Skip to content

Commit 4706885

Browse files
committed
v3.236.14:
- Fixed GetResourceGroupByFullPathAsync to handle full paths containing parentheses by falling back to tree node search - Removed EscapeParens() from GetResourceGroupByFullPathAsync which caused double-encoding via HttpUtility.UrlEncode
1 parent 0ff9278 commit 4706885

3 files changed

Lines changed: 43 additions & 16 deletions

File tree

LogicMonitor.Api.Test/Resources/ResourceGroupTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ namespace LogicMonitor.Api.Test.Resources;
44

55
public class ResourceGroupTests(ITestOutputHelper iTestOutputHelper, Fixture fixture) : TestWithOutput(iTestOutputHelper, fixture), IClassFixture<Fixture>
66
{
7+
//[Fact]
8+
//public async Task GetResourceGroupByDisplayNameContainsParenthesisAsync()
9+
//{
10+
// var x = await LogicMonitorClient.GetResourceGroupByFullPathAsync("DSW - (Test) Denise Home Network", CancellationToken);
11+
// x.Should().NotBeNull();
12+
//}
13+
714
[Fact]
815
public async Task GetResourceGroupByFullPath()
916
{

LogicMonitor.Api/LogicMonitor.Api.csproj

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@
2424
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
2525
<!-- Update the following before releasing to nuget -->
2626
<PackageReleaseNotes>
27-
v3.236.10:
28-
- fix: handle parentheses in GetResourceByDisplayNameAsync
29-
The LM API Eq filter no longer accepts parentheses in values.
30-
Fall back to tree node search (POST /functions) when the display
31-
name contains '(' or ')' and match client-side with SingleOrDefault.
27+
v3.236.14:
28+
- Fixed GetResourceGroupByFullPathAsync to handle full paths containing parentheses by falling back to tree node search
29+
- Removed EscapeParens() from GetResourceGroupByFullPathAsync which caused double-encoding via HttpUtility.UrlEncode
3230
</PackageReleaseNotes>
3331
<UserSecretsId>57aaa0e7-815d-4065-9339-f3f070bed01e</UserSecretsId>
3432
<PackageId>LogicMonitor.Api</PackageId>

LogicMonitor.Api/LogicMonitorClient_Resources.cs

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -408,19 +408,41 @@ public async Task<List<Resource>> GetResourcesByNameAsync(
408408
return await GetAsync<ResourceGroup>(1, cancellationToken).ConfigureAwait(false);
409409
}
410410

411-
// This may actually return more than one, as LogicMonitor does not correctly handle brackets in some cases.
412-
var allResourceGroups = await GetAllAsync(new Filter<ResourceGroup>
411+
// The LM API Eq filter cannot handle parentheses in values - fall back to tree node search
412+
if (resourceGroupFullPath.Contains('(') || resourceGroupFullPath.Contains(')'))
413413
{
414-
FilterItems =
415-
[
416-
new Eq<ResourceGroup>(nameof(ResourceGroup.FullPath), resourceGroupFullPath.EscapePlusCharacter().EscapeParens())
417-
]
418-
},
419-
cancellationToken: cancellationToken)
420-
.ConfigureAwait(false);
414+
// Search by leaf group name, then match by full path client-side
415+
var leafName = resourceGroupFullPath.Split('/')[^1];
416+
var searchResults = await TreeNodeFreeSearchAsync(
417+
leafName,
418+
100,
419+
cancellationToken,
420+
TreeNodeFreeSearchResultType.ResourceGroup)
421+
.ConfigureAwait(false);
422+
423+
foreach (var result in searchResults)
424+
{
425+
var group = await GetAsync<ResourceGroup>(result.EntityId, cancellationToken).ConfigureAwait(false);
426+
if (group.FullPath == resourceGroupFullPath)
427+
{
428+
return group;
429+
}
430+
}
431+
432+
return null;
433+
}
434+
435+
// This may actually return more than one, as LogicMonitor does not correctly handle brackets in some cases.
436+
var allResourceGroups =
437+
await GetAllAsync(new Filter<ResourceGroup>{
438+
FilterItems =
439+
[
440+
new Eq<ResourceGroup>(nameof(ResourceGroup.FullPath), resourceGroupFullPath.EscapePlusCharacter())
441+
]},
442+
cancellationToken: cancellationToken)
443+
.ConfigureAwait(false);
421444

422-
return allResourceGroups
423-
.SingleOrDefault(dg => dg.FullPath == resourceGroupFullPath);
445+
return allResourceGroups.SingleOrDefault(dg => dg.FullPath == resourceGroupFullPath);
424446
}
425447

426448
/// <summary>

0 commit comments

Comments
 (0)