forked from thathaneydude/go-tenable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathio-audit-logs.go
70 lines (61 loc) · 1.63 KB
/
io-audit-logs.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
70
package go_tenable
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"time"
)
func (io *TenableIO) ListEvents(filter EventFilter) ([]Event, error) {
var GetParams string
if filter != (EventFilter{}) {
filterString := fmt.Sprintf("%v.%v:%v", filter.Filter, filter.Operator, filter.Value)
GetParams = fmt.Sprintf("f=%v", filterString)
} else {
GetParams = ""
}
resp, err := io.Get("audit-log/v1/events", GetParams)
if err != nil {
log.Printf("Unable to request audit log events: %v\n", err)
return nil, err
}
ResponseBytes, _ := ioutil.ReadAll(resp.Body)
var Logs AuditLogResponse
// Unmarshal API response to AuditLogResponse struct
responseError := json.Unmarshal(ResponseBytes, &Logs)
if responseError != nil {
log.Printf("Unable to unmarshal Audit Log Response: %v\n", responseError)
}
return Logs.Events, nil
}
type EventFilter struct {
Filter string
Operator string
Value string
}
type Event struct {
ID string `json:"id"`
Action string `json:"action"`
Crud string `json:"crud"`
IsFailure bool `json:"is_failure"`
Received time.Time `json:"received"`
Description interface{} `json:"description"`
Actor struct {
ID string `json:"id"`
Name string `json:"name"`
} `json:"actor"`
IsAnonymous interface{} `json:"is_anonymous"`
Target struct {
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
} `json:"target"`
Fields []interface{} `json:"fields"`
}
type AuditLogResponse struct {
Events []Event `json:"events"`
Pagination struct {
Total int `json:"total"`
Limit int `json:"limit"`
} `json:"pagination"`
}