xpath

package
v1.20.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 13, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

README

Geneos XPath package

Documentation

Overview

Package to handle Geneos Gateway specific XPaths

These are a subset of the W3C XPath 1.0 standard and this package is only interested in absolute paths and no matching is done. Geneos XPaths are of a particular hierarchy and the ones we are interesting in here are those used to communicate with the Gateway REST command API.

The two types of path handled are for headline or table cells, which have the form:

/geneos/gateway/directory/probe/managedEntity/sampler/dataview/ ...

... headlines/cell or ... rows/row/cell

Each component except "geneos", "directory", "headlines" and "rows" can have a name and other predicates. The path can terminate at any level that can carry a name. Apart from names, only attributes in managedEntities are currently handled in anyway.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidPath = errors.New("invalid Geneos XPath")
View Source
var ErrRelativePath = errors.New("unsupported relative Geneos XPath")

Functions

This section is empty.

Types

type Column

type Column struct {
	Name string `json:"name,omitempty"`
}

type Dataview

type Dataview struct {
	Name string `json:"name,omitempty"`
}

type Entity

type Entity struct {
	Name       string            `json:"name,omitempty"`
	Attributes map[string]string `json:"attributes,omitempty"`
}

type Gateway

type Gateway struct {
	Name string `json:"name,omitempty"`
}

type Headline

type Headline struct {
	Name string `json:"name,omitempty"`
}

type Probe

type Probe struct {
	Name string `json:"name,omitempty"`
}

type Row

type Row struct {
	Name string `json:"name,omitempty"`
}

type Sampler

type Sampler struct {
	Name string  `json:"name,omitempty"`
	Type *string `json:"type,omitempty"`
}

type XPath

type XPath struct {
	Gateway  *Gateway  `json:"gateway,omitempty"`
	Probe    *Probe    `json:"probe,omitempty"`
	Entity   *Entity   `json:"entity,omitempty"`
	Sampler  *Sampler  `json:"sampler,omitempty"`
	Dataview *Dataview `json:"dataview,omitempty"`
	Rows     bool      `json:"-"`
	Headline *Headline `json:"headline,omitempty"`
	Row      *Row      `json:"row,omitempty"`
	Column   *Column   `json:"column,omitempty"`
}

XPath represents a Geneos Gateway XPath

Each field (except Rows) is a pointer, which if nil means the Xpath terminates at that point, not that the value is unset. The "Rows" boolean indicates in lower level components are rows or headlines

func New

func New(element interface{}) *XPath

New returns an XPath to the level of the element passed, which can be populated with fields.

func NewDataviewPath

func NewDataviewPath(name string) (x *XPath)

NewDataviewPath returns an xpath populated to the dataview, with name dv if no name is passed, create a wildcard dataview path

func NewHeadlinePath

func NewHeadlinePath(name string) (x *XPath)

NewHeadlinePath returns an xpath populated to the headline cell, identified by headline

func NewTableCellPath

func NewTableCellPath(row, column string) (x *XPath)

NewTableCellPath returns an xpath populated to the table cell identifies by row and column

func Parse

func Parse(s string) (xpath *XPath, err error)

Parse takes an absolute Geneos XPath and returns an XPath structure.

A leading double slash, e.g. //probe[(@name="myprobe")], results in preceding levels being filled-in and further processing continuing from there. Because of the general purpose nature of the function only levels down to //rows and //headlines are supported. If you need a general path to a cell then you must use either //rows/row/cell or //headlines/cell to ensure the returned path uses the correct structure.

Full wildcards, e.g. `//*`, are not supported as it is not possible to determine the terminating level.

Support for predicates is limited. Currently all components understand "name", e.g. //probe[(@name="probeName")], while "managedEntity" supports multiple "attribute" predicates and table cells (under "rows/row/cell") support "column" (which is used instead of "name").

func (*XPath) IsDataview

func (x *XPath) IsDataview() bool

func (*XPath) IsEmpty

func (x *XPath) IsEmpty() bool

IsEmpty returns true is the XPath appears to be empty

func (*XPath) IsEntity

func (x *XPath) IsEntity() bool

func (*XPath) IsGateway

func (x *XPath) IsGateway() bool

func (*XPath) IsHeadline

func (x *XPath) IsHeadline() bool

func (*XPath) IsProbe

func (x *XPath) IsProbe() bool

func (*XPath) IsSampler

func (x *XPath) IsSampler() bool

func (*XPath) IsTableCell

func (x *XPath) IsTableCell() bool

IsTableCell returns true if x represents a table cell

func (*XPath) LookupValues added in v1.11.0

func (x *XPath) LookupValues() (lookup map[string]string)

LookupValues returns a map of the components of x to their values, suitable for use as an Expand LookupTable. Only components of x that are set are added to the returned map and processing stops as soon as an XPath struct field is nil. The returned map is always initialised.

The potential keys set are gateway, probe, entity, sampler, type, dataview, row, column, headline. Entity attributes in the XPath are ignored.

func (XPath) MarshalJSON

func (x XPath) MarshalJSON() ([]byte, error)

return Xpath as a string

func (*XPath) ResolveTo

func (x *XPath) ResolveTo(element interface{}) *XPath

ResolveTo will, given an element type, return a new XPath to that element, removing lower level elements or adding empty elements to the level required. If the XPath does not contain an element of the type given then use the argument (which can include populated fields), but if empty then any existing element will be left as-is and not cleaned.

e.g.

x := x.ResolveTo(&Dataview{})
y := xpath.ResolveTo(&Headline{Name: "headlineName"})

func (*XPath) SetGatewayName

func (x *XPath) SetGatewayName(gateway string)

SetGatewayName sets the Gateway name

?do we need setters? validation?

func (*XPath) String

func (x *XPath) String() (p string)

return a string representation of an XPath

func (*XPath) UnmarshalJSON

func (x *XPath) UnmarshalJSON(b []byte) (err error)

return an xpath parsed from a string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL