cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Axeda Code Snippet: Getting Audit Records

Highlighted
Level 5

Axeda Code Snippet: Getting Audit Records

The following code snippet will retrieve a months worth of data from the system and return it as a CSV document suitable for import into your spreadsheet or reporting tool of choice.

import static com.axeda.sdk.v2.dsl.Bridges.*

import com.axeda.drm.sdk.Context

import com.axeda.common.sdk.id.Identifier

import com.axeda.services.v2.*

import com.axeda.sdk.v2.exception.*

def ac = new AuditCriteria()

ac.fromDate = Date.parse('yyyy-MM-dd', '2017-03-01')

ac.toDate   = Date.parse('yyyy-MM-dd', '2017-03-31')

def retString = ''

tcount = 0

while ( (results = auditBridge.find(ac)) != null  && tcount < results .totalCount) {

  results.audits.each { res ->

    retString += "${res?.user?.id},${res?.asset?.serialNumber},${res?.category},${res.message},${res.date}\n"

    tcount++

  }

  ac.pageNumber = ac.pageNumber + 1

}

return retString

3 REPLIES

Re: Axeda Code Snippet: Getting Audit Records

I would suggest to move tcount++ to the first statement in audits each loop.

This would help when we define a logic to build retString as shown below.

results.audits.each { res ->

  tcount++

  // you can skip some records

  if(!satisfyingMyCondition)

    return

  retString += "${res?.user?.id},${res?.asset?.serialNumber},${res?.category},${res.message},${res.date}\n"

}

Regards

Arunkumar D

http://www.arundhaj.com/

Re: Axeda Code Snippet: Getting Audit Records

How do I specify categories in AuditCriteria? I want to only query FILE_UPLOAD and SYSTEM_CONFIGURATION e.g.

def ac = new AuditCriteria()

ac.fromDate = Date.parse('yyyy-MM-dd', '2018-07-01')
ac.toDate = Date.parse('yyyy-MM-dd', '2018-07-05')
ac.categories = AuditCategory.SYSTEM_CONFIGURATION - ??

Re: Axeda Code Snippet: Getting Audit Records

The following I would expect to work:

ac.categories = [  AuditCategory.FILE_UPLOAD, AuditCategory.SYSTEM_CONFIGURATION ]