VMware {code} Community
cu3rv0x
Contributor
Contributor

Api Sessions

Hello Folks,

I am getting to know the api for vmware(ViewAdmin 8, 2111) but unfortunately the solution provided to get this csv is with powercli. Unfortunately my environment does not have these modules and I am not able to install them. I have looked at the swagger ui section and do not see the endpoint for this. Here is the pictures where I show you the steps of what I like to accomplish from the api query.

1) On picture one I select the subcategory Sessions from Monitor

2) After the query is made there is a table that is created and you have the option of downloading a csv. That is displayed on two.png.

3) I have a little snippet you can view on three.png

Thanks.

0 Kudos
1 Reply
doskiran
Enthusiast
Enthusiast

Use vSphere SOAP-based (vSphere Management SDK) APIs to get the API sessions.

API: SessionManager 

sessionList*UserSession[]

The list of currently active sessions.

 

To get your API sessions, compare the client machine's IP address and application name with the IpAddress and UserAgent of the UserSession object.

 

Sample code:

 

	public void printUserSessions(String vCenterServer, String userName, String password) {
		try {
			si = new ServiceInstance(new URL("https://" + vCenterServer + "/sdk"), userName, password, false);
			SessionManager sm = si.getSessionManager();
			UserSession[] usList = sm.getSessionList();
			for (UserSession us : usList) {
				System.out.println("Client IPAddress::" + us.getIpAddress());
				System.out.println("Session Username::" + us.getUserName());
				System.out.println("Application/UserAgent::" + us.getUserAgent());
				System.out.println("--------------------------------------------------");
			}
		} catch (Exception e) {
			System.err.println("Error ServiceInstance::" + e.getLocalizedMessage());
		}
	}

 

 

 

0 Kudos