定义
getAuditConfig版本 5.0 中的新增功能。
getAuditConfigis an administrative command that retrieves audit configurations frommongodandmongosserver instances.
兼容性
此命令可用于以下环境中托管的部署:
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
重要
MongoDB Atlas 集群不支持此命令。有关 Atlas 对所有命令的支持的信息,请参阅不支持的命令。
语法
该命令具有以下语法:
db.adminCommand( { getAuditConfig: 1 } )
行为
Auditing must be enabled to use getAuditConfig.
未参与运行时审核配置的节点将返回其auditLog.filter和setParameter.auditAuthorizationSuccess的当前配置文件设置。
Nodes that are participating in the runtime audit synthesize their current configuration from memory. Configuration updates are distributed via the oplog mechanism which means updates on mongod nodes are distributed to secondary nodes very quickly. However, the distribution mechanism is different on mongos nodes. mongos nodes have to poll the primary server at regular intervals for configuration updates. You may see stale data due to polling delay if you run setAuditConfig on the primary server and getAuditConfig on a shard before the shard has polled the primary server for updated configuration details.
注意
如果您正在编写自动审核脚本,请注意,mongosh 和旧版 mongo shell之间用于表示集群签名的引号样式和类型有所不同。 在mongosh中,类型为 Binary 和 Long。 传统 shell 中的对应类型是 BinData 和 NumberLong。
// mongosh signature: { hash: Binary(Buffer.from("0000000000000000000000000000000000000000", "hex"), 0), keyId: Long("0") } // mongo "signature" : { "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="), "keyId" : Long(0) }
示例
Run getAuditConfig on the admin database .
db.adminCommand({getAuditConfig: 1})
示例服务器配置为审核读取和写入操作。 它有一个过滤器,用于捕获所需的操作,并且auditAuthorizationSuccess值已设置为true 。
{ generation: ObjectId("60e73e74680a655705f16525"), filter: { atype: 'authCheck', 'param.command': { '$in': [ 'find', 'insert', 'delete', 'update', 'findandmodify' ] } }, auditAuthorizationSuccess: true, ok: 1, '$clusterTime': { clusterTime: Timestamp(1, 1625767540), signature: { hash: Binary(Buffer.from("0000000000000000000000000000000000000000", "hex"), 0), keyId: Long("0") } }, operationTime: Timestamp(1, 1625767540) }