Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻ refactor: Alarm notification adds aggregated variables #358

Merged
merged 21 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
da32aed
chore : using
wzh425 Aug 21, 2023
63088f6
Merge branch 'main' of github.com:masastack/MASA.Alert
wzh425 Sep 27, 2023
e850cf9
Merge branch 'main' of github.com:masastack/MASA.Alert
wzh425 Nov 16, 2023
ffff5df
Merge branch 'main' of github.com:masastack/MASA.Alert
wzh425 Jan 2, 2024
a8a5582
Merge branch 'main' of https://github.com/masastack/MASA.Alert
wzh425 Jan 26, 2024
e03fe75
Merge branch 'main' of https://github.com/masastack/MASA.Alert
wzh425 Feb 1, 2024
bc7b21e
Merge branch 'main' of https://github.com/masastack/MASA.Alert
wzh425 Apr 10, 2024
0cb219c
Merge branch 'main' of https://github.com/masastack/MASA.Alert
wzh425 Apr 16, 2024
d22841e
Merge branch 'main' of https://github.com/masastack/MASA.Alert
wzh425 Jun 1, 2024
ecf5ee4
Merge branch 'main' of https://github.com/masastack/MASA.Alert
wzh425 Jun 19, 2024
0e1e19e
Merge branch 'main' of https://github.com/masastack/MASA.Alert
wzh425 Jul 12, 2024
e24c29d
Merge branch 'main' of https://github.com/masastack/MASA.Alert
wzh425 Jul 17, 2024
0361efe
Merge branch 'main' of github.com:masastack/MASA.Alert
wzh425 Jul 23, 2024
f5ec530
Merge branch 'main' of github.com:masastack/MASA.Alert
wzh425 Jul 23, 2024
f13a7ee
Merge branch 'main' of github.com:masastack/MASA.Alert
wzh425 Aug 6, 2024
caba51d
Merge branch 'main' of github.com:masastack/MASA.Alert
wzh425 Aug 6, 2024
5481e16
Merge branch 'main' of github.com:masastack/MASA.Alert
wzh425 Sep 4, 2024
c27aef1
Merge branch 'main' of github.com:masastack/MASA.Alert
wzh425 Sep 5, 2024
bbd281b
♻ refactor: Alarm notification adds aggregated variables
wzh425 Sep 5, 2024
00ee86c
♻ refactor: Remove unnecessary parameters
wzh425 Sep 5, 2024
75213d6
♻ refactor: Alarm notification add checkTime variables
wzh425 Sep 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ public async Task HandleEventAsync(SendAlarmNotificationEvent eto)
var notificationConfig = item.AlarmRuleItem.NotificationConfig;

var variables = new Dictionary<string, object>();
var alarmRule = await _alarmRuleRepository.FindAsync(x => x.Id == eto.AlarmRuleId);

AddAggregateVariables(variables, eto.AggregateResult);

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);
Expand All @@ -55,6 +58,14 @@ public async Task HandleEventAsync(SendAlarmNotificationEvent eto)
await _repository.UpdateAsync(alarm);
}

private void AddAggregateVariables(Dictionary<string, object> variables, ConcurrentDictionary<string, long> aggregateResult)
{
foreach (var aggregateItem in aggregateResult)
{
variables.TryAdd(aggregateItem.Key, aggregateItem.Value);
}
}

private async Task AddLogVariablesAsync(AlarmRule alarmRule, Dictionary<string, object> variables)
{
var checkTime = DateTimeOffset.Now;
Expand All @@ -63,6 +74,9 @@ private async Task AddLogVariablesAsync(AlarmRule alarmRule, Dictionary<string,
if (startTime == null)
return;

variables.TryAdd(AlertConsts.CHECK_START_TIME_NOTIFICATION_TEMPLATE_VAR_NAME, startTime.Value.UtcDateTime);
variables.TryAdd(AlertConsts.CHECK_END_TIME_NOTIFICATION_TEMPLATE_VAR_NAME, checkTime.UtcDateTime);

var request = new LogLatestRequest
{
Query = alarmRule.WhereExpression,
Expand Down
2 changes: 2 additions & 0 deletions src/Domain/Masa.Alert.Domain.Shared/Consts/AlertConsts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ public static class AlertConsts
public const string DB_TABLE_PREFIX = null;
public const string DB_SCHEMA = "alert";
public const string ALARM_RULE_NAME_NOTIFICATION_TEMPLATE_VAR_NAME = "Name";
public const string CHECK_START_TIME_NOTIFICATION_TEMPLATE_VAR_NAME = "CheckStartTime";
public const string CHECK_END_TIME_NOTIFICATION_TEMPLATE_VAR_NAME = "CheckEndTime";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, long> aggregateResult)
{
IsNotification = isNotification;

if (IsNotification && !isSilence)
{
AddDomainEvent(new SendAlarmNotificationEvent(Id, AlarmRuleId));
AddDomainEvent(new SendAlarmNotificationEvent(Id, aggregateResult));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

namespace Masa.Alert.Domain.AlarmRules.Events;

public record SendAlarmNotificationEvent(Guid AlarmHistoryId, Guid AlarmRuleId) : DomainEvent
public record SendAlarmNotificationEvent(Guid AlarmHistoryId, ConcurrentDictionary<string, long> AggregateResult) : DomainEvent
{
}