Skip to content

Commit 937cab4

Browse files
Api Changes and Additions V1.0.1 (#3)
* update to the v2 api endpoints * add variables, locations, devices, etc * get for devices, locations, variables. CRUD for locations. Remove camelcase param * go fmt fixes * locations are immutable so no need to update. * add link to the official API docs in README * update example in README --------- Co-authored-by: jeremyh <[email protected]>
1 parent ec28325 commit 937cab4

15 files changed

+856
-94
lines changed

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func main() {
3131
c := sc2.NewClient(token, realm)
3232

3333
//Take your ugly (but valid) JSON string as bytes and unmarshal into a CreateHttpCheckV2 struct
34-
jsonData := []byte(`{"test":{"name":"Testing-HTTP-stuff","type":"http","url":"https://www.splunk.com","location_ids":["aws-us-east-1","aws-ap-northeast-3"],"frequency":10,"scheduling_strategy":"round_robin","active":true,"request_method":"GET","body":null,"headers":[{"name":"supercool","value":"batman"},{"name":"ajx-back","value":"peeko"}]}}`)
34+
jsonData := []byte(`{"test":{"name":"http-test","type":"http","url":"https://www.splunk.com","locationIds":["aws-us-east-1"],"frequency":10,"schedulingStrategy":"round_robin","active":true,"requestMethod":"GET","body":null,"headers":[{"name":"boop","value":"beep"}]}}`)
3535
var httpCheckDetail sc2.HttpCheckV2Input
3636
err := json.Unmarshal(jsonData, &httpCheckDetail)
3737
if err != nil {
@@ -48,5 +48,8 @@ func main() {
4848
}
4949
```
5050

51+
## API Documentation
52+
API Docs are [available here](https://dev.splunk.com/observability/reference)
53+
5154
## Additional Information
5255
This client is largely a copypasta mutation of the [go-victor](https://github.com/victorops/go-victorops) client for Splunk On-Call (formerly known as VictorOps).

syntheticsclientv2/common_models.go

+96-73
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ import (
2121
// Common and shared struct models used for more complex requests
2222
type Networkconnection struct {
2323
Description string `json:"description,omitempty"`
24-
Downloadbandwidth int `json:"download_bandwidth,omitempty"`
24+
Downloadbandwidth int `json:"downloadBandwidth,omitempty"`
2525
Latency int `json:"latency,omitempty"`
26-
Packetloss int `json:"packet_loss,omitempty"`
27-
Uploadbandwidth int `json:"upload_bandwidth,omitempty"`
26+
Packetloss int `json:"packetLoss,omitempty"`
27+
Uploadbandwidth int `json:"uploadBandwidth,omitempty"`
2828
}
2929

3030
type Advancedsettings struct {
3131
Authentication `json:"authentication"`
3232
Cookiesv2 []Cookiesv2 `json:"cookies"`
3333
BrowserHeaders []BrowserHeaders `json:"headers,omitempty"`
34-
HostOverrides []HostOverrides `json:"host_overrides,omitempty"`
35-
UserAgent string `json:"user_agent,omitempty"`
34+
HostOverrides []HostOverrides `json:"hostOverrides,omitempty"`
35+
UserAgent string `json:"userAgent,omitempty"`
3636
Verifycertificates bool `json:"verifyCertificates,omitempty"`
3737
}
3838

@@ -57,7 +57,7 @@ type BrowserHeaders struct {
5757
type HostOverrides struct {
5858
Source string `json:"source"`
5959
Target string `json:"target"`
60-
KeepHostHeader bool `json:"keep_host_header"`
60+
KeepHostHeader bool `json:"keepHostHeader"`
6161
}
6262

6363
type Transactions struct {
@@ -75,19 +75,8 @@ type StepsV2 struct {
7575
Type string `json:"type"`
7676
URL string `json:"url,omitempty"`
7777
Action string `json:"action,omitempty"`
78-
WaitForNav bool `json:"wait_for_nav"`
79-
SelectorType string `json:"selector_type,omitempty"`
80-
Selector string `json:"selector,omitempty"`
81-
Options `json:"options,omitempty"`
82-
}
83-
84-
type BusinessTransactionStepsV2 struct {
85-
Name string `json:"name"`
86-
Type string `json:"type"`
87-
URL string `json:"url,omitempty"`
88-
Action string `json:"action,omitempty"`
89-
WaitForNav bool `json:"wait_for_nav"`
90-
SelectorType string `json:"selector_type,omitempty"`
78+
WaitForNav bool `json:"waitForNav"`
79+
SelectorType string `json:"selectorType,omitempty"`
9180
Selector string `json:"selector,omitempty"`
9281
Options `json:"options,omitempty"`
9382
}
@@ -99,10 +88,10 @@ type Options struct {
9988
type Device struct {
10089
ID int `json:"id,omitempty"`
10190
Label string `json:"label,omitempty"`
102-
UserAgent string `json:"user_agent,omitempty"`
103-
Networkconnection `json:"network_connection,omitempty"`
104-
Viewportheight int `json:"viewport_height"`
105-
Viewportwidth int `json:"viewport_width"`
91+
UserAgent string `json:"userAgent,omitempty"`
92+
Networkconnection `json:"networkConnection,omitempty"`
93+
Viewportheight int `json:"viewportHeight"`
94+
Viewportwidth int `json:"viewportWidth"`
10695
}
10796

10897
type Requests struct {
@@ -115,7 +104,7 @@ type Configuration struct {
115104
Body string `json:"body"`
116105
Headers `json:"headers,omitempty"`
117106
Name string `json:"name,omitempty"`
118-
Requestmethod string `json:"requestMethod,omitempty"`
107+
RequestMethod string `json:"requestMethod,omitempty"`
119108
URL string `json:"url,omitempty"`
120109
}
121110

@@ -139,14 +128,14 @@ type Validations struct {
139128

140129
type Tests []struct {
141130
Active bool `json:"active"`
142-
Createdat time.Time `json:"created_at"`
131+
Createdat time.Time `json:"createdAt"`
143132
Frequency int `json:"frequency"`
144133
ID int `json:"id"`
145134
Locationids []string `json:"locationIds"`
146135
Name string `json:"name"`
147-
Schedulingstrategy string `json:"scheduling_strategy"`
136+
Schedulingstrategy string `json:"schedulingStrategy"`
148137
Type string `json:"type"`
149-
Updatedat time.Time `json:"updated_at"`
138+
Updatedat time.Time `json:"updatedAt"`
150139
}
151140

152141
type GetChecksV2Options struct {
@@ -168,12 +157,12 @@ type HttpHeaders struct {
168157
}
169158

170159
type Variable struct {
171-
Createdat time.Time `json:"created_at,omitempty"`
160+
Createdat time.Time `json:"createdAt,omitempty"`
172161
Description string `json:"description,omitempty"`
173162
ID int `json:"id,omitempty"`
174163
Name string `json:"name"`
175164
Secret bool `json:"secret"`
176-
Updatedat time.Time `json:"updated_at,omitempty"`
165+
Updatedat time.Time `json:"updatedAt,omitempty"`
177166
Value string `json:"value"`
178167
}
179168

@@ -183,6 +172,23 @@ type DeleteCheck struct {
183172
Errors Errors `json:"errors"`
184173
}
185174

175+
type Location struct {
176+
ID string `json:"id"`
177+
Label string `json:"label"`
178+
Default bool `json:"default"`
179+
Type string `json:"type,omitempty"`
180+
Country string `json:"country,omitempty"`
181+
}
182+
183+
type Meta struct {
184+
ActiveTestIds []int `json:"activeTestIds"`
185+
PausedTestIds []int `json:"pausedTestIds"`
186+
}
187+
188+
type DevicesV2Response struct {
189+
Devices []Device `json:"devices"`
190+
}
191+
186192
type VariableV2Response struct {
187193
Variable `json:"variable"`
188194
}
@@ -191,6 +197,24 @@ type VariableV2Input struct {
191197
Variable `json:"variable"`
192198
}
193199

200+
type VariablesV2Response struct {
201+
Variable []Variable `json:"variables"`
202+
}
203+
204+
type LocationsV2Response struct {
205+
Location []Location `json:"locations"`
206+
DefaultLocationIds []string `json:"defaultLocationIds"`
207+
}
208+
209+
type LocationV2Response struct {
210+
Location `json:"location"`
211+
Meta `json:"meta"`
212+
}
213+
214+
type LocationV2Input struct {
215+
Location `json:"location"`
216+
}
217+
194218
type ChecksV2Response struct {
195219
Nextpagelink int `json:"nextPageLink"`
196220
Perpage int `json:"perPage"`
@@ -204,10 +228,10 @@ type PortCheckV2Response struct {
204228
Name string `json:"name"`
205229
Active bool `json:"active"`
206230
Frequency int `json:"frequency"`
207-
SchedulingStrategy string `json:"scheduling_strategy"`
208-
CreatedAt time.Time `json:"created_at"`
209-
UpdatedAt time.Time `json:"updated_at"`
210-
LocationIds []string `json:"location_ids"`
231+
SchedulingStrategy string `json:"schedulingStrategy"`
232+
CreatedAt time.Time `json:"createdAt"`
233+
UpdatedAt time.Time `json:"updatedAt"`
234+
LocationIds []string `json:"locationIds"`
211235
Type string `json:"type"`
212236
Protocol string `json:"protocol"`
213237
Host string `json:"host"`
@@ -223,9 +247,9 @@ type PortCheckV2Input struct {
223247
Port int `json:"port"`
224248
Protocol string `json:"protocol"`
225249
Host string `json:"host"`
226-
LocationIds []string `json:"location_ids"`
250+
LocationIds []string `json:"locationIds"`
227251
Frequency int `json:"frequency"`
228-
SchedulingStrategy string `json:"scheduling_strategy"`
252+
SchedulingStrategy string `json:"schedulingStrategy"`
229253
Active bool `json:"active"`
230254
} `json:"test"`
231255
}
@@ -236,13 +260,13 @@ type HttpCheckV2Response struct {
236260
Name string `json:"name"`
237261
Active bool `json:"active"`
238262
Frequency int `json:"frequency"`
239-
SchedulingStrategy string `json:"scheduling_strategy"`
240-
CreatedAt time.Time `json:"created_at,omitempty"`
241-
UpdatedAt time.Time `json:"updated_at,omitempty"`
242-
LocationIds []string `json:"location_ids"`
263+
SchedulingStrategy string `json:"schedulingStrategy"`
264+
CreatedAt time.Time `json:"createdAt,omitempty"`
265+
UpdatedAt time.Time `json:"updatedAt,omitempty"`
266+
LocationIds []string `json:"locationIds"`
243267
Type string `json:"type"`
244268
URL string `json:"url"`
245-
RequestMethod string `json:"request_method"`
269+
RequestMethod string `json:"requestMethod"`
246270
Body string `json:"body,omitempty"`
247271
HttpHeaders []HttpHeaders `json:"headers,omitempty"`
248272
} `json:"test"`
@@ -253,11 +277,11 @@ type HttpCheckV2Input struct {
253277
Name string `json:"name"`
254278
Type string `json:"type"`
255279
URL string `json:"url"`
256-
LocationIds []string `json:"location_ids"`
280+
LocationIds []string `json:"locationIds"`
257281
Frequency int `json:"frequency"`
258-
SchedulingStrategy string `json:"scheduling_strategy"`
282+
SchedulingStrategy string `json:"schedulingStrategy"`
259283
Active bool `json:"active"`
260-
RequestMethod string `json:"request_method"`
284+
RequestMethod string `json:"requestMethod"`
261285
Body string `json:"body,omitempty"`
262286
HttpHeaders []HttpHeaders `json:"headers,omitempty"`
263287
} `json:"test"`
@@ -266,60 +290,59 @@ type HttpCheckV2Input struct {
266290
type ApiCheckV2Input struct {
267291
Test struct {
268292
Active bool `json:"active"`
269-
Deviceid int `json:"device_id"`
293+
Deviceid int `json:"deviceId"`
270294
Frequency int `json:"frequency"`
271-
Locationids []string `json:"location_ids"`
295+
Locationids []string `json:"locationIds"`
272296
Name string `json:"name"`
273297
Requests []Requests `json:"requests"`
274-
Schedulingstrategy string `json:"scheduling_strategy"`
298+
Schedulingstrategy string `json:"schedulingStrategy"`
275299
} `json:"test"`
276300
}
277301

278302
type ApiCheckV2Response struct {
279303
Test struct {
280304
Active bool `json:"active,omitempty"`
281-
Createdat time.Time `json:"created_at"`
305+
Createdat time.Time `json:"createdAt"`
282306
Device `json:"device,omitempty"`
283307
Frequency int `json:"frequency,omitempty"`
284308
ID int `json:"id,omitempty"`
285-
Locationids []string `json:"location_ids,omitempty"`
309+
Locationids []string `json:"locationIds,omitempty"`
286310
Name string `json:"name,omitempty"`
287311
Requests []Requests `json:"requests,omitempty"`
288-
Schedulingstrategy string `json:"scheduling_strategy,omitempty"`
312+
Schedulingstrategy string `json:"schedulingStrategy,omitempty"`
289313
Type string `json:"type,omitempty"`
290-
Updatedat time.Time `json:"updated_at,omitempty"`
314+
Updatedat time.Time `json:"updatedAt,omitempty"`
291315
}
292316
}
293317

294318
type BrowserCheckV2Input struct {
295319
Test struct {
296-
Name string `json:"name"`
297-
BusinessTransactions []BusinessTransactions `json:"business_transactions"`
298-
Urlprotocol string `json:"urlProtocol"`
299-
Starturl string `json:"startUrl"`
300-
LocationIds []string `json:"location_ids"`
301-
DeviceID int `json:"device_id"`
302-
Frequency int `json:"frequency"`
303-
Schedulingstrategy string `json:"scheduling_strategy"`
304-
Active bool `json:"active"`
305-
Advancedsettings `json:"advanced_settings"`
320+
Name string `json:"name"`
321+
Transactions []Transactions `json:"transactions"`
322+
Urlprotocol string `json:"urlProtocol"`
323+
Starturl string `json:"startUrl"`
324+
LocationIds []string `json:"locationIds"`
325+
DeviceID int `json:"deviceId"`
326+
Frequency int `json:"frequency"`
327+
Schedulingstrategy string `json:"schedulingStrategy"`
328+
Active bool `json:"active"`
329+
Advancedsettings `json:"advancedSettings"`
306330
} `json:"test"`
307331
}
308332

309333
type BrowserCheckV2Response struct {
310334
Test struct {
311-
Active bool `json:"active"`
312-
Advancedsettings `json:"advanced_settings"`
313-
BusinessTransactions []BusinessTransactions `json:"business_transactions"`
314-
Createdat time.Time `json:"created_at"`
315-
Device `json:"device"`
316-
Frequency int `json:"frequency"`
317-
ID int `json:"id"`
318-
Locationids []string `json:"location_ids"`
319-
Name string `json:"name"`
320-
Schedulingstrategy string `json:"scheduling_strategy"`
321-
Transactions []Transactions `json:"transactions"`
322-
Type string `json:"type"`
323-
Updatedat time.Time `json:"updated_at"`
335+
Active bool `json:"active"`
336+
Advancedsettings `json:"advancedSettings"`
337+
Createdat time.Time `json:"createdAt"`
338+
Device `json:"device"`
339+
Frequency int `json:"frequency"`
340+
ID int `json:"id"`
341+
Locationids []string `json:"locationIds"`
342+
Name string `json:"name"`
343+
Schedulingstrategy string `json:"schedulingStrategy"`
344+
Transactions []Transactions `json:"transactions"`
345+
Type string `json:"type"`
346+
Updatedat time.Time `json:"updatedAt"`
324347
} `json:"test"`
325348
}

syntheticsclientv2/create_browsercheckv2_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
)
2727

2828
var (
29-
createBrowserCheckV2Body = `{"test":{"name":"browser-beep-test","business_transactions":[{"name":"Synthetic transaction 1","steps":[{"name":"Go to URL","type":"go_to_url","url":"https://www.splunk.com","action":"go_to_url","wait_for_nav":true},{"name":"Nexter step","type":"click_element","selector_type":"id","wait_for_nav":false,"selector":"free-splunk-click-desktop"}]}],"urlProtocol":"https://","startUrl":"www.splunk.com","location_ids":["aws-us-east-1"],"device_id":1,"frequency":5,"scheduling_strategy":"round_robin","active":true,"advanced_settings":{"verify_certificates":true,"authentication":{"username":"boopuser","password":"{{env.beep-var}}"},"headers":[{"name":"batman","value":"Agentoz","domain":"www.batmansagent.com"}],"cookies":[{"key":"super","value":"duper","domain":"www.batmansagent.com","path":"/boom/goes/beep"}]}}}`
29+
createBrowserCheckV2Body = `{"test":{"name":"browser-beep-test","transactions":[{"name":"Synthetic transaction 1","steps":[{"name":"Go to URL","type":"go_to_url","url":"https://www.splunk.com","action":"go_to_url","wait_for_nav":true},{"name":"Nexter step","type":"click_element","selectorType":"id","wait_for_nav":false,"selector":"free-splunk-click-desktop"}]}],"urlProtocol":"https://","startUrl":"www.splunk.com","locationIds":["aws-us-east-1"],"deviceId":1,"frequency":5,"schedulingStrategy":"round_robin","active":true,"advancedSettings":{"verifyCertificates":true,"authentication":{"username":"boopuser","password":"{{env.beep-var}}"},"headers":[{"name":"batman","value":"Agentoz","domain":"www.batmansagent.com"}],"cookies":[{"key":"super","value":"duper","domain":"www.batmansagent.com","path":"/boom/goes/beep"}]}}}`
3030
inputBrowserCheckV2Data = BrowserCheckV2Input{}
3131
)
3232

@@ -71,8 +71,8 @@ func TestCreateBrowserCheckV2(t *testing.T) {
7171
t.Errorf("returned \n\n%#v want \n\n%#v", resp.Test.Frequency, inputBrowserCheckV2Data.Test.Frequency)
7272
}
7373

74-
if !reflect.DeepEqual(resp.Test.BusinessTransactions, inputBrowserCheckV2Data.Test.BusinessTransactions) {
75-
t.Errorf("returned \n\n%#v want \n\n%#v", resp.Test.BusinessTransactions, inputBrowserCheckV2Data.Test.BusinessTransactions)
74+
if !reflect.DeepEqual(resp.Test.Transactions, inputBrowserCheckV2Data.Test.Transactions) {
75+
t.Errorf("returned \n\n%#v want \n\n%#v", resp.Test.Transactions, inputBrowserCheckV2Data.Test.Transactions)
7676
}
7777

7878
if !reflect.DeepEqual(resp.Test.Advancedsettings, inputBrowserCheckV2Data.Test.Advancedsettings) {

0 commit comments

Comments
 (0)