File: dashboard_list_items_v2.go

package info (click to toggle)
golang-github-zorkian-go-datadog-api 2.30.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,612 kB
  • sloc: makefile: 28; sh: 13
file content (76 lines) | stat: -rw-r--r-- 2,757 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
 * Datadog API for Go
 *
 * Please see the included LICENSE file for licensing information.
 *
 * Copyright 2019 by authors and contributors.
 */

package datadog

import (
	"fmt"
)

// DashboardListItemV2 represents a single dashboard in a dashboard list.
type DashboardListItemV2 struct {
	ID   *string `json:"id,omitempty"`
	Type *string `json:"type,omitempty"`
}

type reqDashboardListItemsV2 struct {
	Dashboards []DashboardListItemV2 `json:"dashboards,omitempty"`
}

type reqAddedDashboardListItemsV2 struct {
	Dashboards []DashboardListItemV2 `json:"added_dashboards_to_list,omitempty"`
}

type reqDeletedDashboardListItemsV2 struct {
	Dashboards []DashboardListItemV2 `json:"deleted_dashboards_from_list,omitempty"`
}

// GetDashboardListItemsV2 fetches the dashboard list's dashboard definitions.
func (client *Client) GetDashboardListItemsV2(id int) ([]DashboardListItemV2, error) {
	var out reqDashboardListItemsV2
	if err := client.doJsonRequest("GET", fmt.Sprintf("/v2/dashboard/lists/manual/%d/dashboards", id), nil, &out); err != nil {
		return nil, err
	}
	return out.Dashboards, nil
}

// AddDashboardListItemsV2 adds dashboards to an existing dashboard list.
//
// Any items already in the list are ignored (not added twice).
func (client *Client) AddDashboardListItemsV2(dashboardListID int, items []DashboardListItemV2) ([]DashboardListItemV2, error) {
	req := reqDashboardListItemsV2{items}
	var out reqAddedDashboardListItemsV2
	if err := client.doJsonRequest("POST", fmt.Sprintf("/v2/dashboard/lists/manual/%d/dashboards", dashboardListID), req, &out); err != nil {
		return nil, err
	}
	return out.Dashboards, nil
}

// UpdateDashboardListItemsV2 updates dashboards of an existing dashboard list.
//
// This will set the list of dashboards to contain only the items in items.
func (client *Client) UpdateDashboardListItemsV2(dashboardListID int, items []DashboardListItemV2) ([]DashboardListItemV2, error) {
	req := reqDashboardListItemsV2{items}
	var out reqDashboardListItemsV2
	if err := client.doJsonRequest("PUT", fmt.Sprintf("/v2/dashboard/lists/manual/%d/dashboards", dashboardListID), req, &out); err != nil {
		return nil, err
	}
	return out.Dashboards, nil
}

// DeleteDashboardListItemsV2 deletes dashboards from an existing dashboard list.
//
// Deletes any dashboards in the list of items from the dashboard list.
func (client *Client) DeleteDashboardListItemsV2(dashboardListID int, items []DashboardListItemV2) ([]DashboardListItemV2, error) {
	req := reqDashboardListItemsV2{items}
	var out reqDeletedDashboardListItemsV2
	if err := client.doJsonRequest("DELETE", fmt.Sprintf("/v2/dashboard/lists/manual/%d/dashboards", dashboardListID), req, &out); err != nil {
		return nil, err
	}
	return out.Dashboards, nil
}