Audit log
| Suitable Enviroment | SaaS |
| Private Deployment |
Requirements
| ONES | @ones-op/node-ability |
|---|---|
| v3.6.0+ | v0.1.9+ |
Overview
The plugin can write the audit log to the ONES. You can see the contents of the audit log on the Configuration -> System security -> Audit Log page.
The operation type of audit log generated by plugin using this ability is Plugin log.
Usage
Step 1:Installing dependencies
Enter the /backend directory of the plugin project, and execute the following command for dependent installation:
npm i @ones-op/node-ability
Step 2:Call the createLog method in the plugin to write the audit log to ONES
The
createLogmethod requires two input parameters, one of which contains the structure of theX-Real-IpandOnes-User-Idfields, as well as the audit information to be recordedmessage.Ones-User-Idis the uuid of the operator,X-Real-Ipis the IP address of the operator.
As shown in the following code, construct a structure auditData with X-Real-Ip and Ones-User-Id as the first input parameter, and take the audit information you want to record message as the second input parameter, and call the createLog method to write to the plugin audit log. It needs the team's unique identifier teamUUID as the third entry.
import { AuditLog } from '@ones-op/node-ability'
export async function testAuditLog(request: PluginRequest): Promise<PluginResponse> {
const auditHeader = {
'Ones-User-Id': 'E6ZqgsSX', //This parameter is user uuid
'X-Real-Ip': '127.0.0.1', //IP address
}
const teamUUID = 'xxx'
const resp = await AuditLog.createLog(auditHeader, 'Test log', teamUUID)
return {
body: {
res: 'audit log',
resp: resp,
},
}
}
The header of request contains all the parameters required by the createLog method, so you can directly use the header of request as a parameter. The operator of the audit diary is the user accessing the interface, and the IP address of the audit log is the IP address of the user accessing the interface, as shown below.
import { AuditLog } from '@ones-op/node-ability'
export async function hello(request: PluginRequest): Promise<PluginResponse> {
const body = request.body || {}
const teamUUID = 'xxx'
await AuditLog.createLog(request.headers, 'Audit log from plugin', teamUUID) //write audit information
return {
body: {
res: 'audit log',
requestBody: body,
},
}
}