Definição
getAuditConfigNovidade na versão 5.0.
getAuditConfigis an administrative command that retrieves audit configurations frommongodandmongosserver instances.
Compatibilidade
Esse comando está disponível em implantações hospedadas nos seguintes ambientes:
MongoDB Enterprise: a versão autogerenciada e baseada em assinatura do MongoDB
MongoDB Community: uma versão com código disponível, de uso gratuito e autogerenciada do MongoDB
Importante
Este comando não é aceito em clusters do MongoDB Atlas. Para obter informações sobre o suporte do Atlas a todos os comandos, consulte Comandos não suportados.
Sintaxe
O comando tem a seguinte sintaxe:
db.adminCommand( { getAuditConfig: 1 } )
Comportamento
Auditing must be enabled to use getAuditConfig.
Os nós que não participam de uma configuração de auditoria de tempo de execução retornam suas definições de arquivo de configuração atuais para auditLog.filter e 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.
Observação
Se você estiver gravando scripts de auditoria automatizados, observe que o estilo entre aspas e os tipos usados para representar a assinatura do cluster diferem entre mongosh e o shell mongo legado. Em mongosh os tipos são Binário e Longo. Os tipos correspondentes no shell legado são BinData e NumberLong.
// mongosh signature: { hash: Binary(Buffer.from("0000000000000000000000000000000000000000", "hex"), 0), keyId: Long("0") } // mongo "signature" : { "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="), "keyId" : Long(0) }
Exemplos
Run getAuditConfig on the admin database .
db.adminCommand({getAuditConfig: 1})
O servidor de exemplo é configurado para auditar operações de leitura e gravação. Tem um filtro que captura as operações desejadas e o valor auditAuthorizationSuccess foi definido como 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) }