1
0
Fork 0
mirror of https://github.com/TwiN/gatus.git synced 2024-12-14 11:58:04 +00:00

only set RepeatInterval if nil

This commit is contained in:
Jackson Sabey 2024-08-31 16:33:03 -07:00
parent 45bfd47920
commit 8e496904be
4 changed files with 24 additions and 14 deletions

View file

@ -50,7 +50,7 @@ type Alert struct {
ResolveKey string `yaml:"-"`
// RepeatInterval is the interval between reminders
RepeatInterval time.Duration `yaml:"repeat-interval,omitempty"`
RepeatInterval *time.Duration `yaml:"repeat-interval"`
// Triggered is used to determine whether an alert has been triggered. When an alert is resolved, this value
// should be set back to false. It is used to prevent the same alert from going out twice.

View file

@ -57,7 +57,7 @@ func ParseWithDefaultAlert(providerDefaultAlert, endpointAlert *alert.Alert) {
if endpointAlert.SuccessThreshold == 0 {
endpointAlert.SuccessThreshold = providerDefaultAlert.SuccessThreshold
}
if endpointAlert.RepeatInterval == 0 {
if endpointAlert.RepeatInterval == nil {
endpointAlert.RepeatInterval = providerDefaultAlert.RepeatInterval
}
}

View file

@ -38,8 +38,8 @@ func handleAlertsToTrigger(ep *endpoint.Endpoint, result *endpoint.Result, alert
if lr, ok := ep.LastReminderSent[endpointAlert.Type]; ok && !lr.IsZero() {
lastReminder = time.Since(lr)
}
sendReminder := endpointAlert.Triggered && endpointAlert.RepeatInterval > 0 &&
(lastReminder == 0 || lastReminder >= endpointAlert.RepeatInterval)
sendReminder := endpointAlert.Triggered && endpointAlert.RepeatInterval != nil &&
*endpointAlert.RepeatInterval > 0 && (lastReminder == 0 || lastReminder >= *endpointAlert.RepeatInterval)
// If neither initial alert nor reminder needs to be sent, skip to the next alert
if !sendInitialAlert && !sendReminder {
if debug {

View file

@ -39,7 +39,8 @@ func TestHandleAlerting(t *testing.T) {
}
enabled := true
ep := &endpoint.Endpoint{
URL: "https://example.com",
URL: "https://example.com",
LastReminderSent: make(map[alert.Type]time.Time),
Alerts: []*alert.Alert{
{
Type: alert.TypeCustom,
@ -83,7 +84,8 @@ func TestHandleAlertingWithBadAlertProvider(t *testing.T) {
enabled := true
ep := &endpoint.Endpoint{
URL: "http://example.com",
URL: "http://example.com",
LastReminderSent: make(map[alert.Type]time.Time),
Alerts: []*alert.Alert{
{
Type: alert.TypeCustom,
@ -118,7 +120,8 @@ func TestHandleAlertingWhenTriggeredAlertIsAlmostResolvedButendpointStartFailing
}
enabled := true
ep := &endpoint.Endpoint{
URL: "https://example.com",
URL: "https://example.com",
LastReminderSent: make(map[alert.Type]time.Time),
Alerts: []*alert.Alert{
{
Type: alert.TypeCustom,
@ -153,7 +156,8 @@ func TestHandleAlertingWhenTriggeredAlertIsResolvedButSendOnResolvedIsFalse(t *t
enabled := true
disabled := false
ep := &endpoint.Endpoint{
URL: "https://example.com",
URL: "https://example.com",
LastReminderSent: make(map[alert.Type]time.Time),
Alerts: []*alert.Alert{
{
Type: alert.TypeCustom,
@ -185,7 +189,8 @@ func TestHandleAlertingWhenTriggeredAlertIsResolvedPagerDuty(t *testing.T) {
}
enabled := true
ep := &endpoint.Endpoint{
URL: "https://example.com",
URL: "https://example.com",
LastReminderSent: make(map[alert.Type]time.Time),
Alerts: []*alert.Alert{
{
Type: alert.TypePagerDuty,
@ -221,7 +226,8 @@ func TestHandleAlertingWhenTriggeredAlertIsResolvedPushover(t *testing.T) {
}
enabled := true
ep := &endpoint.Endpoint{
URL: "https://example.com",
URL: "https://example.com",
LastReminderSent: make(map[alert.Type]time.Time),
Alerts: []*alert.Alert{
{
Type: alert.TypePushover,
@ -391,7 +397,8 @@ func TestHandleAlertingWithProviderThatReturnsAnError(t *testing.T) {
for _, scenario := range scenarios {
t.Run(scenario.Name, func(t *testing.T) {
ep := &endpoint.Endpoint{
URL: "https://example.com",
URL: "https://example.com",
LastReminderSent: make(map[alert.Type]time.Time),
Alerts: []*alert.Alert{
{
Type: scenario.AlertType,
@ -451,7 +458,8 @@ func TestHandleAlertingWithProviderThatOnlyReturnsErrorOnResolve(t *testing.T) {
}
enabled := true
ep := &endpoint.Endpoint{
URL: "https://example.com",
URL: "https://example.com",
LastReminderSent: make(map[alert.Type]time.Time),
Alerts: []*alert.Alert{
{
Type: alert.TypeCustom,
@ -502,8 +510,10 @@ func TestHandleAlertingWithRepeatInterval(t *testing.T) {
},
}
enabled := true
repeatInterval := 1 * time.Second
ep := &endpoint.Endpoint{
URL: "https://example.com",
URL: "https://example.com",
LastReminderSent: make(map[alert.Type]time.Time),
Alerts: []*alert.Alert{
{
Type: alert.TypeCustom,
@ -512,7 +522,7 @@ func TestHandleAlertingWithRepeatInterval(t *testing.T) {
SuccessThreshold: 3,
SendOnResolved: &enabled,
Triggered: false,
RepeatInterval: 1 * time.Second,
RepeatInterval: &repeatInterval,
},
},
}