-
Notifications
You must be signed in to change notification settings - Fork 57
/
ListLogs.go
43 lines (37 loc) · 1.21 KB
/
ListLogs.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
// Search logs returns "OK" response
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
"github.com/DataDog/datadog-api-client-go/v2/api/datadogV2"
)
func main() {
body := datadogV2.LogsListRequest{
Filter: &datadogV2.LogsQueryFilter{
Query: datadog.PtrString("datadog-agent"),
Indexes: []string{
"main",
},
From: datadog.PtrString("2020-09-17T11:48:36+01:00"),
To: datadog.PtrString("2020-09-17T12:48:36+01:00"),
},
Sort: datadogV2.LOGSSORT_TIMESTAMP_ASCENDING.Ptr(),
Page: &datadogV2.LogsListRequestPage{
Limit: datadog.PtrInt32(5),
},
}
ctx := datadog.NewDefaultContext(context.Background())
configuration := datadog.NewConfiguration()
apiClient := datadog.NewAPIClient(configuration)
api := datadogV2.NewLogsApi(apiClient)
resp, r, err := api.ListLogs(ctx, *datadogV2.NewListLogsOptionalParameters().WithBody(body))
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `LogsApi.ListLogs`: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
responseContent, _ := json.MarshalIndent(resp, "", " ")
fmt.Fprintf(os.Stdout, "Response from `LogsApi.ListLogs`:\n%s\n", responseContent)
}