-
Notifications
You must be signed in to change notification settings - Fork 3
/
discoverAPI.go
69 lines (58 loc) · 1.7 KB
/
discoverAPI.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
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"strconv"
"github.com/getsentry/sentry-go"
)
type DiscoverAPI struct {
Data []EventMetadata
endpoint string
}
type EventMetadata struct {
Id string
Project string
Platform string
}
// Events from last 24HrPeriod events for selected Projects
// Returns event metadata (e.g. Id, Project) but not the entire Event itself, which gets queried separately.
// n of 200 may not work
func (d DiscoverAPI) latestEventMetadata(org string, n int) []EventMetadata {
query := makeQuery(platforms)
endpoint := fmt.Sprintf("https://sentry.io/api/0/organizations/%v/eventsv2/?statsPeriod=24h&field=event.type&field=project&field=platform&per_page=%v&query=%v", org, strconv.Itoa(n), query)
request, _ := http.NewRequest("GET", endpoint, nil)
request.Header.Set("content-type", "application/json")
request.Header.Set("Authorization", fmt.Sprint("Bearer ", config.SentryAuthToken))
var httpClient = &http.Client{}
response, err := httpClient.Do(request)
if err != nil {
sentry.CaptureException(err)
log.Fatal(err)
}
body, errResponse := ioutil.ReadAll(response.Body)
if errResponse != nil {
sentry.CaptureException(errResponse)
log.Fatal(errResponse)
}
json.Unmarshal(body, &d)
fmt.Printf("> %v Discover.Data length: %v\n", org, len(d.Data))
for _, e := range d.Data {
fmt.Printf("> %v %v\n", org, e.Project)
}
return d.Data
}
func makeQuery(supportedPlatforms []string) string {
var result string
for _, platform := range supportedPlatforms {
result += "platform.name%3A" + platform + "+OR+"
}
// slices the final "+OR+" off
return result[:len(result)-4]
}
// EVAL chaining
// func (d DiscoverAPI) execute() {
//
// }