config

package
v1.0.7-pre Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2022 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBool added in v1.10.0

func GetBool(s string) bool

func GetDuration added in v1.10.0

func GetDuration(s string) time.Duration

func GetInt added in v1.4.3

func GetInt(s string) int

func GetString

func GetString(s string, confmap ...map[string]string) string

Returns the configuration item as a string with ExpandString() applied, passing the first "confmap" if given

func GetStringMapString

func GetStringMapString(s string, confmap ...map[string]string) map[string]string

func GetStringSlice

func GetStringSlice(s string, confmap ...map[string]string) []string

func GetViper

func GetViper() *viper.Viper

func SetDefault added in v1.10.0

func SetDefault(s string, i interface{})

Types

type Attribute

type Attribute struct {
	XMLName xml.Name `xml:"attribute"`
	Name    string   `xml:"name,attr"`
	Value   string   `xml:",innerxml"`
}

type Column

type Column struct {
	Name  string `xml:"name>data"`
	XPath string `xml:"xpath"`
	Type  string `xml:"type"`
}

type Config

type Config struct {
	// contains filtered or unexported fields
}

The Config type acts as a container for local/extended viper instances

func GetConfig

func GetConfig() *Config

func (*Config) ExpandString

func (c *Config) ExpandString(input string, confmap map[string]string) (value string)

Return a string that has all contents of the form ${var} or $var expanded according to the following rules:

