Mike Oh
Mike Oh

Reputation: 151

Audit Log on Softlayer

In Softlayer Portal, what Java API can retrieve the data on Audit Log view. I am developing a portal page using Java Client API. If you choose one of the actions in the device list, you can get into the page below.. If you share a python sample code, it will be helpful as well.

Softlayer Audit View Log page

Looking for your feedback.. Thank you

Mike

Upvotes: 0

Views: 598

Answers (2)

mcruz
mcruz

Reputation: 1532

Please try this java example to get the Audit log items using the SoftLayer_Event_Log::getAllObjects

import java.util.Iterator;
import java.util.List;

import com.softlayer.api.ApiClient;
import com.softlayer.api.RestApiClient;
import com.softlayer.api.ResultLimit;
import com.softlayer.api.service.event.Log;

public class getAllObjects {

    public static void main(String[] args) {
        String username = "set me"; 
        String apikey = "set me";
        ApiClient client = new RestApiClient().withCredentials(username, apikey).withLoggingEnabled();
        com.softlayer.api.service.event.Log.Service eventLogService =  com.softlayer.api.service.event.Log.service(client);

        eventLogService.setResultLimit(new ResultLimit(0,50));
        List<Log> a = eventLogService.getAllObjects();

        Iterator<Log> iterator = a.iterator();
        int idx = 0;
        while (iterator.hasNext()) {
        Log data = iterator.next();
        System.out.println(" Data: " + idx);
        System.out.println(" UserName: " + data.getUsername());
        System.out.println(" userType: " + data.getUserType());
        System.out.println(" Action: " + data.getEventName());
        idx++;

    }

}

}

In the script was added “result Limits” in order to get more items than by default (amount by default displayed= 25 last items).

Some references:

http://sldn.softlayer.com/reference/services/SoftLayer_Event_Log/getAllObjects https://github.com/softlayer/softlayer-java/blob/master/examples/src/main/java/com/softlayer/api/example/Pagination.java http://sldn.softlayer.com/article/rest Section: Using Result Limits

Upvotes: 1

Using the API you can get the same information as in control portal (https://control.softlayer.com/account/auditlog), you just need to use this method: http://sldn.softlayer.com/reference/services/SoftLayer_Event_Log/getAllObjects

here an example using REST API call to get the logs:

URL: https://$USERNAME:[email protected]/rest/v3/SoftLayer_Event_Log/getAllObjects.json?resultLimit=0,300

Method: GET

Note: By default the method return the last 25 events if you wish to see more events you need to use the "resultLimit" query

For more information about Softlayer Rest see http://sldn.softlayer.com/article/REST)

If you have troubles to call the method in java or need more information let me know.

I hope it helps

Upvotes: 0

Related Questions