-
Notifications
You must be signed in to change notification settings - Fork 4
/
rule_with_data.go
135 lines (113 loc) · 3.95 KB
/
rule_with_data.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package qradar
import (
"context"
"fmt"
"net/http"
)
// RuleWithDataService handles methods related to RuleWithData of the QRadar Undocumented API.
type RuleWithDataService service
const ruleWithDataAPIPrefix = "api/analytics/rules_with_data"
// RuleWithData represents QRadar's RuleWithData. Undocumented.
type RuleWithData struct {
Rule
CRE *int `json:"cre,omitempty"`
TypeID *int `json:"type_id,omitempty"`
IsBuildingBlock *bool `json:"is_building_block,omitempty"`
RuleXML *string `json:"rule_xml,omitempty"`
}
// Get returns RuleWithData of the current QRadar installation. Undocumented API.
func (c *RuleWithDataService) Get(ctx context.Context, fields, filter string, from, to int) ([]RuleWithData, error) {
req, err := c.client.requestHelp(http.MethodGet, ruleWithDataAPIPrefix, fields, filter, from, to, nil, nil)
if err != nil {
return nil, err
}
req.Header.Set("Allow-Hidden", "true")
var result []RuleWithData
_, err = c.client.Do(ctx, req, &result)
if err != nil {
return nil, err
}
return result, nil
}
// Create creates RuleWithData in the current QRadar installation. Undocumented API.
func (c *RuleWithDataService) Create(ctx context.Context, fields string, data interface{}) (*RuleWithData, error) {
req, err := c.client.requestHelp(http.MethodPost, ruleWithDataAPIPrefix, fields, "", 0, 0, nil, data)
if err != nil {
return nil, err
}
req.Header.Set("Allow-Hidden", "true")
var result RuleWithData
_, err = c.client.Do(ctx, req, &result)
if err != nil {
return nil, err
}
return &result, nil
}
// GetByID returns RuleWithData of the current QRadar installation by ID. Undocumented API.
func (c *RuleWithDataService) GetByID(ctx context.Context, fields string, id int) (*RuleWithData, error) {
req, err := c.client.requestHelp(http.MethodGet, ruleWithDataAPIPrefix, fields, "", 0, 0, &id, nil)
if err != nil {
return nil, err
}
req.Header.Set("Allow-Hidden", "true")
var result RuleWithData
_, err = c.client.Do(ctx, req, &result)
if err != nil {
return nil, err
}
return &result, nil
}
// UpdateByID updates RuleWithData of the current QRadar installation by ID. Undocumented API.
func (c *RuleWithDataService) UpdateByID(ctx context.Context, fields string, id int, data interface{}) (*RuleWithData, error) {
req, err := c.client.requestHelp(http.MethodPost, ruleWithDataAPIPrefix, fields, "", 0, 0, &id, data)
if err != nil {
return nil, err
}
req.Header.Set("Allow-Hidden", "true")
var result RuleWithData
_, err = c.client.Do(ctx, req, &result)
if err != nil {
return nil, err
}
return &result, nil
}
// GetByName returns RuleWithData of the current QRadar installation by Name. Undocumented API.
func (c *RuleWithDataService) GetByName(ctx context.Context, fields string, name string) (*RuleWithData, error) {
req, err := c.client.requestHelp(http.MethodGet, ruleWithDataAPIPrefix, fields, fmt.Sprintf("name=\"%s\"", name), 0, 0, nil, nil)
if err != nil {
return nil, err
}
req.Header.Set("Allow-Hidden", "true")
var result []RuleWithData
_, err = c.client.Do(ctx, req, &result)
if err != nil {
return nil, err
}
if len(result) == 0 {
return nil, nil
}
if len(result) > 1 {
return nil, fmt.Errorf("found more rules than expected - %d", len(result))
}
return &result[0], nil
}
// GetByUUID returns RuleWithData of the current QRadar installation by UUID. Undocumented API.
func (c *RuleWithDataService) GetByUUID(ctx context.Context, fields string, uuid string) (*RuleWithData, error) {
req, err := c.client.requestHelp(http.MethodGet, ruleWithDataAPIPrefix, fields, fmt.Sprintf("identifier=\"%s\"", uuid), 0, 0, nil, nil)
if err != nil {
return nil, err
}
req.Header.Set("Allow-Hidden", "true")
var result []RuleWithData
_, err = c.client.Do(ctx, req, &result)
if err != nil {
return nil, err
}
if len(result) == 0 {
return nil, nil
}
if len(result) > 1 {
return nil, fmt.Errorf("found more rules than expected - %d", len(result))
}
return &result[0], nil
}