diff --git a/models/notifications.go b/models/notifications.go index 819f8bba..87c32f00 100644 --- a/models/notifications.go +++ b/models/notifications.go @@ -18,6 +18,7 @@ type Notification struct { Title string `json:"title,omitempty"` Template string `json:"template,omitempty"` Filter string `json:"filter,omitempty"` + PlaybookID *uuid.UUID `json:"playbook_id,omitempty"` PersonID *uuid.UUID `json:"person_id,omitempty"` TeamID *uuid.UUID `json:"team_id,omitempty"` Properties types.JSONStringMap `json:"properties,omitempty"` @@ -50,7 +51,7 @@ func (n Notification) PK() string { } func (n *Notification) HasRecipients() bool { - return n.TeamID != nil || n.PersonID != nil || len(n.CustomServices) != 0 + return n.TeamID != nil || n.PersonID != nil || len(n.CustomServices) != 0 || n.PlaybookID != nil } func (n Notification) AsMap(removeFields ...string) map[string]any { @@ -105,6 +106,9 @@ type NotificationSendHistory struct { // ID of the person this notification is for. PersonID *uuid.UUID `json:"person_id"` + // The run created by this notification + PlaybookRunID *uuid.UUID `json:"playbook_run_id"` + timeStart time.Time } diff --git a/models/playbooks.go b/models/playbooks.go index 5673e6b2..82c82087 100644 --- a/models/playbooks.go +++ b/models/playbooks.go @@ -78,6 +78,14 @@ type Playbook struct { DeletedAt *time.Time `json:"deleted_at,omitempty" time_format:"postgres_timestamp"` } +func (p *Playbook) NamespacedName() string { + if p.Namespace != "" { + return fmt.Sprintf("%s/%s", p.Namespace, p.Name) + } + + return p.Name +} + func (p *Playbook) LoggerName() string { return "playbook." + p.Name } diff --git a/schema/notifications.hcl b/schema/notifications.hcl index 3b267563..2455c0e8 100644 --- a/schema/notifications.hcl +++ b/schema/notifications.hcl @@ -40,6 +40,11 @@ table "notifications" { type = jsonb comment = "Shoutrrr properties used when sending email to the person receipient." } + column "playbook_id" { + null = true + type = uuid + comment = "playbook to trigger" + } column "person_id" { null = true type = uuid @@ -145,17 +150,17 @@ table "notification_send_history" { type = text } column "not_before" { - null = true - type = timestamptz + null = true + type = timestamptz } column "retries" { - null = true - type = integer + null = true + type = integer comment = "number of retries of pending notifications" } column "payload" { - null = true - type = jsonb + null = true + type = jsonb comment = "holds in original event properties for delayed/pending notifications" } column "count" { @@ -182,6 +187,11 @@ table "notification_send_history" { null = true type = uuid } + column "playbook_run_id" { + null = true + type = uuid + comment = "playbook run created by this notification dispatch" + } column "error" { null = true type = text