Exporting Audit logs for last 24 hours into a .zip file is quite easy with the combination of Groovy and REST API. Here is an example.

def params = new JSONObject()
     .put("fileName",(new Date()).format('ddMMMyyyy')+".zip")
     .put("ndays","1")
     .put("excludeApplicationId","true")  
def body = new JSONObject()
     .put("jobType","Export Audit")
     .put("jobName","ExportAudit")
     .put("parameters",params)
     .toString()

Parameter ndays set to 1 means last 24 hours. If you schedule to run this rule same time everyday, you will have a collection of .zip files for each day. You can transfer the file to another audit monitoring software or perhaps send someone as an email attachment.

Rest of the code is pretty standard for any job execution and monitoring.

HttpResponse jsonResponse = operation.application.getConnection("PBCS").post("/HyperionPlanning/rest/v3/applications/PLAN/jobs").body(body).asString();
    def pbcsstatus = awaitCompletion(jsonResponse, "PBCS")
    println("PBCS Status for : ${pbcsstatus == 0 ? "successful" : "failed"}.\n")
def awaitCompletion(HttpResponse<String> jsonResponse, String connectionName) {
     final int IN_PROGRESS = -1
     if(!(200..299).contains(jsonResponse.status))
         throwVetoException("Error occured: $jsonResponse.statusText")
     ReadContext ctx = JsonPath.parse(jsonResponse.body)
     int status = ctx.read('$.status')
     for(long delay = 50; status == IN_PROGRESS; delay = Math.min(1000, delay * 2)) {
         sleep(delay)
         status = getJobStatus(connectionName, (String)ctx.read('$.jobId'))
     }
     return status
}
 int getJobStatus(String connectionName, String jobId) {
     HttpResponse<String> pingResponse = operation.application.getConnection(connectionName).get("HyperionPlanning/rest/v3/applications/PLAN/jobs/$jobId").asString()
     return JsonPath.parse(pingResponse.body).read('$.status')
 }

Once you execute, you will see 2 jobs. 1 for the business rule you execute, 1 for the export job you are triggering from the rule. It should be seen as follows.

File is simply visible from inbox / outbox explorer for further processing.

LEAVE A REPLY

Please enter your comment!
Please enter your name here