Back to Geneos FAQ

XPath Quick Guide with Examples

Geneos - XPath Quick Guide with Examples This FAQ features XPaths that may or may not be fully documented in the primary XPaths User Guide. If you notice anything that is not correct or out-of-date, please let Client Services know through the normal Helpdesk channels.

Table of Contents Copied

Introduction

Predicate Functions

Operators

State Attributes

Managed Entity Attributes

Attribute Listing

Introduction Copied

An XPath is a way of describing an item on a gateway. The XPath syntax can be described as a sequence of steps, each one optionally filtered by a set of predicates.

/ <step> <predicates> / <step> <predicates> / ...
/ geneos / gateway [pred1] / directory / probe [pred1] [pred2] / ...

Currently, predicates are restricted so that you cannot evaluate another xpath within a predicate - you can only call functions and access the attributes of the current step node. For this reason, several functions have been created to enable you to access common attributes in a child node which would otherwise be inaccessible (see functions below).

For best performance, it is recommended that paths only contain the names of directory components in order. The full paths possible are then as follows. These can of course have predicates added.

/geneos/gateway/directory/probe/managedEntity/sampler/dataview/rows/row/cell
/geneos/gateway/directory/probe/managedEntity/sampler/dataview/headlines/cell

Predicate Functions Copied

As mentioned above there are several accessor functions which can be used to extract values. These are listed below, along with the number of arguments they take and what each argument should be.

true() Copied

Produces the Boolean value true, takes 0 arguments

/geneos/gateway[state('snoozed')=true()]

false() Copied

Produces the Boolean value false, takes 0 arguments

/geneos/gateway[state('snoozed')=false()]

wild(searchString, matchString) Copied

Performs a wildcard comparison on strings, takes 2 arguments

  1. searchString - the value to match
  2. matchString - a wildcard pattern to match against
/geneos/gateway[wild(@name,"test*")]

wild-no-case(searchString, matchString) Copied

Performs a wildcard comparison on strings ignoring the case of letters, takes 2 arguments

  1. searchString - the value to match
  2. matchString - a wildcard pattern to match against
/geneos/gateway[wild-no-case(@name,"TeSt*")]

contains(haystack, needle) Copied

Checks whether a “haystack” string contains a “needle” string, takes 2 arguments

  1. the “haystack” string
  2. the “needle” string
/geneos/gateway[contains(@name,"test")]

not(value) Copied

Negates a Boolean argument, takes 1 argument

  1. the Boolean to negate
/geneos/gateway[not(contains(@name,"test"))]

attr(name) Copied

Extracts the value of a managed entity attribute, takes 1 argument

  1. the managed entity attribute name to get the value of
/geneos/gateway/directory/probe/managedEntity[attr("attr_name")="some_value"]/sampler/...

Note: The value of the argument should be used in some kind of comparison operation. To get the attribute value on its own, use the path:

/geneos/gateway/directory/probe/managedEntity/attributes/attribute[@name="attr_name"]/@value

rparam(name) Copied

Extracts the value of a runtime parameter for a directory component node, takes 1 argument

  1. the name of the runtime parameter to get the value of
/geneos/gateway/directory/probe[rparam("ConState")="Up"]

To extract a value using an xpath (rather than filtering by predicate), use:

/geneos/gateway/directory/probe/runtimeParameters/@ConState

param(name) Copied

Extracts the value of a parameter for a directory component node, takes 1 argument

  1. the name of the parameter to get the value of
/geneos/gateway/directory/probe[param("HostName")="linux165"]

To extract a value using an xpath (rather than filtering by predicate), use:

/geneos/gateway/directory/probe/parameters/@HostName

state(name) Copied

Extracts the value of a state attribute for a directory component node, or a dataview cell node, takes 1 argument

  1. the name of the state attribute to get the value of
/geneos/gateway/directory/probe[state("severity")>1]

To extract a value using an xpath (rather than filtering by predicate), use:

/geneos/gateway/directory/probe/state/@severity

Back to the top

Operators Copied

In addition to the above functions, the following operators are available for use inside of a predicate:

Back to the top

State Attributes Copied

States can be accessed either using a direct path, or by using an accessor function (see functions above). E.g.

/geneos/gateway/directory/probe/state/@severity
/geneos/gateway/directory/probe[state("snoozed")=0]/managedEntity/sampler/...

Directory components (and cells) contain the following attributes:

Back to the top

Managed Entity attributes Copied

Managed entity attributes are configured by the user, and so will not have a fixed name. Attribute values can be accessed through an accessor function (see functions above). E.g.

/geneos/gateway/directory/managedEntity[attr("user_attribute")="some_value"]/sampler/...

Back to the top

Attribute Listing Copied

The following shows which attributes can be extracted from each XPath element:

geneos Copied

client Copied

gateway Copied

directory Copied

probe Copied

managedEntity Copied

sampler Copied

dataview Copied

headlines Copied

headlines / cell Copied

rows Copied

row Copied

row / cell Copied

Back to the top

XPath Setup Copied

Each Gateway contains a directory of every item within it. The directory is a tree structure. The root of the tree is the Gateway and below that are configured probes, managed entities, samplers, dataviews, cells and headlines. These are added to the directory as they become live. For example, a directory can contain a gateway->probe->managed entity->sample setup. However, until the probe is connected and the sampler has started sampling, the directory will not contain the dataviews, cells and headlines until they are published. State is propagated upward towards the Gateway, thus when a cell becomes critical the Gateway will also become critical.

At the Gateway level the terms directory and Gateway are identical, and they share the same attributes even though the XPath is of the form /geneos/gateway/directory … This is to accommodate XPaths in the Geneos namespace that refer to other things like client (Active Console etc) or components that can connect to several Gateways and identify uniquely by name or attribute.

For Geneos the fastest XPaths you can write are ones that use the “name” attribute. These can be resolved internally using something called a “FastName”. This is an optimization whereby a directory item can supply an object that knows the name of each item leading to it and direct access to those items to query attributes and parameters. If you can identify an item by name this will be the quickest lookup. You should always favor a [@name=value] predicate over [param(“parameter”) = value] predicate. For example “/sampler[(@name=“CPU”)] will be quicker than /sampler[(param(“PluginName”)=“CPU”)].

The next quickest will involve attributes and parameters predicates. Containing these will involve querying the object for the value. These don’t change at run-time so are fairly quick to look up. Similarly run-time parameters (rparam) need to be looked up, but their changeable nature may slow down the process as locking may slow down the process.

Splitting of XPaths

If you look at load monitoring stats you may see parts of your XPath being evaluated individually. The naming code will try to use the efficient parts of the name as one XPath and evaluate the rest separately. It will make this split where path variables are used or a non-identifying predicate (such as [@value=”…"]). A predicate such as this is the worst case scenario as the value of everything that can be matched up to that point will have to be retrieved.

Back to the top

["Geneos"] ["Geneos > Gateway"] ["FAQ"]

Was this topic helpful?