-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlog_source_extension.go
190 lines (155 loc) · 5.06 KB
/
log_source_extension.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package qradar
import (
"bytes"
"context"
"fmt"
"mime/multipart"
"net/http"
"strings"
)
// LogSourceExtensionService handles methods related to Log Source Extensions of the QRadar Undocumented API.
type LogSourceExtensionService service
const (
logSourceExtensionAPIPrefix = "api/config/event_sources/log_source_extensions"
)
// LogSourceExtension represents QRadar's Log Source Extension.
type LogSourceExtension struct {
ID *int `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
UseCondition *int `json:"use_condition,omitempty"`
XML *string `json:"xml,omitempty"`
}
// Get returns Log Source Extension of the current QRadar installation. Undocumented API.
func (c *LogSourceExtensionService) Get(ctx context.Context, fields, filter string, from, to int) ([]LogSourceExtension, error) {
req, err := c.client.requestHelp(http.MethodGet, logSourceExtensionAPIPrefix, fields, filter, from, to, nil, nil)
if err != nil {
return nil, err
}
req.Header.Set("Allow-Hidden", "true")
var result []LogSourceExtension
_, err = c.client.Do(ctx, req, &result)
if err != nil {
return nil, err
}
return result, nil
}
// todo: add support of multipart uploading
// Create creates Log Source Extension in the current QRadar installation. Undocumented API.
func (c *LogSourceExtensionService) Create(ctx context.Context, fields string, data interface{}) (*LogSourceExtension, error) {
req, err := c.client.requestHelp(http.MethodPost, logSourceExtensionAPIPrefix, fields, "", 0, 0, nil, data)
if err != nil {
return nil, err
}
var b bytes.Buffer
w := multipart.NewWriter(&b)
defer w.Close()
req.Header.Set("Allow-Hidden", "true")
// req.Header.Set("Content-Type", w.FormDataContentType()) //
req.Header.Set("Content-Type", "multipart/form-data")
var result LogSourceExtension
_, err = c.client.Do(ctx, req, &result)
if err != nil {
return nil, err
}
return &result, nil
}
// GetByID returns Log Source Extension of the current QRadar installation by ID. Undocumented API.
func (c *LogSourceExtensionService) GetByID(ctx context.Context, fields string, id int) (*LogSourceExtension, error) {
req, err := c.client.requestHelp(http.MethodGet, logSourceExtensionAPIPrefix, fields, "", 0, 0, &id, nil)
if err != nil {
return nil, err
}
req.Header.Set("Allow-Hidden", "true")
var result LogSourceExtension
_, err = c.client.Do(ctx, req, &result)
if err != nil {
return nil, err
}
return &result, nil
}
// todo: add support of multipart uploading
/*
// UpdateByID updates Log Source Extension of the current QRadar installation by ID. Undocumented API.
func (c *LogSourceExtensionService) UpdateByID(ctx context.Context, fields string, id int, data interface{}) (*LogSourceExtension, error) {
req, err := c.client.requestHelp(http.MethodPost, logSourceExtensionAPIPrefix, fields, "", 0, 0, &id, data)
if err != nil {
return nil, err
}
req.Header.Set("Allow-Hidden", "true")
var result LogSourceExtension
_, err = c.client.Do(ctx, req, &result)
if err != nil {
return nil, err
}
return &result, nil
}
*/
// GetByName returns Log Source Extension of the current QRadar installation by Name. Undocumented API.
func (c *LogSourceExtensionService) GetByName(ctx context.Context, fields string, name string) (*LogSourceExtension, error) {
req, err := c.client.requestHelp(http.MethodGet, logSourceExtensionAPIPrefix, fields, fmt.Sprintf("name=\"%s\"", name), 0, 0, nil, nil)
if err != nil {
return nil, err
}
req.Header.Set("Allow-Hidden", "true")
var result []LogSourceExtension
_, err = c.client.Do(ctx, req, &result)
if err != nil {
return nil, err
}
if len(result) == 0 {
return nil, nil
} else if len(result) > 1 {
return nil, fmt.Errorf("found more log_source_extensions than expected - %d", len(result))
}
return &result[0], nil
}
func (c *Client) customRequest(method, urlStr, fields, filter string, id *int, body interface{}) (*http.Request, error) {
if id != nil {
urlStr = fmt.Sprintf("%s/%d", urlStr, *id)
}
if !strings.HasSuffix(c.BaseURL.Path, "/") {
return nil, fmt.Errorf("BaseURL must have a trailing slash, but %q does not", c.BaseURL)
}
u, err := c.BaseURL.Parse(urlStr)
if err != nil {
return nil, err
}
var b bytes.Buffer
w := multipart.NewWriter(&b)
//io.Closer
w.CreateFormFile("file", b.String())
w.Close()
//var buf io.ReadWriter
if body != nil {
}
req, err := http.NewRequest(method, u.String(), &b)
if err != nil {
return nil, err
}
// req.Header.Set("Accept", "application/json")
if c.APIv == "" {
req.Header.Set("Version", defaultAPIVersion)
} else {
req.Header.Set("Version", c.APIv)
}
//if buf != nil {
// req.Header.Set("Content-Type", "application/json")
//}
if c.SECKey != "" {
req.Header.Set("SEC", c.SECKey)
}
if c.UserAgent != "" {
req.Header.Set("User-Agent", c.UserAgent)
}
q := req.URL.Query()
if fields != "" {
q.Add("fields", fields)
}
if filter != "" {
q.Add("filter", filter)
}
req.URL.RawQuery = q.Encode()
return req, nil
}