Wednesday, June 25, 2008

Using Extended Attributes in TADDM with the TADDM API

As I've mentioned before, TADDM is the heart of IBM's CMDB solution.

Now, each Configuration Item (CI) in the CMDB has a very long list of attributes; For a computer it's the computer's name, IP address, amount of memory and so on. For a database it's the list of schemas, physical files and so on.

Now, TADDM is smart and can extract just about everything possible about a system. However, there's no way in the world it can know about outside information - such as the name of the person in charge of the specific server. That's why there are a number of attributes which are not discovered automatically, but are entered manually. These are called administration attributes are mainly names, phone-numbers and so on.

Now, you may have a use for information of this sort that does not appear as one of the administration attributes. The classic example is the physical location of the server. To solve this problem, TADDM has Extended Attributes which you can create and add to any type of CI. You could add a PhysicalLocation field to every ComputerSystem and a NeedsToBeBackedUp field to every database.

The only problem is that the default reports will not show you your Extended Attributes.

There are two solutions at the moment (I understand that the default reporting options should improve by the end of this year).

The smart solution is to download the TADDM connector for TDI which will enable you to manipulate your TADDM database easily. (After you've gone through the learning curve, of course)

The simple(r) solution is to write a short Java program which will extract the information for you.

I recommend you do both - and see what works best for you. You'll certainly learn more about TADDM this way.

Here is a short Java program which will demonstrate how to use the Java API to get data out of TADDM

----- Begin

// I don't think you need ALL these includes for this specific program to run, but they never hurt...
import com.collation.platform.model.Guid;
import com.collation.platform.model.AttributeNotSetException;
import com.collation.platform.model.ModelObject;
import com.collation.platform.model.topology.extattrib.UserData;
import com.collation.platform.model.topology.meta.UserDataAttributeMeta;
import com.collation.platform.model.topology.meta.UserDataMeta;
import com.collation.platform.model.topology.sys.ComputerSystem;
import com.collation.platform.model.topology.sys.OperatingSystem;
import com.collation.platform.util.ModelFactory;
import com.collation.proxy.api.client.ApiConnection;
import com.collation.proxy.api.client.ApiException;
import com.collation.proxy.api.client.ApiSession;
import com.collation.proxy.api.client.CMDBApi;
import com.collation.proxy.api.common.AttrNameValue;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Vector;

public class ShowAttributes{

        String usage = "Usage: ShowAttributes <hostname> <port> <username> <password> <condition>";
        if (args.length < 6) {
        String hostname = args[0];
        int port = Integer.parseInt(args[1]);
        String username = args[2];
        String password = args[3];
        String condition = args[4];
        String extendedAttribute = args[5];

        //We've got our initial arguments. Lets access the TADDM database!
        CMDBApi Api= null;
        ApiSession Session = null;
        ApiConnection Conn = ApiFactory.getInstance().getApiConnection(hostname, port, null, false);
        Session = ApiFactory.getInstance().getSession(Conn, username, password, ApiSession.DEFAULT_VERSION);
        Api = Session.createCMDBApi();

        //We'll extract a list of ComputerSystems
        Query = "SELECT * FROM ComputerSystem where fqdn contains '" + condition + "'";            
        ModelObject mo[] = Api.find(Query, -1, null, null);
        System.out.println("Found " + String.valueOf(mo.length) + " items."); 
        //Loop over the list of computers
        for (int j=0; j<mo.length; j++) {   

              //Print out the computer's name
              ComputerSystem computer = (ComputerSystem) mo[j];
              //Extract the list of Extended Attributes for our specific computer
              Guid guid = mo[j].getGuid();
              AttrNameValue[] attrNameValGet = api.getExtendedAttributes(guid);
              //Loop over the list of Extended Attributes  
              for (int jj=0; jj<attrNameValGet.length; jj++) { 
                          System.out.println(">" + attrNameValGet[jj].name + "," + attrNameValGet[jj].value + ","); 



---- End

(This has been cut & pasted without re-double-triple-checking, so please tell me if there are problems)

Now, the problems don't end just with writing the program. How do you compile and run it?
Java being Java, you need a ton of parameters so that the right jar files will be found.
Here's a batch file which compiles our program and runs it.

---- Begin ShowAttributes.bat

@echo off
rem You must set these two to suit your environment.
set COLLATION_HOME=D:\IBM\cmdb\dist
set JAVA_HOME=%COLLATION_HOME%\external\jdk-1.5.0-Windows-i386

rem We will now set TADDM's environment so we can compile java
set path=%path%;%JAVA_HOME%\bin
call %TADDM_SDK_HOME%\bin\setTaddmEnv.bat

echo Compiling
javac -Xlint:deprecation -cp %TADDM_CLASSPATH% -d .
if %errorlevel% neq 0 exit /b
Rem Continue if there were no compiler errors

java -Dcom.collation.home=%COLLATION_HOME% -cp %COLLATION_HOME%\lib\api-client.jar;%COLLATION_HOME%\lib\api-dep.jar;%COLLATION_HOME%\lib\platform-model.jar;. ShowAttributes %1 %2 %3 %4 %5 %6 %7 %8


---- End ShowAttributes.bat

Read more about the TADDM API and other TADDM tricks and tips with the new Redbooks which have just been published.

IBM Tivoli Application Dependency Discovery Manager Capabilities and Best Practices

Deployment Guide Series: IBM Tivoli Application Dependency Discovery Manager V7.1

Have fun!

No comments: