While the TADDM user interface is useful when you want to browse your discovered data, it has its limitations. When you're in support like I am, you use the api to get output in a format you can easily share, transfer, and grep for particular data. When you're a TADDM user, the same types of queries can be useful for getting configuration descriptions of particular discovered objects, troubleshooting, and integration. I keep a file of reference api queries that I refer to on a daily basis, and though I'd pull some of those reference queries out and share them with you. This first post will cover the most common scenario -- querying discovered data -- but the API can do more than just that and I'll share some of those other things in later posts.
A couple of notes:
-- run api queries from dist/sdk/bin
-- for Windows servers the command is api.bat, not api.sh. Just replace it in the examples below.
-- the "-d" or "--depth" flag controls how far "down" the tree of objects is returned. For large applications, use a depth of 1 or filter the output. A depth of 3 while querying a large Oracle RAC or a depth of 5 while querying a large WebSphere server can return enough information to cause an OutOfMemory.
1) Query by IP or name
This is the most simple of API queries, but it is what I find myself doing the most -- querying for a specific system using the attributes most of us use to think about a system -- the name or IP address.
query by hostname, ignoring all case changes:
./api.sh -u <user> -p <password> find "SELECT * FROM ComputerSystem where upper(name) contains 'SGEMOP06'
query by fully qualified domain name:
./api.sh -u <user> -p <password> find --depth 3 "select * from
ComputerSystem where fqdn=='lpqmd504.dev.ipc.us.aexp.com'"
query by IP address:
./api.sh -u <user> -p <password> find --depth 1 "select * from
ComputerSystem where contextIp == '10.69.108.226'
Note: this won't always work if the system is multi-homed. The contextIP is the IP the computer system was discovered with, which may not be the IP you are using to query. (For instance, the context IP for a virtual machine could be the IP of the Virtual Center Server.)
2) Query by guid:
A GUID is a global unique identifier. When I'm troubleshooting a problem and am thinking of discovered data in terms of guids, I use this simple query:
./api.sh -u <user> -p <password> find --depth 1 --guid
You can find the guid in the user interface details pane for the object.
3) Query by object type:
./api.sh -u userid -p password find --depth 1 <object type>
Where <object type> is a CDM Object. There are tons of these CDM objects, but here are a couple to get you started. (If the object you are looking for isn't in this short list, review the Common Data Model for additional objec types -- they are just some common ones.)
Oracle : OracleServer
WebSphere : WebSphereCell, WebSphereServer, WebSphereNode
Windows : WindowsComputerSystem
./api.sh -l log -H localhost -u <user> -p <password> find WindowsComputerSystem
./api.sh -l log -H localhost -u <user> -p <password> find SolarisUnitaryComputerSystem
You can also perform the same query using an MQL (model query language) "select" command:
./api.sh -u <user> -p <password> find --depth 4 "SELECT * FROM ApacheServer"
This is useful when the results of your query produces too much information and you want to filter that information down using attributes, as I show in the next set of examples.
4) Query by object type, filtering with a single attribute:
Finding the WeblogicDomain of a certain guid:
api.sh find 'select * from WeblogicDomain where guid ==
Finding a Db2 database with a specific name:
api.sh find 'select * from Db2Database where name == "TEMPDB"'
Finding all the network devices by finding computer systems of type "bridge" or "router":
"select * from ComputerSystem where type == 'Bridge' or type == 'Router'"
These are all pretty simple -- but once you become fluent in these simple queries, you gain confidence in how to use the API and can start building more complicated MQL queries and using the API for a wider variety of tasks.
What other types of API queries would you like to understand better? Let me know in the comments!
Next in this series: My favorite queries for finding TADDM configuration information using the API.