Skip to content

Commit ec28325

Browse files
Main: Version 2 API endpoints package for Splunk Observability APIs (#2)
* Version 2 API endpoints package for Splunk Observability APIs (#1) * update the client and models * api checks v2 * browser checks v2 * get checks * get checks * add parts for variables * add httpchecksv2 * port checks * fix testing and move integration tests to own excluded file * fix integration tests * snake_case fixes until the API has been adjusted to camelCase * update models and move integration tests Co-authored-by: jeremyh <[email protected]> * update readme for V2 * only check V2 with new testing standards. V1 is unchanged and deprecated. Co-authored-by: jeremyh <[email protected]>
1 parent 78fa1e1 commit ec28325

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3590
-50
lines changed

.gitignore

+17
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,20 @@
1313

1414
# Dependency directories (remove the comment below to include it)
1515
# vendor/
16+
17+
# VS Code
18+
.vscode/*
19+
!.vscode/settings.json
20+
!.vscode/tasks.json
21+
!.vscode/launch.json
22+
!.vscode/extensions.json
23+
!.vscode/*.code-snippets
24+
25+
# Local History for Visual Studio Code
26+
.history/
27+
28+
# Built Visual Studio Code Extensions
29+
*.vsix
30+
31+
.DS_Store
32+
.vscode/settings.json

Makefile

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
PKG_NAME=syntheticsclient
44
FILES=./...
55

6-
default: test
6+
default: test
77

8-
all: clean build test
8+
all: clean build test
99

1010
build: fmtcheck
11-
go build
11+
go build -tags=unit_tests
1212

1313
clean:
1414
@echo "==> Cleaning out old builds "
@@ -22,17 +22,17 @@ fmt:
2222

2323
lint:
2424
@echo "==> Checking source code against linters "
25-
@GOGC=30 golangci-lint run $(FILES)
25+
@GOGC=30 golangci-lint run ./syntheticsclientv2/...
2626

2727
fmtcheck: fmt lint
2828

2929
test: fmtcheck
3030
@echo "==> Running all tests"
31-
go test $(FILES) -v -timeout=30s -parallel=4 -cover
31+
go test $(FILES) -v -tags=unit_tests -timeout=30s -parallel=4 -cover
3232

3333
testacc: clean fmtcheck
3434
@echo "==> Running all tests"
35-
go test $(FILES) -v -timeout=30s -parallel=8 -cover -coverprofile coverage.txt
35+
go test $(FILES) -v -tags=unit_tests -timeout=30s -parallel=8 -cover -coverprofile coverage.txt
3636

3737
sonarqube: testacc
3838
docker run -it -v "${PWD}:/usr/src" sonarsource/sonar-scanner-cli

README.md

+16-44
Original file line numberDiff line numberDiff line change
@@ -6,72 +6,44 @@ A Splunk Synthetics (Formerly Rigor) client for golang.
66

77
## Important Note
88

9-
This client is used to make the API calls that are mentioned here [Splunk Synthetics (Formerly Rigor) public API](https://monitoring-api.rigor.com/). However, some features are not implemented or publicly available yet.
9+
V2 client is used to make API calls and CRUD operations to the Splunk Observability Synthetics endpoints (E.G. [API Tests](https://dev.splunk.com/observability/reference/api/synthetics_api_tests/))
10+
11+
**Deprecated** V1 Client is used to make the API calls for the [Splunk Synthetics (Formerly Rigor) public API](https://monitoring-api.rigor.com/).
1012

1113
## Example Usages
1214
```go
13-
package syntheticsclient
15+
package main
1416

1517
import (
1618
"fmt"
17-
18-
"https://github.com/splunk/syntheticsclient.git"
19+
"os"
20+
"encoding/json"
21+
sc2 "github.com/splunk/syntheticsclient/syntheticsclientv2"
1922
)
2023

2124
func main() {
2225
//Expects a token is available from the API_ACCESS_TOKEN environment variable
26+
//Expects a realm (e.g. us1) is available from REALM environment variable
2327
token := os.Getenv("API_ACCESS_TOKEN")
28+
realm := os.Getenv("REALM")
2429

2530
//Create your client with the token
26-
c := NewClient(token)
27-
28-
// Initialize your check settings
29-
o := CreateHttpCheck{
30-
Name: "test test",
31-
Frequency: 5,
32-
URL: "https://www.google.com"}
33-
34-
// Make the request with your check settings and print result
35-
res, _, err := c.CreateHttpCheck(&o)
36-
if err != nil {
37-
fmt.Println(err)
38-
} else {
39-
JsonPrint(res)
40-
}
41-
}
42-
```
43-
44-
Another possibility for initializing your interface is to unmarshal a valid JSON string into the needed struct
45-
```go
46-
package syntheticsclient
47-
48-
import (
49-
"fmt"
50-
"encoding/json"
51-
52-
"https://github.com/splunk/syntheticsclient.git"
53-
)
54-
55-
func main() {
56-
57-
token := os.Getenv("API_ACCESS_TOKEN")
58-
59-
c := NewClient(token)
31+
c := sc2.NewClient(token, realm)
6032

61-
//Take your ugly (but valid) JSON string as bytes and unmarshal into a CreateBrowserCheck struct
62-
jsonData := []byte(`{"name":"test","type":"real_browser","frequency":10,"round_robin":true,"auto_retry":false,"enabled":true,"integrations":[],"http_request_headers":{"User-Agent":"Mozilla/5.0 (X11; Linux x86_64; Rigor) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36"},"notifications":{"sms":false,"call":false,"email":true,"notify_after_failure_count":2,"notify_on_location_failure":true,"muted":false,"notify_who":[{"sms":false,"call":false,"email":true,"type":"user","links":{"self_html":"https://monitoring.rigor.com/admin/users/1"},"id":1}],"notification_windows":[],"escalations":[]},"url":"https://www.google.com/","user_agent":"Mozilla/5.0 (X11; Linux x86_64; Rigor) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36","auto_update_user_agent":true,"viewport":{"width":1366,"height":768},"enforce_ssl_validation":true,"browser":{"type":"chrome"},"dns_overrides":{},"wait_for_full_metrics":true,"tags":[],"blackout_periods":[{"timezone":"Eastern Time (US & Canada)","start_time":"2000-01-01T07:00:00.000Z","end_time":"2000-01-01T14:00:00.000Z","repeat_type":"daily","duration_in_minutes":420,"is_repeat":true,"created_at":"2020-11-11T21:54:32.000Z","updated_at":"2021-03-30T19:02:54.000Z"}],"steps":[],"javascript_files":[],"threshold_monitors":[],"excluded_files":[],"cookies":[],"connection":{"download_bandwidth":20000,"upload_bandwidth":5000,"latency":28,"packet_loss":0}}`)
63-
var browserCheckDetail CreateBrowserCheck
64-
err := json.Unmarshal(jsonData, &browserCheckDetail)
33+
//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"}]}}`)
35+
var httpCheckDetail sc2.HttpCheckV2Input
36+
err := json.Unmarshal(jsonData, &httpCheckDetail)
6537
if err != nil {
6638
fmt.Println(err)
6739
}
6840

6941
//Use your converted JSON to make the request and print
70-
res, _, err := c.CreateBrowserCheck(&browserCheckDetail)
42+
res, _, err := c.CreateHttpCheckV2(&httpCheckDetail)
7143
if err != nil {
7244
fmt.Println(err)
7345
} else {
74-
JsonPrint(res)
46+
fmt.Println(res)
7547
}
7648
}
7749
```

0 commit comments

Comments
 (0)