From 9441d99489f08116c59b3d041f5094175768f872 Mon Sep 17 00:00:00 2001 From: Roland Banks Date: Mon, 25 Mar 2024 18:06:21 +0700 Subject: [PATCH 1/3] Too many request check updated not to check reason phrase, but just the HTTP status code --- LogicMonitor.Api/LogicMonitor.Api.csproj | 2 +- LogicMonitor.Api/LogicMonitorClient.cs | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/LogicMonitor.Api/LogicMonitor.Api.csproj b/LogicMonitor.Api/LogicMonitor.Api.csproj index 026cf33d..2ad6943f 100644 --- a/LogicMonitor.Api/LogicMonitor.Api.csproj +++ b/LogicMonitor.Api/LogicMonitor.Api.csproj @@ -28,7 +28,7 @@ - Fixed various broken UpdateLogicModules methods + Too many request check updated not to check reason phrase, but just the HTTP status code 57aaa0e7-815d-4065-9339-f3f070bed01e diff --git a/LogicMonitor.Api/LogicMonitorClient.cs b/LogicMonitor.Api/LogicMonitorClient.cs index b197a251..0de9c86d 100644 --- a/LogicMonitor.Api/LogicMonitorClient.cs +++ b/LogicMonitor.Api/LogicMonitorClient.cs @@ -467,7 +467,7 @@ public async Task PutAsync(string subUrl, object @item, CancellationToken cancel // Check the outer HTTP status code if (!httpResponseMessage.IsSuccessStatusCode) { - if ((int)httpResponseMessage.StatusCode != 429 && httpResponseMessage.ReasonPhrase != "Too Many Requests") + if ((int)httpResponseMessage.StatusCode != 429) { if (WaitDuringLogicMonitorUpgrades && httpResponseMessage.StatusCode == HttpStatusCode.ServiceUnavailable) { @@ -870,7 +870,7 @@ public async Task DeleteAsync(string subUrl, CancellationToken cancellationToken // Check the outer HTTP status code if (!httpResponseMessage.IsSuccessStatusCode) { - if ((int)httpResponseMessage.StatusCode != 429 && httpResponseMessage.ReasonPhrase != "Too Many Requests") + if ((int)httpResponseMessage.StatusCode != 429) { if (WaitDuringLogicMonitorUpgrades && httpResponseMessage.StatusCode == HttpStatusCode.ServiceUnavailable) { @@ -1017,7 +1017,7 @@ public async Task DeleteAsync(string subUrl, CancellationToken cancellationToken // NOT A SUCCESS :-( var statusCode = (int)httpResponseMessage.StatusCode; - var tooManyRequests = statusCode == 429 && httpResponseMessage.ReasonPhrase.Equals("Too Many Requests", StringComparison.OrdinalIgnoreCase); + var tooManyRequests = statusCode == 429; if (!tooManyRequests) { @@ -1188,11 +1188,10 @@ public async Task DeleteAsync(string subUrl, CancellationToken cancellationToken if (!httpResponseMessage.IsSuccessStatusCode) { - if ((int)httpResponseMessage.StatusCode != 429 && httpResponseMessage.ReasonPhrase != "Too Many Requests") + if ((int)httpResponseMessage.StatusCode != 429) { if (WaitDuringLogicMonitorUpgrades && httpResponseMessage.StatusCode == HttpStatusCode.ServiceUnavailable) { - // TODO: could also check the reason phrase, and / or the RESPONSE (which contains "Service Temporarily Unavailable") _logger.LogDebug("{Prefix} Service Unavailable. Waiting 10000ms", prefix); await Task.Delay(10000, cancellationToken).ConfigureAwait(false); continue; @@ -1296,7 +1295,7 @@ public async Task DeleteAsync(string subUrl, CancellationToken cancellationToken // Check the outer HTTP status code if (!httpResponseMessage.IsSuccessStatusCode) { - if ((int)httpResponseMessage.StatusCode != 429 && httpResponseMessage.ReasonPhrase != "Too Many Requests") + if ((int)httpResponseMessage.StatusCode != 429) { if (WaitDuringLogicMonitorUpgrades && httpResponseMessage.StatusCode == HttpStatusCode.ServiceUnavailable) { From c3a579cc2f920147eeabe72542e0c83284ef34c6 Mon Sep 17 00:00:00 2001 From: Roland Banks Date: Tue, 26 Mar 2024 10:22:32 +0700 Subject: [PATCH 2/3] Added missing LastAuthIp property to User. Added missing CostOptimization property to RolePrivilegeType. Added User Role test --- LogicMonitor.Api.Test/Users/RoleTests.cs | 15 +++++++++++++++ LogicMonitor.Api/LogicMonitor.Api.csproj | 2 +- LogicMonitor.Api/Users/PrivilegeObjectType.cs | 8 +++++++- LogicMonitor.Api/Users/User.cs | 6 ++++++ 4 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 LogicMonitor.Api.Test/Users/RoleTests.cs diff --git a/LogicMonitor.Api.Test/Users/RoleTests.cs b/LogicMonitor.Api.Test/Users/RoleTests.cs new file mode 100644 index 00000000..df937f90 --- /dev/null +++ b/LogicMonitor.Api.Test/Users/RoleTests.cs @@ -0,0 +1,15 @@ +namespace LogicMonitor.Api.Test.Users; + +public class RoleTests(ITestOutputHelper iTestOutputHelper) : TestWithOutput(iTestOutputHelper) +{ + [Fact] + public async Task GetAll() + { + var items = await LogicMonitorClient + .GetAllAsync(default) + .ConfigureAwait(true); + + items.Should().NotBeNull(); + items.Should().NotBeNullOrEmpty(); + } +} diff --git a/LogicMonitor.Api/LogicMonitor.Api.csproj b/LogicMonitor.Api/LogicMonitor.Api.csproj index 2ad6943f..f6e71111 100644 --- a/LogicMonitor.Api/LogicMonitor.Api.csproj +++ b/LogicMonitor.Api/LogicMonitor.Api.csproj @@ -28,7 +28,7 @@ - Too many request check updated not to check reason phrase, but just the HTTP status code + Added missing LastAuthIp property to User. Added missing CostOptimization property to RolePrivilegeType. Added User Role test 57aaa0e7-815d-4065-9339-f3f070bed01e diff --git a/LogicMonitor.Api/Users/PrivilegeObjectType.cs b/LogicMonitor.Api/Users/PrivilegeObjectType.cs index f613fd8d..c06ac077 100644 --- a/LogicMonitor.Api/Users/PrivilegeObjectType.cs +++ b/LogicMonitor.Api/Users/PrivilegeObjectType.cs @@ -107,5 +107,11 @@ public enum PrivilegeObjectType /// Module /// [DataMember(Name = "module")] - Module + Module, + + /// + /// Cost Optimzsation + /// + [DataMember(Name = "costOptimization")] + CostOptimization } diff --git a/LogicMonitor.Api/Users/User.cs b/LogicMonitor.Api/Users/User.cs index e12a29a3..edcdfdff 100644 --- a/LogicMonitor.Api/Users/User.cs +++ b/LogicMonitor.Api/Users/User.cs @@ -216,6 +216,12 @@ public class User : IdentifiedItem, IHasEndpoint [DataMember(Name = "immediateForceLogout")] public bool ImmediateForceLogout { get; set; } + /// + /// The last authorized IP address + /// + [DataMember(Name = "lastAuthIp")] + public string LastAuthIp { get; set; } = string.Empty; + /// /// The endpoint /// From 584196a81390d8b6bbf8cd76bc1e64a65e0ce472 Mon Sep 17 00:00:00 2001 From: Roland Banks Date: Fri, 5 Apr 2024 14:12:44 +0700 Subject: [PATCH 3/3] Fixed some broken models for alert settings --- .../Alerts/InstanceGroupAlertThresholdInfo.cs | 19 +++++++++++++++++++ .../LogicModules/DataPointConfiguration.cs | 8 +++++++- .../DataPointConfigurationCreationDTO.cs | 2 +- LogicMonitor.Api/LogicMonitor.Api.csproj | 2 +- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/LogicMonitor.Api/Alerts/InstanceGroupAlertThresholdInfo.cs b/LogicMonitor.Api/Alerts/InstanceGroupAlertThresholdInfo.cs index 04f1f51c..07513418 100644 --- a/LogicMonitor.Api/Alerts/InstanceGroupAlertThresholdInfo.cs +++ b/LogicMonitor.Api/Alerts/InstanceGroupAlertThresholdInfo.cs @@ -36,4 +36,23 @@ public class InstanceGroupAlertThresholdInfo /// [DataMember(Name = "alertExpr")] public string AlertExpression { get; set; } = string.Empty; + + /// + /// The alert transition interval + /// + [DataMember(Name = "alertTransitionInterval")] + public string AlertTransitionInterval { get; set; } = string.Empty; + + /// + /// The alert clear transition interval + /// + [DataMember(Name = "alertClearTransitionInterval")] + public string AlertClearTransitionInterval { get; set; } = string.Empty; + + /// + /// The alert for no data value + /// + [DataMember(Name = "alertForNoData")] + public int AlertForNoData { get; set; } + } diff --git a/LogicMonitor.Api/LogicModules/DataPointConfiguration.cs b/LogicMonitor.Api/LogicModules/DataPointConfiguration.cs index d2313dc3..79f3d1b0 100644 --- a/LogicMonitor.Api/LogicModules/DataPointConfiguration.cs +++ b/LogicMonitor.Api/LogicModules/DataPointConfiguration.cs @@ -205,7 +205,13 @@ public class DataPointConfiguration : IdentifiedItem /// Parent Instance Group Alert Expression /// [DataMember(Name = "parentInstanceGroupAlertExpr")] - public string ParentInstanceGroupAlertExpression { get; set; } = string.Empty; + public InstanceGroupAlertThresholdInfo? ParentInstanceGroupAlertExpression { get; set; } + + /// + /// Parent Resource Group Alert Expression + /// + [DataMember(Name = "parentResourceDataSourceAlertExpr")] + public object? ParentResourceDataSourceAlertExpr { get; set; } /// /// Alert for no data diff --git a/LogicMonitor.Api/LogicModules/DataPointConfigurationCreationDTO.cs b/LogicMonitor.Api/LogicModules/DataPointConfigurationCreationDTO.cs index d5b18009..b19301a2 100644 --- a/LogicMonitor.Api/LogicModules/DataPointConfigurationCreationDTO.cs +++ b/LogicMonitor.Api/LogicModules/DataPointConfigurationCreationDTO.cs @@ -52,5 +52,5 @@ public class DataPointConfigurationCreationDTO : IdentifiedItem /// Parent Instance Group Alert Expression /// [DataMember(Name = "parentInstanceGroupAlertExpr")] - public string ParentInstanceGroupAlertExpression { get; set; } = string.Empty; + public InstanceGroupAlertThresholdInfo? ParentInstanceGroupAlertExpression { get; set; } } diff --git a/LogicMonitor.Api/LogicMonitor.Api.csproj b/LogicMonitor.Api/LogicMonitor.Api.csproj index f6e71111..5ed4b34e 100644 --- a/LogicMonitor.Api/LogicMonitor.Api.csproj +++ b/LogicMonitor.Api/LogicMonitor.Api.csproj @@ -28,7 +28,7 @@ - Added missing LastAuthIp property to User. Added missing CostOptimization property to RolePrivilegeType. Added User Role test + Fixed some broken models for alert settings 57aaa0e7-815d-4065-9339-f3f070bed01e