Skip to content

Commit

Permalink
CR
Browse files Browse the repository at this point in the history
  • Loading branch information
Kimchelly committed Jun 3, 2024
1 parent f618a56 commit 8ff9f5a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 39 deletions.
6 changes: 3 additions & 3 deletions model/alertrecord/alert_bookkeeping.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ func FindBySpawnHostExpirationWithHours(hostID string, hours int) (*AlertRecord,
return FindOne(db.Query(q).Limit(1))
}

// FindByTemporaryExemptionExpirationWithHours finds the most recent alert
// record for a spawn host's temporary exemption that is about to expire.
func FindMostRecentByTemporaryExemptionExpirationWithHours(hostID string, hours int) (*AlertRecord, error) {
// FindByMostRecentTemporaryExemptionExpirationWithHours finds the most recent
// alert record for a spawn host's temporary exemption that is about to expire.
func FindByMostRecentTemporaryExemptionExpirationWithHours(hostID string, hours int) (*AlertRecord, error) {
alertType := fmt.Sprintf(hostTemporaryExemptionWarningTemplate, hours)
q := subscriptionIDQuery(legacyAlertsSubscription)
q[TypeKey] = alertType
Expand Down
73 changes: 37 additions & 36 deletions trigger/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,48 +220,49 @@ func (t *hostTemplateData) hostSlackPayload(messageString string, linkTitle stri
func (t *hostTriggers) hostExpiration(sub *event.Subscription) (*notification.Notification, error) {
switch t.event.EventType {
case event.EventHostExpirationWarningSent:
if t.host.NoExpiration {
return nil, nil
}

timeZone := time.Local
if sub.OwnerType == event.OwnerTypePerson {
userTimeZone, err := getUserTimeZone(sub.Owner)
grip.Error(message.WrapError(err, message.Fields{
"message": "problem getting user's time zone",
"user": sub.Owner,
"event_type": t.event.EventType,
"trigger": "host temporary exemption expiration",
}))
if userTimeZone != nil {
timeZone = userTimeZone
}
}
t.templateData.ExpirationTime = t.host.ExpirationTime.In(timeZone).Format(time.RFC1123)

return t.generateExpiration(sub)
return t.makeHostExpirationNotification(sub)
case event.EventHostTemporaryExemptionExpirationWarningSent:
timeZone := time.Local
if sub.OwnerType == event.OwnerTypePerson {
userTimeZone, err := getUserTimeZone(sub.Owner)
grip.Error(message.WrapError(err, message.Fields{
"message": "problem getting user time zone",
"user": sub.Owner,
"event_type": t.event.EventType,
"trigger": " host expiration",
}))
if userTimeZone != nil {
timeZone = userTimeZone
}
}
t.templateData.ExpirationTime = t.host.SleepSchedule.TemporarilyExemptUntil.In(timeZone).Format(time.RFC1123)

return t.generateTemporaryExemptionExpiration(sub)
return t.makeHostTemporaryExemptionNotification(sub)
default:
return nil, nil
}
}

func (t *hostTriggers) makeHostExpirationNotification(sub *event.Subscription) (*notification.Notification, error) {
if t.host.NoExpiration {
return nil, nil
}

timeZone := t.getTimeZone(sub, "host expiration")
t.templateData.ExpirationTime = t.host.ExpirationTime.In(timeZone).Format(time.RFC1123)

return t.generateExpiration(sub)
}

func (t *hostTriggers) makeHostTemporaryExemptionNotification(sub *event.Subscription) (*notification.Notification, error) {
timeZone := t.getTimeZone(sub, "host temporary exemption expiration")
t.templateData.ExpirationTime = t.host.SleepSchedule.TemporarilyExemptUntil.In(timeZone).Format(time.RFC1123)

return t.generateTemporaryExemptionExpiration(sub)
}

func (t *hostTriggers) getTimeZone(sub *event.Subscription, trigger string) *time.Location {
if sub.OwnerType == event.OwnerTypePerson {
userTimeZone, err := getUserTimeZone(sub.Owner)
grip.Error(message.WrapError(err, message.Fields{
"message": "problem getting user time zone",
"user": sub.Owner,
"event_type": t.event.EventType,
"trigger": trigger,
}))
if userTimeZone != nil {
return userTimeZone
}
}

return time.Local
}

func (t *hostTriggers) spawnHostIdle(sub *event.Subscription) (*notification.Notification, error) {
shouldNotify, err := t.host.ShouldNotifyStoppedSpawnHostIdle()
if err != nil {
Expand Down

0 comments on commit 8ff9f5a

Please sign in to comment.