url - read the contents of the url, which can be a local file, as below:
	${file://path/to/file} - read the entire contents of the file, trim whitespace
	${https://host/path} - fetch the remote contents, trim whitespace. "http:" also supported.
${env:VARNAME} - replace with the contents of the environment varaible VARNAME, trim whitespace
${path.to.config} - and var containing a '.' will be looked up in global viper config space - this is NOT recursive
${name} - replace with the contents of confmap["name"] - trim whitespace

While the form $var is also supported but may be ambiguous and is not recommended.

If confmap is not given then environment variables are used directly.

Any errors result in an empty string being returned.

func (*Config) GetBool added in v1.10.0

func (c *Config) GetBool(s string) bool

func (*Config) GetDuration added in v1.10.0

func (c *Config) GetDuration(s string) time.Duration

func (*Config) GetInt added in v1.4.3

func (c *Config) GetInt(s string) int

func (*Config) GetString

func (c *Config) GetString(s string, confmap ...map[string]string) string

Returns the configuration item as a string with ExpandString() applied, passing the first "confmap" if given

func (*Config) GetStringMapString

func (c *Config) GetStringMapString(s string, confmap ...map[string]string) (m map[string]string)

func (*Config) GetStringSlice

func (c *Config) GetStringSlice(s string, confmap ...map[string]string) (slice []string)

func (*Config) GetViper

func (c *Config) GetViper() *viper.Viper

func (*Config) SetDefault added in v1.10.0

func (c *Config) SetDefault(s string, i interface{})

func (*Config) SetViper

func (c *Config) SetViper(v *viper.Viper)

type DBConnection

type DBConnection struct {
	MySQL                     *MySQL     `xml:"database>mysql,omitempty"`
	SQLServer                 *SQLServer `xml:"database>sqlServer,omitempty"`
	Sybase                    *Sybase    `xml:"database>sybase,omitempty"`
	UsernameVar               VarRef     `xml:"var-userName>var"`
	PasswordVar               VarRef     `xml:"password>var"`
	CloseConnectionAfterQuery bool       `xml:"closeConnectionAfterQuery>data"`
}

type Data

type Data struct {
	XMLName xml.Name `xml:"data"`
	Data    string   `xml:",chardata"`
}

type Dataview

type Dataview struct {
	XMLName   xml.Name `xml:"dataview"`
	Name      string   `xml:"name,attr"`
	Additions DataviewAdditions
}

type DataviewAdditions

type DataviewAdditions struct {
	XMLName   xml.Name           `xml:"additions"`
	Headlines []DataviewHeadline `xml:"var-headlines>data,omitempty"`
}

type DataviewHeadline

type DataviewHeadline struct {
	Name string `xml:"headline>data,omitempty"`
}

type Environment

type Environment struct {
	XMLName      xml.Name      `xml:"environment,omitempty"`
	Name         string        `xml:"name,attr"`
	Environments []Environment `xml:"environment,omitempty"`
	Vars         []Vars
}

type EnvironmentGroup

type EnvironmentGroup struct {
	XMLName      xml.Name `xml:"environmentGroup"`
	Name         string   `xml:"name,attr"`
	Environments []Environment
}

type EnvironmentVariable

type EnvironmentVariable struct {
	Name  string           `xml:"name"`
	Value SingleLineString `xml:"value"`
}

type Environments

type Environments struct {
	XMLName      xml.Name `xml:"environments"`
	Groups       []EnvironmentGroup
	Environments []Environment
}

type FTMAdditionalPath

type FTMAdditionalPath struct {
	Path string `xml:"data"`
}

type FTMAdditionalPaths

type FTMAdditionalPaths struct {
	Paths []FTMAdditionalPath `xml:"additionalPath"`
}

type FTMFile

type FTMFile struct {
	XMLName         xml.Name            `xml:"file"`
	Path            string              `xml:"path>data"`
	AdditionalPaths *FTMAdditionalPaths `xml:"additionalPaths,omitempty"`
	ExpectedArrival string              `xml:"expectedArrival>data"`
	ExpectedPeriod  *struct {
		Period string `xml:",innerxml"`
	} `xml:"expectedPeriod,omitempty"`
	TZOffset         string      `xml:"tzOffset>data"`
	MonitoringPeriod interface{} `xml:"monioringPeriod"`
	Alias            string      `xml:"alias>data"`
}

type FTMSampler

type FTMSampler struct {
	XMLName                    xml.Name   `xml:"sampler"`
	Name                       string     `xml:"name,attr"`
	Comment                    string     `xml:",comment"`
	Group                      string     `xml:"var-group>data"`
	Interval                   *VarData   `xml:"sampleInterval,omitempty"`
	Files                      []FTMFile  `xml:"plugin>ftm>files>file"`
	ConsistentDateStamps       bool       `xml:"plugin>ftm>consistentDateStamps>data,omitempty"`
	DisplayTimeInISO8601Format bool       `xml:"plugin>ftm>displayTimeInIso8601Format>data,omitempty"`
	ShowActualFilename         bool       `xml:"plugin>ftm>showActualFilename>data,omitempty"`
	DelayUnit                  string     `xml:"plugin>ftm>delayUnit"`
	SizeUnit                   string     `xml:"plugin>ftm>sizeUnit"`
	Dataviews                  []Dataview `xml:"dataviews>dataview,omitempty"`
}

type Gateway

type Gateway struct {
	XMLName         xml.Name `xml:"gateway"`
	Compatibility   int      `xml:"compatibility,attr"`
	XMLNs           string   `xml:"xmlns:xsi,attr"`                     // http://www.w3.org/2001/XMLSchema-instance
	XSI             string   `xml:"xsi:noNamespaceSchemaLocation,attr"` // http://schema.itrsgroup.com/GA5.12.0-220125/gateway.xsd
	ManagedEntities *ManagedEntities
	Types           *Types
	Samplers        *Samplers
	Environments    *Environments
}

type GatewaySQLSampler

type GatewaySQLSampler struct {
	XMLName   xml.Name          `xml:"sampler"`
	Name      string            `xml:"name,attr"`
	Comment   string            `xml:",comment"`
	Group     string            `xml:"var-group>data"`
	Interval  *VarData          `xml:"sampleInterval,omitempty"`
	Setup     string            `xml:"plugin>Gateway-sql>setupSql>sql>data"`
	Tables    []GatewaySQLTable `xml:"plugin>Gateway-sql>tables>xpath"`
	Views     []View            `xml:"plugin>Gateway-sql>views>view"`
	Dataviews []Dataview        `xml:"dataviews>dataview,omitempty"`
}

type GatewaySQLTable

type GatewaySQLTable struct {
	XMLName xml.Name `xml:"xpath"`
	Name    string   `xml:"tableName>data"`
	XPaths  []string `xml:"xpaths>xpath"`
	Columns []Column `xml:"columns>column"`
}

type Macro

type Macro struct{}

type ManagedEntities

type ManagedEntities struct {
	XMLName            xml.Name `xml:"managedEntities"`
	ManagedEntityGroup struct {
		XMLName    xml.Name        `xml:"managedEntityGroup"`
		Name       string          `xml:"name,attr"`
		Attributes []Attribute     `xml:",omitempty"`
		Vars       []Vars          `xml:",omitempty"`
		Entities   []ManagedEntity `xml:",omitempty"`
	}
}

type ManagedEntity

type ManagedEntity struct {
	XMLName xml.Name `xml:"managedEntity"`
	Name    string   `xml:"name,attr"`
	Probe   struct {
		Name     string         `xml:"ref,attr"`
		Timezone *time.Location `xml:"-"`
	} `xml:"probe"`
	Attributes []Attribute `xml:",omitempty"`
	AddTypes   struct {
		XMLName xml.Name  `xml:"addTypes"`
		Types   []TypeRef `xml:",omitempty"`
	}
	Vars []Vars `xml:",omitempty"`
}

type MonitoringPeriodAlias

type MonitoringPeriodAlias struct {
	Alias string `xml:"periodAlias"`
}

type MonitoringPeriodStart

type MonitoringPeriodStart struct {
	PeriodStart string `xml:"periodStart>data"`
}

type MySQL

type MySQL struct {
	ServerNameVar VarRef `xml:"var-serverName>var"`
	DBNameVar     VarRef `xml:"var-databaseName>var"`
	PortVar       VarRef `xml:"var-port>var"`
}

type Query

type Query struct {
	Name string           `xml:"name>data"`
	SQL  SingleLineString `xml:"sql"`
}

type Rule

type Rule struct {
	XMLName      xml.Name `xml:"rule"`
	Name         string   `xml:"name,attr"`
	Targets      []string `xml:"targets>target"`
	Priority     int      `xml:"priority"`
	Ifs          []interface{}
	Transactions []interface{}
}

type RuleGroups

type RuleGroups struct {
	XMLName xml.Name `xml:"ruleGroup"`
	Name    string   `xml:"name,attr"`
}

type Rules

type Rules struct {
	XMLName    xml.Name `xml:"rules"`
	RuleGroups []interface{}
	Rules      []interface{}
}

type SQLServer

type SQLServer struct {
	ServerNameVar VarRef `xml:"var-serverName>var"`
	DBNameVar     VarRef `xml:"var-databaseName>var"`
	PortVar       VarRef `xml:"var-port>var"`
}

type SQLToolkitSampler

type SQLToolkitSampler struct {
	XMLName    xml.Name     `xml:"sampler"`
	Name       string       `xml:"name,attr"`
	Comment    string       `xml:",comment"`
	Group      string       `xml:"var-group>data"`
	Interval   *VarData     `xml:"sampleInterval,omitempty"`
	Queries    []Query      `xml:"plugin>sql-toolkit>queries>query"`
	Connection DBConnection `xml:"plugin>sql-toolkit>connection"`
}

type Samplers

type Samplers struct {
	XMLName      xml.Name `xml:"samplers"`
	SamplerGroup struct {
		Name          string `xml:"name,attr"`
		SamplerGroups []interface{}
		Samplers      []interface{}
	} `xml:"samplerGroup"`
}

type SingleLineString

type SingleLineString struct {
	Parts []interface{}
}

A container for a single line string that can be made up of static text and variable references. Use like this:

type MyContainer struct {
	XMLName  xml.Name         `xml:"mycontainer`
	VarField SingleLineString `xml:"fieldname"`
}

func blah() {
	x := MyContainer{
		VarField: geneos.NewSingleLineString(geneos.Data{Data: "hello"}, geneos.Var{Var: "world"}, geneos.Data{Data: "!"})
	}
	...
}

func ExpandSingleLineString

func ExpandSingleLineString(in string) (s SingleLineString)

ExpandSingleLineString take a plain string and locates any Geneos style variables of the form $(var) - not these are parenthesis and not brackets - and splits the string into Data and Var parts as required so that this can be used directly in the XML encodings

func NewSingleLineString

func NewSingleLineString(parts ...interface{}) (s SingleLineString)

type Sybase

type Sybase struct {
	InstanceNameVar VarRef `xml:"var-instanceName>var"`
	DBNameVar       VarRef `xml:"var-databaseName>var"`
}

type ToolkitSampler

type ToolkitSampler struct {
	XMLName              xml.Name              `xml:"sampler"`
	Name                 string                `xml:"name,attr"`
	Comment              string                `xml:",comment"`
	Group                string                `xml:"var-group>data"`
	Interval             *VarData              `xml:"sampleInterval,omitempty"`
	SamplerScript        string                `xml:"plugin>toolkit>samplerScript>data"`
	EnvironmentVariables []EnvironmentVariable `xml:"plugin>toolkit>environmentVariables>variable"`
}

type Type

type Type struct {
	XMLName      xml.Name `xml:"type"`
	Name         string   `xml:"name,attr"`
	Environments []VarRef `xml:"environment,omitempty"`
	Vars         []Vars   `xml:",omitempty"`
	Samplers     []VarRef `xml:"sampler,omitempty"`
}

type TypeRef

type TypeRef struct {
	XMLName xml.Name `xml:"type"`
	Name    string   `xml:"ref,attr"`
}

type Types

type Types struct {
	XMLName xml.Name `xml:"types"`
	Group   struct {
		XMLName xml.Name `xml:"typeGroup"`
		Name    string   `xml:"name,attr"`
		Types   []Type
	}
}

type Var

type Var struct {
	XMLName xml.Name `xml:"var"`
	Var     string   `xml:"ref,attr"`
}

type VarData

type VarData struct {
	Part interface{}
}

VarData is a struct that contains either a Var or a Data type depending on the usage.

func NewVarData

func NewVarData(s string) (n *VarData)

NewVarData takes a string argument and removes leading and trailing spaces. If the string is of the form "$(var)" then returns a pointer to a VarData struct containing a Var{} or if a non-empty string returns a Data{}. If the string is empty then a nil pointer is returned. This allows `xml:",omixempty"“ to leave out VarData fields that contain no data.

type VarMacro

type VarMacro struct {
	ManagedEntitiesName *Macro `xml:"managedEntityName,omitempty"`
	InsecureGatewayPort *Macro `xml:"insecureGatewayPort,omitempty"`
}

these have to be pointers for the ",omitempty" logic to work. only ever initialise one field to an empty struct.

type VarRef

type VarRef struct {
	Name string `xml:"ref,attr"`
}

type VarStringList

type VarStringList struct {
	Strings []string `xml:"string"`
}

type Vars

type Vars struct {
	XMLName    xml.Name       `xml:"var"`
	Name       string         `xml:"name,attr"`
	Macro      *VarMacro      `xml:"macro,omitempty"`
	String     string         `xml:"string,omitempty"`
	StringList *VarStringList `xml:"stringList,omitempty"`
}

type View

type View struct {
	XMLName  xml.Name         `xml:"view"`
	ViewName SingleLineString `xml:"name"`
	SQL      string           `xml:"sql>data"`
}

Jump to

Keyboard shortcuts

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