1 package linodego
2 3 import (
4 "context"
5 "encoding/json"
6 "time"
7 8 "github.com/linode/linodego/internal/parseabletime"
9 )
10 11 // Notification represents a notification on an Account
12 type Notification struct {
13 Label string `json:"label"`
14 Body *string `json:"body"`
15 Message string `json:"message"`
16 Type NotificationType `json:"type"`
17 Severity NotificationSeverity `json:"severity"`
18 Entity *NotificationEntity `json:"entity"`
19 Until *time.Time `json:"-"`
20 When *time.Time `json:"-"`
21 }
22 23 // NotificationEntity adds detailed information about the Notification.
24 // This could refer to the ticket that triggered the notification, for example.
25 type NotificationEntity struct {
26 ID int `json:"id"`
27 Label string `json:"label"`
28 Type string `json:"type"`
29 URL string `json:"url"`
30 }
31 32 // NotificationSeverity constants start with Notification and include all known Linode API Notification Severities.
33 type NotificationSeverity string
34 35 // NotificationSeverity constants represent the actions that cause a Notification. New severities may be added in the future.
36 const (
37 NotificationMinor NotificationSeverity = "minor"
38 NotificationMajor NotificationSeverity = "major"
39 NotificationCritical NotificationSeverity = "critical"
40 )
41 42 // NotificationType constants start with Notification and include all known Linode API Notification Types.
43 type NotificationType string
44 45 // NotificationType constants represent the actions that cause a Notification. New types may be added in the future.
46 const (
47 NotificationMigrationScheduled NotificationType = "migration_scheduled"
48 NotificationMigrationImminent NotificationType = "migration_imminent"
49 NotificationMigrationPending NotificationType = "migration_pending"
50 NotificationRebootScheduled NotificationType = "reboot_scheduled"
51 NotificationOutage NotificationType = "outage"
52 NotificationPaymentDue NotificationType = "payment_due"
53 NotificationTicketImportant NotificationType = "ticket_important"
54 NotificationTicketAbuse NotificationType = "ticket_abuse"
55 NotificationNotice NotificationType = "notice"
56 NotificationMaintenance NotificationType = "maintenance"
57 NotificationMaintenanceScheduled NotificationType = "maintenance_scheduled"
58 )
59 60 // ListNotifications gets a collection of Notification objects representing important,
61 // often time-sensitive items related to the Account. An account cannot interact directly with
62 // Notifications, and a Notification will disappear when the circumstances causing it
63 // have been resolved. For example, if the account has an important Ticket open, a response
64 // to the Ticket will dismiss the Notification.
65 func (c *Client) ListNotifications(ctx context.Context, opts *ListOptions) ([]Notification, error) {
66 return getPaginatedResults[Notification](ctx, c, "account/notifications", opts)
67 }
68 69 // UnmarshalJSON implements the json.Unmarshaler interface
70 func (i *Notification) UnmarshalJSON(b []byte) error {
71 type Mask Notification
72 73 p := struct {
74 *Mask
75 76 Until *parseabletime.ParseableTime `json:"until"`
77 When *parseabletime.ParseableTime `json:"when"`
78 }{
79 Mask: (*Mask)(i),
80 }
81 82 if err := json.Unmarshal(b, &p); err != nil {
83 return err
84 }
85 86 i.Until = (*time.Time)(p.Until)
87 i.When = (*time.Time)(p.When)
88 89 return nil
90 }
91