Last active
October 13, 2021 16:58
-
-
Save ataylor284/a98ae622f167314b904dbcf038770967 to your computer and use it in GitHub Desktop.
[nxrm] Export audit records from NXRM3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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