Skip to content

Instantly share code, notes, and snippets.

@ataylor284
Last active October 13, 2021 16:58
Show Gist options
  • Save ataylor284/a98ae622f167314b904dbcf038770967 to your computer and use it in GitHub Desktop.
Save ataylor284/a98ae622f167314b904dbcf038770967 to your computer and use it in GitHub Desktop.
[nxrm] Export audit records from NXRM3
import groovy.json.*
def outputFile = new File("auditExport.json")
def auditStore = container.lookup("org.sonatype.nexus.audit.internal.AuditStore")
int pageSize = 1000
int offset = 0
log.info("exporting audit data to ${outputFile.getAbsolutePath()}")
def output = new PrintWriter(outputFile)
def done = false
while (!done) {
def records = auditStore.browse(offset, pageSize)
records.each { r ->
def attribs = [domain: r.domain, type: r.type, context: r.context, timestamp: r.timestamp, nodeId: r.nodeId, initiator: r.initiator, attributes: r.attributes]
output.println(new JsonBuilder(attribs).toString())
}
if (records.isEmpty()) {
done = true
} else {
offset += records.size()
log.info("exported ${offset} audit records")
}
}
output.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment