Get Methods

There are multiple ways of retrieving SysInfo data using the API. The next section of code determines which retrieval method should be used for demonstration purposes:

String method = args[0];
if (method.equalsIgnoreCase("LocalMethod1")) {
	/*
	 * Retrieve the SysInfo data specified by classes.
	 */
	sysInfo = getLocalMethod1(sysInfoDir, classes);
} else if (method.equalsIgnoreCase("LocalMethod2")) {
	/*
	 * Retrieve the SysInfo data specified by classes.
	 * This does the same thing as LocalMethod1.
	 */
	sysInfo = getLocalMethod2(sysInfoDir, classes);
} else if (method.equalsIgnoreCase("RemoteMethod1")) {
	/*
	 * Retrieve the SysInfo data specified by classes
	 * from host remoteHostName.
	 */
	sysInfo = getRemoteMethod1(remoteHostName, classes);
}

Get Local Method 1

The getLocalMethod1 method retrieves data using the most simple API calls from the local system by running the SysInfo Command Line Interface (CLI). The core code is:

SysInfoCore2 sysInfo = null;
		
SysInfo si = new SysInfo(sysInfoDir);
// Specify what SysInfo data classes we should retrieve
si.setDataClasses(classes);
// Get the SysInfo object with data populated
sysInfo = si.get();

return sysInfo;

The call to new SysInfo(sysInfoDir) creates a new SysInfo object and tells it to look in the directory specified by sysInfoDir for the SysInfo CLI.

The call to si.setDataClasses(classes) specifies the list of SysInfo data classes to retrieve.

The call to si.get() does the actual retrieval of data.

Get Local Method 2

The getLocalMethod2 method retrieves data from the local system by running the SysInfo Command Line Interface (CLI). It does the same thing as getLocalMethod1 but shows how to specify options to the CLI. The core code is:

SysInfoCore2 sysInfo = null;
		
List<String> siArgs = new ArrayList<String>();
siArgs.add("--class");
// Tell SysInfo what data classes to populate
siArgs.add(classes);
// Create SysInfo object
SysInfo si = new SysInfo(sysInfoDir, siArgs);
// OPTIONAL: Enable debugging
//si.setDebug(true);
// Get the SysInfo object with data populated
sysInfo = si.get();

return sysInfo;

Any valid SysInfo CLI option can be specified by additional siArgs.add(...) calls.

It may be useful to sometimes enable debugging in the SysInfo Java API layer. To do this, you can use the following method:

si.setDebug(true);

Get Remote Method 1

The getRemoteMethod1 method retrieves data from a remote system running the SysInfo Agent version 10 or later. The core code is:

SysInfoCore2 sysInfo = null;
		
SysInfo si = new SysInfo(null, hostName);
// Specify what SysInfo data classes we should retrieve
si.setDataClasses(classes);
// Get the SysInfo object with data populated
sysInfo = si.get();

return sysInfo;

The call to SysInfo(null, hostName) is what tells the SysInfo API to retrieve the information from a host called hostName.