|
| 1 | +package linodego |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "encoding/json" |
| 6 | + "time" |
| 7 | + |
| 8 | + "github.com/linode/linodego/internal/parseabletime" |
| 9 | +) |
| 10 | + |
| 11 | +// MonitorDashboard represents an ACLP Dashboard object |
| 12 | +type MonitorDashboard struct { |
| 13 | + ID int `json:"id"` |
| 14 | + Type DashboardType `json:"type"` |
| 15 | + ServiceType ServiceType `json:"service_type"` |
| 16 | + Label string `json:"label"` |
| 17 | + Created *time.Time `json:"-"` |
| 18 | + Updated *time.Time `json:"-"` |
| 19 | + Widgets []DashboardWidget `json:"widgets"` |
| 20 | +} |
| 21 | + |
| 22 | +// enum object for serviceType |
| 23 | +type ServiceType string |
| 24 | + |
| 25 | +const ( |
| 26 | + ServiceTypeLinode ServiceType = "linode" |
| 27 | + ServiceTypeLKE ServiceType = "lke" |
| 28 | + ServiceTypeDBaaS ServiceType = "dbaas" |
| 29 | + ServiceTypeACLB ServiceType = "aclb" |
| 30 | + ServiceTypeNodeBalancer ServiceType = "nodebalancer" |
| 31 | + ServiceTypeObjectStorage ServiceType = "objectstorage" |
| 32 | + ServiceTypeVPC ServiceType = "vpc" |
| 33 | + ServiceTypeFirewallService ServiceType = "firewall" |
| 34 | +) |
| 35 | + |
| 36 | +// enum object for DashboardType |
| 37 | +type DashboardType string |
| 38 | + |
| 39 | +const ( |
| 40 | + DashboardTypeStandard DashboardType = "standard" |
| 41 | + DashboardTypeCustom DashboardType = "custom" |
| 42 | +) |
| 43 | + |
| 44 | +// DashboardWidget represents an ACLP DashboardWidget object |
| 45 | +type DashboardWidget struct { |
| 46 | + Metric string `json:"metric"` |
| 47 | + Unit string `json:"unit"` |
| 48 | + Label string `json:"label"` |
| 49 | + Color string `json:"color"` |
| 50 | + Size int `json:"size"` |
| 51 | + ChartType ChartType `json:"chart_type"` |
| 52 | + YLabel string `json:"y_label"` |
| 53 | + AggregateFunction AggregateFunction `json:"aggregate_function"` |
| 54 | +} |
| 55 | + |
| 56 | +// Enum object for AggregateFunction |
| 57 | +type AggregateFunction string |
| 58 | + |
| 59 | +const ( |
| 60 | + AggregateFunctionMin AggregateFunction = "min" |
| 61 | + AggregateFunctionMax AggregateFunction = "max" |
| 62 | + AggregateFunctionAvg AggregateFunction = "avg" |
| 63 | + AggregateFunctionSum AggregateFunction = "sum" |
| 64 | + AggregateFunctionRate AggregateFunction = "rate" |
| 65 | + AggregateFunctionIncrease AggregateFunction = "increase" |
| 66 | + AggregateFunctionCount AggregateFunction = "count" |
| 67 | + AggregateFunctionLast AggregateFunction = "last" |
| 68 | +) |
| 69 | + |
| 70 | +// Enum object for Chart type |
| 71 | +type ChartType string |
| 72 | + |
| 73 | +const ( |
| 74 | + ChartTypeLine ChartType = "line" |
| 75 | + ChartTypeArea ChartType = "area" |
| 76 | +) |
| 77 | + |
| 78 | +// ListMonitorDashboards lists all the ACLP Monitor Dashboards |
| 79 | +func (c *Client) ListMonitorDashboards(ctx context.Context, opts *ListOptions) ([]MonitorDashboard, error) { |
| 80 | + return getPaginatedResults[MonitorDashboard](ctx, c, "monitor/dashboards", opts) |
| 81 | +} |
| 82 | + |
| 83 | +// GetMonitorDashboard gets an ACLP Monitor Dashboard for a given dashboardID |
| 84 | +func (c *Client) GetMonitorDashboard(ctx context.Context, dashboardID int) (*MonitorDashboard, error) { |
| 85 | + e := formatAPIPath("monitor/dashboards/%d", dashboardID) |
| 86 | + return doGETRequest[MonitorDashboard](ctx, c, e) |
| 87 | +} |
| 88 | + |
| 89 | +// ListMonitorDashboardsByServiceType lists ACLP Monitor Dashboards for a given serviceType |
| 90 | +func (c *Client) ListMonitorDashboardsByServiceType(ctx context.Context, serviceType string, opts *ListOptions) ([]MonitorDashboard, error) { |
| 91 | + e := formatAPIPath("monitor/services/%s/dashboards", serviceType) |
| 92 | + return getPaginatedResults[MonitorDashboard](ctx, c, e, opts) |
| 93 | +} |
| 94 | + |
| 95 | +// UnmarshalJSON implements the json.Unmarshaler interface |
| 96 | +func (i *MonitorDashboard) UnmarshalJSON(b []byte) error { |
| 97 | + type Mask MonitorDashboard |
| 98 | + |
| 99 | + p := struct { |
| 100 | + *Mask |
| 101 | + Created *parseabletime.ParseableTime `json:"created"` |
| 102 | + Updated *parseabletime.ParseableTime `json:"updated"` |
| 103 | + }{ |
| 104 | + Mask: (*Mask)(i), |
| 105 | + } |
| 106 | + |
| 107 | + if err := json.Unmarshal(b, &p); err != nil { |
| 108 | + return err |
| 109 | + } |
| 110 | + |
| 111 | + i.Created = (*time.Time)(p.Created) |
| 112 | + i.Updated = (*time.Time)(p.Updated) |
| 113 | + |
| 114 | + return nil |
| 115 | +} |
0 commit comments