// Search Audit Logs events 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.AuditLogsSearchEventsRequest{
Filter: &datadogV2.AuditLogsQueryFilter{
From: datadog.PtrString("now-15m"),
Query: datadog.PtrString("@type:session AND @session.type:user"),
To: datadog.PtrString("now"),
},
Options: &datadogV2.AuditLogsQueryOptions{
TimeOffset: datadog.PtrInt64(0),
Timezone: datadog.PtrString("GMT"),
},
Page: &datadogV2.AuditLogsQueryPageOptions{
Limit: datadog.PtrInt32(25),
},
Sort: datadogV2.AUDITLOGSSORT_TIMESTAMP_ASCENDING.Ptr(),
}
ctx := datadog.NewDefaultContext(context.Background())
configuration := datadog.NewConfiguration()
apiClient := datadog.NewAPIClient(configuration)
api := datadogV2.NewAuditApi(apiClient)
resp, r, err := api.SearchAuditLogs(ctx, *datadogV2.NewSearchAuditLogsOptionalParameters().WithBody(body))
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `AuditApi.SearchAuditLogs`: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
responseContent, _ := json.MarshalIndent(resp, "", " ")
fmt.Fprintf(os.Stdout, "Response from `AuditApi.SearchAuditLogs`:\n%s\n", responseContent)
}