UCMDB API CIs to Record Set

Hi,

I am trying to pull the information from UCMDB using the api(Version 8). This extract needs to be stored in a database. I am able to connect to the server and then iterate thru each of the topology. But all topology CI's have 0 properties.

Please let me know how to read the Topology to convert it to a recorset. I wanted somthing like the way we export it to CSV, so we can store it as a database base.

 

 

P.S. This thread has been moevd from Application Perf Mgmt (BAC / BSM) Support and News Forum to CMS and Discovery Support and News Forum. - Hp Forum Moderator

Parents
  • Hi

    Use getCIsByName and getPropertyValue methods, as seen below:

    TopologyQueryService queryService =
    ucmdbService.getTopologyQueryService();
    TopologyQueryFactory queryFactory =
    queryService.getFactory();
    QueryDefinition queryDefinition =
    queryFactory.createQueryDefinition
    ("Get hosts with more than one network interface");
    String hostNodeName = "Host";
    QueryNode hostNode =
    queryDefinition.addNode(hostNodeName).ofType("host").queryProperty("display_l
    abel");
    QueryNode ipNode =
    queryDefinition.addNode("IP").ofType("ip").queryProperty("ip_address");
    hostNode.linkedTo(ipNode).withLinkOfType("contained").atLeast(2);
    Topology topology = queryService.executeQuery(queryDefinition);
    Collection hosts = topology.getCIsByName(hostNodeName);
    for (TopologyCI host : hosts) {
    System.out.println("Host " host.getPropertyValue("display_label"));
    for (TopologyRelation relation : host.getOutgoingRelations()) {
    System.out.println
    (" has IP " relation.getEnd2CI().getPropertyValue("ip_address"));
    }
    }


    this is from Topology javadoc:

    Result of a topology query execution.
    You can retrieve CIs and relations from this by query node name or as a flat collection. If each CI matches exactly one node, the two techniques give the same result. If a CI matches more than one node, the topology structure holds n 1 instances of the CI where n is the number of nodes that contain the CI. When a CI is retrieved from the collection returned by getCIsByName(java.lang.String), its properties and relations are defined by the node with the specified name. When a CI is retrieved from the collection returned by getAllCIs(), the CI has all of the of the queried properties and connected relations of all instances of that CI.

    Similarly, when a Relations relation is matched by more than one query link node, the relation appears in this structure more than once.

    When traversing the resulting graph with TopologyCI.getOutgoingRelations() and TopologyCI.getIncomingRelations(), the relations are consistent with the connected CIs. If the CI is taken from a node, the relation will be the one connected to that node. When the CI is taken from the collection of all CIs, it is associated with all the relations to which the CI is connected from all nodes.

    Examples:

    List all hosts in uCMDB:

    QueryDefinition queryDefinition = factory.createQueryDefinition("Get all hosts");
    queryDefinition.addNode("Hosts").ofType("host").queryProperty("host_dnsname");
    Topology topology = topologyQueryService.executeQuery(queryDefinition);
    for (TopologyCI host : topology.getAllCIs()) {
    System.out.println("Host key:" host.getPropertyValue("host_dnsname");
    }
    List all hosts with their contained resources
    QueryDefinition queryDefinition = factory.createQueryDefinition("Get hosts' resources");
    String hostsNodeName = "Hosts";
    QueryNode hostsNode = queryDefinition.addNode(cisNodeName).ofType("host");
    QueryNode resourcesNode = queryDefinition.addNode("Resources").ofType("hostresource").queryKeyProperties();
    hostsNode.linkedTo(resourcesNode).withLinkOfType("container_f");
    Topology topology = topologyQueryService.executeQuery(queryDefinition);
    for (TopologyCI host : topology.getCIsByName(hostsNodeName)) {
    System.out.println("Host:");
    printElement(host);
    for (Relation relation : host.getOutgoingRelations()) {
    System.out.println("\tResource:");
    printElement(relation.getEnd2CI(), "\t");
    }
    }
Reply
  • Hi

    Use getCIsByName and getPropertyValue methods, as seen below:

    TopologyQueryService queryService =
    ucmdbService.getTopologyQueryService();
    TopologyQueryFactory queryFactory =
    queryService.getFactory();
    QueryDefinition queryDefinition =
    queryFactory.createQueryDefinition
    ("Get hosts with more than one network interface");
    String hostNodeName = "Host";
    QueryNode hostNode =
    queryDefinition.addNode(hostNodeName).ofType("host").queryProperty("display_l
    abel");
    QueryNode ipNode =
    queryDefinition.addNode("IP").ofType("ip").queryProperty("ip_address");
    hostNode.linkedTo(ipNode).withLinkOfType("contained").atLeast(2);
    Topology topology = queryService.executeQuery(queryDefinition);
    Collection hosts = topology.getCIsByName(hostNodeName);
    for (TopologyCI host : hosts) {
    System.out.println("Host " host.getPropertyValue("display_label"));
    for (TopologyRelation relation : host.getOutgoingRelations()) {
    System.out.println
    (" has IP " relation.getEnd2CI().getPropertyValue("ip_address"));
    }
    }


    this is from Topology javadoc:

    Result of a topology query execution.
    You can retrieve CIs and relations from this by query node name or as a flat collection. If each CI matches exactly one node, the two techniques give the same result. If a CI matches more than one node, the topology structure holds n 1 instances of the CI where n is the number of nodes that contain the CI. When a CI is retrieved from the collection returned by getCIsByName(java.lang.String), its properties and relations are defined by the node with the specified name. When a CI is retrieved from the collection returned by getAllCIs(), the CI has all of the of the queried properties and connected relations of all instances of that CI.

    Similarly, when a Relations relation is matched by more than one query link node, the relation appears in this structure more than once.

    When traversing the resulting graph with TopologyCI.getOutgoingRelations() and TopologyCI.getIncomingRelations(), the relations are consistent with the connected CIs. If the CI is taken from a node, the relation will be the one connected to that node. When the CI is taken from the collection of all CIs, it is associated with all the relations to which the CI is connected from all nodes.

    Examples:

    List all hosts in uCMDB:

    QueryDefinition queryDefinition = factory.createQueryDefinition("Get all hosts");
    queryDefinition.addNode("Hosts").ofType("host").queryProperty("host_dnsname");
    Topology topology = topologyQueryService.executeQuery(queryDefinition);
    for (TopologyCI host : topology.getAllCIs()) {
    System.out.println("Host key:" host.getPropertyValue("host_dnsname");
    }
    List all hosts with their contained resources
    QueryDefinition queryDefinition = factory.createQueryDefinition("Get hosts' resources");
    String hostsNodeName = "Hosts";
    QueryNode hostsNode = queryDefinition.addNode(cisNodeName).ofType("host");
    QueryNode resourcesNode = queryDefinition.addNode("Resources").ofType("hostresource").queryKeyProperties();
    hostsNode.linkedTo(resourcesNode).withLinkOfType("container_f");
    Topology topology = topologyQueryService.executeQuery(queryDefinition);
    for (TopologyCI host : topology.getCIsByName(hostsNodeName)) {
    System.out.println("Host:");
    printElement(host);
    for (Relation relation : host.getOutgoingRelations()) {
    System.out.println("\tResource:");
    printElement(relation.getEnd2CI(), "\t");
    }
    }
Children
No Data