Geneos ["Geneos"]
"1"


The end of life (EOL) date for this module is on 31 January, 2020.

Creating XPaths

Quick Start

Take the path from the previous example:

/geneos/gateway[(@name="Demo Gateway")]/directory/probe[(@name="Basic Probe")]/managedEntity[(@name="Basic Entity")]/sampler[(@name="cpu")][(@type="Basic")]/dataview[(@name="cpu")]

This is how the same path is constructed using the builder:

String query = XPathBuilder.xpath()
    .gateway("Demo Gateway")
    .probe("Basic Probe")
    .entity("Basic Entity")
    .sampler("cpu", "Basic")
    .view("cpu")
    .get();

Similarly, an xpath that matches a number of items can also be expressed. For example the path to match all CRITICAL entities:

/gateway/directory/probe/managedEntity[(state("severity")="3")]

can be constructed with the builder in a more succinct and readable form:

String query = XPathBuilder.xpath().entity().severity(Severity.CRITICAL).get();

Unique identities

Some methods in the API only work with xpaths that match a single item in the system, for example executing commands. In general, the rule of thumb is the path uniquely identifies an item if all the parents are named. For the case of samplers, a type must be specified as well as a name (although this can be blank).

The builder provides the isID() utility method that can be used to test if a path satisfies these criteria:

XPathBuilder.xpath().view("test").isID() == false;

XPathBuilder.xpath().gateway("gw").probe("probey").entity("woo").isID() == true;

More examples

Here’s some more examples of using the builder:
XPathBuilder.xpath().get();                          // Matches all gateways

XPathBuilder.xpath().entity().get();                 // Matches all Managed Entities
                                                     // Methods are available for all items (from gateway to cell)

XPathBuilder.xpath().view("fred").get();             // Matches all Dataviews with the name fred

XPathBuilder.probe("henry").entity("ford").get();    // Matches all Managed Entities named ford under the Probe named henry

XPathBuilder.sampler("test", "test_type").get();     // Matches all Samplers named test from the Type test_type

XPathBuilder.xpath()                                 // Matches all critical probes named barry
    .probe("barry")
    .severity(Severity.CRITICAL)
    .get();

XPathBuilder.xpath()                                 // Matches all snoozed entities
    .entity()
    .snoozed()
    .get();

XPathBuilder.xpath()                                 // Matches all inactive dataviews
    .view()
    .active(false)
    .get();

XPathBuilder.xpath()                                 // Matches all entities where "Country" is "US"
    .entity()
    .attribute("Country", "US")
    .get();

XPathBuilder.xpath()                                 // All samplers with a severity of warning or higher
    .sampler()
    .predicate("state('severity')>1")
    .get();