-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuilding_block.go
85 lines (77 loc) · 2.99 KB
/
building_block.go
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
77
78
79
80
81
82
83
84
85
package qradar
import (
"context"
"net/http"
)
// BuildingBlockService handles methods related to BuildingBlock of the QRadar API.
type BuildingBlockService service
const buildingBlockAPIPrefix = "api/analytics/building_blocks"
// BuildingBlock represents QRadar's BuildingBlock.
type BuildingBlock struct {
ID *int `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
BuildingBlockType *string `json:"building_block_type,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
Owner *string `json:"owner,omitempty"`
Origin *string `json:"origin,omitempty"`
BaseCapacity *int `json:"base_capacity,omitempty"`
BaseHostID *int `json:"base_host_id,omitempty"`
AverageCapacity *int `json:"average_capacity,omitempty"`
CapacityTimestamp *int `json:"capacity_timestamp,omitempty"`
Identifier *string `json:"identifier,omitempty"`
LinkedRuleIdentifier *string `json:"linked_rule_identifier,omitempty"`
CreationDate *int `json:"creation_date,omitempty"`
ModificationDate *int `json:"modification_date,omitempty"`
}
// Get returns BuildingBlocks of the current QRadar installation
func (c *BuildingBlockService) Get(ctx context.Context, fields, filter string, from, to int) ([]BuildingBlock, error) {
req, err := c.client.requestHelp(http.MethodGet, buildingBlockAPIPrefix, fields, filter, from, to, nil, nil)
if err != nil {
return nil, err
}
var result []BuildingBlock
_, err = c.client.Do(ctx, req, &result)
if err != nil {
return nil, err
}
return result, nil
}
// GetByID returns BuildingBlock of the current QRadar installation by ID.
func (c *BuildingBlockService) GetByID(ctx context.Context, fields string, id int) (*BuildingBlock, error) {
req, err := c.client.requestHelp(http.MethodGet, buildingBlockAPIPrefix, fields, "", 0, 0, &id, nil)
if err != nil {
return nil, err
}
var result BuildingBlock
_, err = c.client.Do(ctx, req, &result)
if err != nil {
return nil, err
}
return &result, nil
}
// UpdateByID updates only the BuildingBlock owner or enabled/disabled by ID.
func (c *BuildingBlockService) UpdateByID(ctx context.Context, fields string, id int, data interface{}) (*BuildingBlock, error) {
req, err := c.client.requestHelp(http.MethodPost, buildingBlockAPIPrefix, fields, "", 0, 0, &id, data)
if err != nil {
return nil, err
}
var result BuildingBlock
_, err = c.client.Do(ctx, req, &result)
if err != nil {
return nil, err
}
return &result, nil
}
// DeleteByID creates A Delete Task in QRadar installation in order to safely delete BuildingBlock by ID.
func (c *BuildingBlockService) DeleteByID(ctx context.Context, fields string, id int) (*DeleteTask, error) {
req, err := c.client.requestHelp(http.MethodDelete, buildingBlockAPIPrefix, fields, "", 0, 0, &id, nil)
if err != nil {
return nil, err
}
var result DeleteTask
_, err = c.client.Do(ctx, req, &result)
if err != nil {
return nil, err
}
return &result, nil
}