Search…
Audit
Add audit logging for custom objects using the scripting API.

Static method

record(title, objectId, action, options)

Arguments
  • title { String }
  • objectId { ObjectID }
  • action { String } For example, create, read, update, delete, access, and transfer
  • options { Object } Options object
    • metadata { Object }
    • err {Fault}

Associate audit logs with custom objects

You can associate audit logs with custom objects using a script to add custom property information to the audit logs.
This only applies to user audit events in the subcategories listed below.
create ​ ​​
audit.record('my_object', _id, 'create', {metadata: {message: 'Create custom object'}})​​ ​ ​ ​
read ​ ​​
audit.record('my_object', _id, 'read', {metadata: {message: 'Read custom object'}}) ​​ ​ ​ ​
update
​​audit.record('my_object', _id, 'update', {metadata: {message: 'Update custom object'}})​​ ​ ​ ​
delete
​​audit.record('my_object', _id, 'delete', {metadata: {message: 'Delete custom object'}})​​ ​ ​
access
​​audit.record('my_object', _id, 'access', {metadata: {message: 'Access custom object'}})​​ ​ ​ ​
transfer
​audit.record('my_object', _id, 'transfer', {metadata: {message: 'Transfer custom object'}})​​ ​

Example: Create audit record

1
import audit from 'audit'
2
3
// Create custom object
4
org.objects.objects.insertOne({
5
label: 'My Object',
6
name: 'my_object',
7
defaultAcl: 'owner.delete',
8
createAcl: 'account.public',
9
properties: [
10
{
11
label: 'name',
12
name: 'c_name',
13
type: 'String',
14
indexed: true
15
}
16
]
17
})
18
.execute()
19
20
// Create audit record
21
return audit.record('my_object', org.objects.my_object._id, 'create', {
22
metadata: {
23
message: 'record created'
24
}
25
})
Copied!

Object schema

1
{
2
"ETag": "9984ad7455e8b36d32bc7395ca0148d9",
3
"_id": "436f6e746578742041756474",
4
"allowConnections": false,
5
"auditing": {
6
"all": false,
7
"category": "audit",
8
"changes": false,
9
"enabled": false,
10
"updateSubcategory": "update"
11
},
12
"connectionOptions": {
13
"requireAccept": true,
14
"requiredAccess": 5,
15
"sendNotifications": true
16
},
17
"createAcl": [],
18
"custom": false,
19
"defaultAcl": [],
20
"extended": true,
21
"extensible": false,
22
"feedDefinition": [],
23
"hasETag": false,
24
"isUnmanaged": true,
25
"isVersioned": false,
26
"label": "Audit",
27
"name": "audit",
28
"object": "schema",
29
"pluralName": "audits",
30
"properties": [
31
{
32
"fqpp": "audit._id",
33
"indexed": true,
34
"label": "Id",
35
"name": "_id",
36
"read": 1,
37
"readOnly": true,
38
"type": "ObjectId"
39
},
40
{
41
"fqpp": "audit.object",
42
"indexed": true,
43
"label": "Object",
44
"name": "object",
45
"read": 1,
46
"readOnly": true,
47
"type": "String"
48
},
49
{
50
"fqpp": "audit.access",
51
"label": "Access Level",
52
"name": "access",
53
"read": 1,
54
"readOnly": true,
55
"type": "Number"
56
},
57
{
58
"fqpp": "audit.propertyAccess",
59
"label": "Property Access",
60
"name": "propertyAccess",
61
"optional": true,
62
"read": 1,
63
"readOnly": true,
64
"type": "Document"
65
},
66
{
67
"fqpp": "audit.req",
68
"indexed": true,
69
"label": "Request Id",
70
"name": "req",
71
"read": 4,
72
"readOnly": true,
73
"type": "ObjectId"
74
},
75
{
76
"fqpp": "audit.principal",
77
"indexed": true,
78
"label": "Principal",
79
"name": "principal",
80
"read": 4,
81
"readOnly": true,
82
"type": "ObjectId"
83
},
84
{
85
"fqpp": "audit.ipv4",
86
"indexed": true,
87
"label": "IP Address",
88
"name": "ipv4",
89
"read": 4,
90
"readOnly": true,
91
"type": "Number"
92
},
93
{
94
"fqpp": "audit.cat",
95
"indexed": true,
96
"label": "Category",
97
"name": "cat",
98
"read": 4,
99
"readOnly": true,
100
"type": "String"
101
},
102
{
103
"fqpp": "audit.sub",
104
"indexed": true,
105
"label": "Sub Category",
106
"name": "sub",
107
"read": 4,
108
"readOnly": true,
109
"type": "String"
110
},
111
{
112
"fqpp": "audit.context",
113
"label": "Context",
114
"name": "context",
115
"properties": [
116
{
117
"fqpp": "audit.context.object",
118
"indexed": true,
119
"label": "Object",
120
"name": "object",
121
"read": 4,
122
"readOnly": true,
123
"type": "String"
124
},
125
{
126
"fqpp": "audit.context._id",
127
"indexed": true,
128
"label": "Identifier",
129
"name": "_id",
130
"read": 4,
131
"readOnly": true,
132
"type": "ObjectId"
133
}
134
],
135
"read": 4,
136
"readOnly": true,
137
"type": "Document"
138
},
139
{
140
"fqpp": "audit.ac",
141
"label": "Access Context",
142
"name": "ac",
143
"read": 4,
144
"readOnly": true,
145
"type": "Any"
146
},
147
{
148
"fqpp": "audit.metadata",
149
"label": "Metadata",
150
"name": "metadata",
151
"read": 4,
152
"readOnly": true,
153
"type": "Any"
154
},
155
{
156
"fqpp": "audit.err",
157
"label": "Error",
158
"name": "err",
159
"read": 4,
160
"readOnly": true,
161
"type": "Any"
162
}
163
],
164
"shareAcl": [],
165
"shareChain": [
166
5,
167
2
168
]
169
}
Copied!
Last modified 2mo ago