Monday, March 10, 2008

A Java example to access ITM SOAP methods

One of the beauty of ITM 6.1 the SOAP interface is that it allows us to access the monitoring data from any programming language. This article explains how to invoke CT_Get SOAP method from Java.

Overview

This is my first stab at accessing the ITM 6.1 SOAP methods from Java. The idea is to use the built-in XML capabilities of Java with a simple HTTP post mechanism. We could very well use Java SOAP APIs instead of XML and HTTP.

TEMS.java

TEMS.java is an abstraction of Tivoli Enterprise Monitoring Server (TEMS) that is acting as a SOAP server. The TEMS class can hold the hostname, port, userid and password information for the server and the default settings can be changed by set methods. You can retrieve current settings via get* methods. Of course the password information can only be set not retrieved.

The CT_Get() method contains the heart of the logic. There are two parameters to this method, one the object name to retrieve and the target from which the object has to be retrieved. For example, if you want to retrieve the disk data from one managed system, the object name would be "NT_Logical_Disk:" and the target name would be the name of the OS agent.

The CT_Get() method builds the SOAP request XML and post it to the soap server. It also passes the resulting SOAP respense stream to parseXmlStream() method for parsing. After parsing, the results is stored in a XML NodeList and returned to the caller.

TEMSTester.java

This is the "main" program that initializes the TEMS class and invokes CT_Get method. In this example, we get the list of managed systems from the SOAP server and print their status.

Again, this code is just to illustrate the concept and not for any production use as it lacks error handling features and a good XML parsing logic.

You can download the sample code from here

Hope you find it useful. A Perl version is coming up soon.

No comments: