From da32aed6477c5c3786b11ee3bd53857da4b45513 Mon Sep 17 00:00:00 2001 From: wzh425 Date: Mon, 21 Aug 2023 08:55:44 +0800 Subject: [PATCH 1/4] chore : using --- src/Application/Masa.Alert.Application/_Imports.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Application/Masa.Alert.Application/_Imports.cs b/src/Application/Masa.Alert.Application/_Imports.cs index 65c48d1..609f155 100644 --- a/src/Application/Masa.Alert.Application/_Imports.cs +++ b/src/Application/Masa.Alert.Application/_Imports.cs @@ -49,11 +49,9 @@ global using Masa.BuildingBlocks.StackSdks.Tsc.Model; global using Masa.Contrib.Dispatcher.Events; global using Masa.Contrib.StackSdks.Config; -global using Masa.Contrib.StackSdks.Caller; global using Microsoft.EntityFrameworkCore; global using Microsoft.Extensions.Logging; global using Masa.Alert.Infrastructure.Constants; -global using Masa.Alert.Application.AlarmRules.Commands; global using Masa.BuildingBlocks.Dispatcher.Events; global using Masa.BuildingBlocks.Caching; global using Masa.Alert.Domain.Shared.Consts; From bbd281b757c172b03e57217c9838c8a5aaa05e9e Mon Sep 17 00:00:00 2001 From: wzh425 Date: Thu, 5 Sep 2024 17:04:52 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E2=99=BB=20refactor:=20Alarm=20notificatio?= =?UTF-8?q?n=20adds=20aggregated=20variables?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EventHandler/TriggerAlarmEventHandler.cs | 4 ++-- .../EventHandler/SendAlarmNotificationEventHandler.cs | 11 +++++++++++ .../AlarmHistories/Aggregates/AlarmHistory.cs | 4 ++-- .../AlarmRules/Events/SendAlarmNotificationEvent.cs | 2 +- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Application/Masa.Alert.Application/AlarmHistories/EventHandler/TriggerAlarmEventHandler.cs b/src/Application/Masa.Alert.Application/AlarmHistories/EventHandler/TriggerAlarmEventHandler.cs index 7e1cfe1..f096f27 100644 --- a/src/Application/Masa.Alert.Application/AlarmHistories/EventHandler/TriggerAlarmEventHandler.cs +++ b/src/Application/Masa.Alert.Application/AlarmHistories/EventHandler/TriggerAlarmEventHandler.cs @@ -29,13 +29,13 @@ public async Task HandleEventAsync(TriggerAlarmEvent eto) { alarm = new AlarmHistory(eto.AlarmRuleId, eto.AlertSeverity, isNotification, eto.TriggerRuleItems); alarm.AddAlarmRuleRecord(eto.ExcuteTime, eto.AggregateResult, true, eto.ConsecutiveCount, eto.TriggerRuleItems); - alarm.SetIsNotification(isNotification, isSilence); + alarm.SetIsNotification(isNotification, isSilence, eto.AggregateResult); await _repository.AddAsync(alarm); } else { alarm.Update(eto.AlertSeverity, isNotification, eto.TriggerRuleItems); - alarm.SetIsNotification(isNotification, isSilence); + alarm.SetIsNotification(isNotification, isSilence, eto.AggregateResult); alarm.AddAlarmRuleRecord(eto.ExcuteTime, eto.AggregateResult, true, eto.ConsecutiveCount, eto.TriggerRuleItems); await _repository.UpdateAsync(alarm); diff --git a/src/Application/Masa.Alert.Application/AlarmRules/EventHandler/SendAlarmNotificationEventHandler.cs b/src/Application/Masa.Alert.Application/AlarmRules/EventHandler/SendAlarmNotificationEventHandler.cs index 800b6cd..7ed760f 100644 --- a/src/Application/Masa.Alert.Application/AlarmRules/EventHandler/SendAlarmNotificationEventHandler.cs +++ b/src/Application/Masa.Alert.Application/AlarmRules/EventHandler/SendAlarmNotificationEventHandler.cs @@ -37,6 +37,9 @@ public async Task HandleEventAsync(SendAlarmNotificationEvent eto) var notificationConfig = item.AlarmRuleItem.NotificationConfig; var variables = new Dictionary(); + + AddAggregateVariables(variables, eto.AggregateResult); + var alarmRule = await _alarmRuleRepository.FindAsync(x => x.Id == eto.AlarmRuleId); if (alarmRule != null) { @@ -55,6 +58,14 @@ public async Task HandleEventAsync(SendAlarmNotificationEvent eto) await _repository.UpdateAsync(alarm); } + private void AddAggregateVariables(Dictionary variables, ConcurrentDictionary aggregateResult) + { + foreach (var aggregateItem in aggregateResult) + { + variables.TryAdd(aggregateItem.Key, aggregateItem.Value); + } + } + private async Task AddLogVariablesAsync(AlarmRule alarmRule, Dictionary variables) { var checkTime = DateTimeOffset.Now; diff --git a/src/Domain/Masa.Alert.Domain/AlarmHistories/Aggregates/AlarmHistory.cs b/src/Domain/Masa.Alert.Domain/AlarmHistories/Aggregates/AlarmHistory.cs index 1570597..dbd5b3d 100644 --- a/src/Domain/Masa.Alert.Domain/AlarmHistories/Aggregates/AlarmHistory.cs +++ b/src/Domain/Masa.Alert.Domain/AlarmHistories/Aggregates/AlarmHistory.cs @@ -85,13 +85,13 @@ public void Notification() LastNotificationTime = DateTimeOffset.Now; } - public void SetIsNotification(bool isNotification, bool isSilence) + public void SetIsNotification(bool isNotification, bool isSilence, ConcurrentDictionary aggregateResult) { IsNotification = isNotification; if (IsNotification && !isSilence) { - AddDomainEvent(new SendAlarmNotificationEvent(Id, AlarmRuleId)); + AddDomainEvent(new SendAlarmNotificationEvent(Id, AlarmRuleId, aggregateResult)); } } diff --git a/src/Domain/Masa.Alert.Domain/AlarmRules/Events/SendAlarmNotificationEvent.cs b/src/Domain/Masa.Alert.Domain/AlarmRules/Events/SendAlarmNotificationEvent.cs index 211188c..0a8e827 100644 --- a/src/Domain/Masa.Alert.Domain/AlarmRules/Events/SendAlarmNotificationEvent.cs +++ b/src/Domain/Masa.Alert.Domain/AlarmRules/Events/SendAlarmNotificationEvent.cs @@ -3,6 +3,6 @@ namespace Masa.Alert.Domain.AlarmRules.Events; -public record SendAlarmNotificationEvent(Guid AlarmHistoryId, Guid AlarmRuleId) : DomainEvent +public record SendAlarmNotificationEvent(Guid AlarmHistoryId, Guid AlarmRuleId, ConcurrentDictionary AggregateResult) : DomainEvent { } \ No newline at end of file From 00ee86c4b277b90e5d95a2d576d196a66d6d7f92 Mon Sep 17 00:00:00 2001 From: wzh425 Date: Thu, 5 Sep 2024 17:08:38 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E2=99=BB=20refactor:=20Remove=20unnecessar?= =?UTF-8?q?y=20parameters?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EventHandler/SendAlarmNotificationEventHandler.cs | 2 +- .../Masa.Alert.Domain/AlarmHistories/Aggregates/AlarmHistory.cs | 2 +- .../AlarmRules/Events/SendAlarmNotificationEvent.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Application/Masa.Alert.Application/AlarmRules/EventHandler/SendAlarmNotificationEventHandler.cs b/src/Application/Masa.Alert.Application/AlarmRules/EventHandler/SendAlarmNotificationEventHandler.cs index 7ed760f..1f9d585 100644 --- a/src/Application/Masa.Alert.Application/AlarmRules/EventHandler/SendAlarmNotificationEventHandler.cs +++ b/src/Application/Masa.Alert.Application/AlarmRules/EventHandler/SendAlarmNotificationEventHandler.cs @@ -40,7 +40,7 @@ public async Task HandleEventAsync(SendAlarmNotificationEvent eto) AddAggregateVariables(variables, eto.AggregateResult); - var alarmRule = await _alarmRuleRepository.FindAsync(x => x.Id == eto.AlarmRuleId); + var alarmRule = await _alarmRuleRepository.FindAsync(x => x.Id == alarm.AlarmRuleId); if (alarmRule != null) { variables.TryAdd(AlertConsts.ALARM_RULE_NAME_NOTIFICATION_TEMPLATE_VAR_NAME, alarmRule.DisplayName); diff --git a/src/Domain/Masa.Alert.Domain/AlarmHistories/Aggregates/AlarmHistory.cs b/src/Domain/Masa.Alert.Domain/AlarmHistories/Aggregates/AlarmHistory.cs index dbd5b3d..8c6ecfb 100644 --- a/src/Domain/Masa.Alert.Domain/AlarmHistories/Aggregates/AlarmHistory.cs +++ b/src/Domain/Masa.Alert.Domain/AlarmHistories/Aggregates/AlarmHistory.cs @@ -91,7 +91,7 @@ public void SetIsNotification(bool isNotification, bool isSilence, ConcurrentDic if (IsNotification && !isSilence) { - AddDomainEvent(new SendAlarmNotificationEvent(Id, AlarmRuleId, aggregateResult)); + AddDomainEvent(new SendAlarmNotificationEvent(Id, aggregateResult)); } } diff --git a/src/Domain/Masa.Alert.Domain/AlarmRules/Events/SendAlarmNotificationEvent.cs b/src/Domain/Masa.Alert.Domain/AlarmRules/Events/SendAlarmNotificationEvent.cs index 0a8e827..e7a9512 100644 --- a/src/Domain/Masa.Alert.Domain/AlarmRules/Events/SendAlarmNotificationEvent.cs +++ b/src/Domain/Masa.Alert.Domain/AlarmRules/Events/SendAlarmNotificationEvent.cs @@ -3,6 +3,6 @@ namespace Masa.Alert.Domain.AlarmRules.Events; -public record SendAlarmNotificationEvent(Guid AlarmHistoryId, Guid AlarmRuleId, ConcurrentDictionary AggregateResult) : DomainEvent +public record SendAlarmNotificationEvent(Guid AlarmHistoryId, ConcurrentDictionary AggregateResult) : DomainEvent { } \ No newline at end of file From 75213d6a5e1c42f3489014ced7f741dcf14df8c8 Mon Sep 17 00:00:00 2001 From: wzh425 Date: Thu, 5 Sep 2024 17:30:52 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E2=99=BB=20refactor:=20Alarm=20notificatio?= =?UTF-8?q?n=20add=20checkTime=20variables?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EventHandler/SendAlarmNotificationEventHandler.cs | 3 +++ src/Domain/Masa.Alert.Domain.Shared/Consts/AlertConsts.cs | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/Application/Masa.Alert.Application/AlarmRules/EventHandler/SendAlarmNotificationEventHandler.cs b/src/Application/Masa.Alert.Application/AlarmRules/EventHandler/SendAlarmNotificationEventHandler.cs index 1f9d585..fd33dd1 100644 --- a/src/Application/Masa.Alert.Application/AlarmRules/EventHandler/SendAlarmNotificationEventHandler.cs +++ b/src/Application/Masa.Alert.Application/AlarmRules/EventHandler/SendAlarmNotificationEventHandler.cs @@ -74,6 +74,9 @@ private async Task AddLogVariablesAsync(AlarmRule alarmRule, Dictionary