instance

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: May 25, 2023 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const AttributeValuesOptionsText = "An attribute in the format NAME=VALUE\n(Repeat as required, san only)"
View Source
const EnvValuesOptionsText = "An environment variable for instance start-up\n(Repeat as required)"
View Source
const GatewayValuesOptionstext = "A gateway connection in the format HOSTNAME:PORT\n(Repeat as required, san and floating only)"
View Source
const IncludeValuesOptionsText = "An include file in the format `PRIORITY:[PATH|URL]`\n(Repeat as required, gateway only)"

IncludeValuesOptionsText is the default help text for command to use for options setting include files

View Source
const TypeValuesOptionsText = "A type NAME\n(Repeat as required, san only)"
View Source
const VarValuesOptionsText = "A variable in the format [TYPE:]NAME=VALUE\n(Repeat as required, san only)"

Variables

This section is empty.

Functions

func Abs

func Abs(c geneos.Instance, file string) (result string)

Abs returns an absolute path to file prepended with the instance working directory if file is not already an absolute path.

func AllNames

func AllNames(h *geneos.Host, ct *geneos.Component) (names []string)

Return a slice of all instance names for a given component. No checking is done to validate that the directory is a populated instance.

func AtLeastVersion added in v1.5.0

func AtLeastVersion(c geneos.Instance, version string) bool

AtLeastVersion returns true if the installed version for instance c is version or greater. If the version of the instance is somehow unparseable then this returns false.

func BuildCmd

func BuildCmd(c geneos.Instance) (cmd *exec.Cmd, env []string)

BuildCmd gathers the path to the binary, arguments and any environment variables for an instance and returns an exec.Cmd, almost ready for execution. Callers will add more details such as working directories, user and group etc.

func Clean

func Clean(c geneos.Instance, full bool) (err error)

Clean removes all the files and directories listed in the component type of the instance c for removal. First all entries in the CleanList are removed and then, if full is true, the instance is stopped and the entries in FullClean are removed. Any instances stopped are started up, but any that were already stopped will be left stopped.

func ComponentFilename

func ComponentFilename(c geneos.Instance, extensions ...string) string

ComponentFilename returns the filename for the component named by the instance similarly to ComponentFilepath

func ComponentFilepath

func ComponentFilepath(c geneos.Instance, extensions ...string) string

ComponentFilepath returns an absolute path to a file named for the component type of the instance with any extensions joined using ".", e.g. is c is a netprobe instance then

path := instance.ComponentFilepath(c, "xml", "orig")

will return /path/to/netprobe/netprobe.xml.orig

If no extensions are passed then the default us to add an extension of the instance.ConfigType, which defaults to "json", e.g. using the same instance as above:

path := instance.ComponentPath(c)

will return /path/to/netprobe/netprobe.json

func ConfigFileType added in v1.4.1

func ConfigFileType() (conftype string)

ConfigFileType returns the current primary configuration file extension

func ConfigFileTypes added in v1.4.1

func ConfigFileTypes() []string

ConfigFileTypes contains a list of supported configuration file extensions

func CopyInstance

func CopyInstance(ct *geneos.Component, source, destination string, move bool) (err error)

CopyInstance copies the instance named source to destination for component type ct. If the move argument is true then the source is deleted after the copy.

Both source and destination can include host labels as well as being only host labels to indicate all instances of type ct on that host. If source is in the form `@host` then destination must also be a host - and different - or the function returns an error, but is it valid to have a specific source and a destination of only `@host` and then the name of the instance is used, as with file system operations on files and directories normally.

If ct is nil that all component types are considered

func CreateCert

func CreateCert(c geneos.Instance) (err error)

CreateCert creates a new certificate for an instance

this also creates a new private key

skip if certificate exists and is valid

func CreateConfigFromTemplate

func CreateConfigFromTemplate(c geneos.Instance, path string, name string, defaultTemplate []byte) (err error)

CreateConfigFromTemplate loads templates from TYPE/templates/[tmpl]* and parse it using the instance data write it out to a single file. If tmpl is empty, load all files

func DeleteSettingFromMap added in v1.4.1

func DeleteSettingFromMap(c geneos.Instance, from map[string]interface{}, key string)

DeleteSettingFromMap removes key from the map from and if it is registered as an alias it also removes the key that alias refers to.

func Disable added in v1.5.0

func Disable(c geneos.Instance) (err error)

Disable the instance c. Does not try to stop a running instance and returns an error if it is running.

func DisplayName

func DisplayName(c geneos.Instance) string

DisplayName returns the type, name and non-local host as a string suitable for display.

func Enable added in v1.5.0

func Enable(c geneos.Instance) (err error)

Enable removes the disabled flag, if any,m from instance c.

func Filename

func Filename(c geneos.Instance, name string) (filename string)

Filename returns the basename of the file named by the configuration item given in 'name'. Returns an empty string if the configuration item doesn't exist or is not set.

func Filenames

func Filenames(c geneos.Instance, names ...string) (filenames []string)

Filenames returns the basename of the files named by the configuration items given in 'names'. Returns an empty slice if the instance is not valid or empty strings for each name if the configuration item doesn't exist or is not set.

func Filepath

func Filepath(c geneos.Instance, name string) string

Filepath returns the full path to the file named by the configuration item given in 'name'. If the configuration item is already an absolute path then it is returned as-is, otherwise it is joined with the home directory of the instance and returned. No indication is given if the path is a valid local one or on a remote host.

func Files

func Files(c geneos.Instance) (openfiles map[int]OpenFiles)

Files returns a map of file descriptor (int) to file details (InstanceProcFiles) for all open, real, files for the process running as the instance. All paths that are not absolute paths are ignored. An empty map is returned if the process cannot be found.

func ForAll

func ForAll(ct *geneos.Component, hostname string, fn func(geneos.Instance, []string) error, args []string, params []string) (err error)

ForAll calls the supplied function for each matching instance. It prints any returned error on STDOUT and the only error returned is os.ErrNotExist if there are no matching instances.

func ForAllWithResults added in v1.4.1

func ForAllWithResults(ct *geneos.Component, fn func(geneos.Instance, []string) (interface{}, error), args []string, params []string) (results []interface{}, err error)

ForAllWithResults calls the given function for each matching instance and gather the return values into a slice of interfaces for handling upstream. Errors are printed on STDOUT for each call and the only error returned ErrNotExist if there are no matches.

func Get

func Get(ct *geneos.Component, name string) (c geneos.Instance, err error)

Get return an instance of component ct, and loads the config. It is an error if the config cannot be loaded.

func GetAll

func GetAll(r *geneos.Host, ct *geneos.Component) (confs []geneos.Instance)

GetAll returns a slice of instances for a given component type on remote r

func GetPID

func GetPID(c geneos.Instance) (pid int, err error)

GetPID returns the PID of the process running for the instance. If not found then an err of os.ErrProcessDone is returned.

The process is identified by checking the conventions used to start Geneos processes.

the component type must be part of the basename of the executable and the component name must be on the command line as an exact and standalone args

walk the /proc directory (local or remote) and find the matching pid. This is subject to races, but not much we can do

func GetPIDInfo

func GetPIDInfo(c geneos.Instance) (pid int, uid uint32, gid uint32, mtime time.Time, err error)

func GetPorts

func GetPorts(r *geneos.Host) (ports map[uint16]*geneos.Component)

GetPorts gets all used ports in config files on a specific remote this will not work for ports assigned in component config files, such as gateway setup or netprobe collection agent

returns a map

func ImportCommons

func ImportCommons(r *geneos.Host, ct *geneos.Component, common string, params []string) (filename string, err error)

func ImportFile

func ImportFile(h *geneos.Host, dir string, source string, options ...geneos.Options) (filename string, err error)

ImportFile

func IsA added in v1.5.0

func IsA(c geneos.Instance, name string) bool

IsA returns true if instance c has a type that is component if the type name.

func IsDisabled

func IsDisabled(c geneos.Instance) bool

IsDisabled returns true if the instance c is disabled.

func IsProtected

func IsProtected(c geneos.Instance) bool

IsProtected returns true if instance c is marked protected

func IsRunning added in v1.5.0

func IsRunning(c geneos.Instance) bool

IsRunning returns true if the instance is running

func LoadConfig

func LoadConfig(c geneos.Instance) (err error)

LoadConfig will load the JSON config file if available, otherwise try to load the "legacy" .rc file

support cache?

error check core values - e.g. Name

func LogFile

func LogFile(c geneos.Instance) (logfile string)

LogFile returns the fulle path to the log file for the instance.

XXX logdir = LogD relative to Home or absolute

func Match

func Match(ct *geneos.Component, name string) (c geneos.Instance, err error)

Match looks for exactly one matching instance across types and hosts returns Invalid Args if zero of more than 1 match

func MatchAll

func MatchAll(ct *geneos.Component, name string) (c []geneos.Instance)

MatchAll constructs and returns a slice of instances that have a matching name

func MatchKeyValue

func MatchKeyValue(h *geneos.Host, ct *geneos.Component, key, value string) (confs []geneos.Instance)

MatchKeyValue returns a slice of instances where the instance configuration key matches the value given.

func Migrate

func Migrate(c geneos.Instance) (err error)

Migrate is a helper that checks if the configuration was loaded from a legacy .rc file and if it has it then saves the current configuration (it does not convert the .rc file) in a new format file and renames the .rc file to .rc.orig to allow Revert to work.

func NextPort

func NextPort(r *geneos.Host, ct *geneos.Component) uint16

given a range, find the first unused port

range is comma or two-dot separated list of single number, e.g. "7036" min-max inclusive range, e.g. "7036-8036" start- open ended range, e.g. "7041-"

some limits based on https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers

not concurrency safe at this time

func ReadCert

func ReadCert(c geneos.Instance) (cert *x509.Certificate, valid bool, err error)

ReadCert reads the instance certificate

func ReadKey

func ReadKey(c geneos.Instance) (key *memguard.Enclave, err error)

ReadKey reads the instance RSA private key

func ReadRootCert

func ReadRootCert(tlsDir string) (cert *x509.Certificate, err error)

ReadRootCert reads the root certificate from the installation directory

func ReadSigningCert

func ReadSigningCert(tlsDir string) (cert *x509.Certificate, err error)

ReadSigningCert reads the signing certificate from the installation directory

func RemovePaths

func RemovePaths(c geneos.Instance, paths string) (err error)

RemovePaths removes all files and directories in paths, each file or directory is separated by ListSeperator

func ReservedName

func ReservedName(name string) (ok bool)

ReservedName returns true if in name a reserved word. Reserved names are checked against all the values registered by components at start-up.

func SetDefaults

func SetDefaults(c geneos.Instance, name string) (err error)

SetDefaults is a common function called by component factory functions to iterate over the component specific instance struct and set the defaults as defined in the 'defaults' struct tags.

func SetEnvs added in v1.5.0

func SetEnvs(c geneos.Instance, envs []string) (changed bool)

SetEnvs takes a slice of KEY=VALUE pairs and applies them to the configuration key "envs" for instance c

func SetExtendedValues added in v1.5.0

func SetExtendedValues(c geneos.Instance, x ExtraConfigValues) (changed bool)

SetExtendedValues applies the settings in x to instance c by iterating through the fields and calling the appropriate helper function

XXX abstract this for a general case

func SetSecureArgs

func SetSecureArgs(c geneos.Instance) (args []string)

SetSecureArgs returns a slice of arguments to enable secure connections if the correct configuration values are set. These command line options are common to all core Geneos components except the gateway, which is special-cased

func SetSlice added in v1.5.0

func SetSlice(c geneos.Instance, items []string, setting string, key func(string) string) (changed bool)

SetSlice sets items in the instance configuration key setting. The key function returns an identifier to use in merge comparisons

func SharedPath added in v1.5.0

func SharedPath(c geneos.Instance, subs ...interface{}) string

SharedPath returns the full path a directory or file in the instances component type shared directory joined to any parts subs - the last element can be a filename. If the instance is not loaded then "." is returned for the current directory.

func Signal

func Signal(c geneos.Instance, signal syscall.Signal) (err error)

Signal sends the signal to the instance

func Sockets added in v1.4.1

func Sockets(c geneos.Instance) (links map[int]int)

Sockets returns a map[int]int of file descriptor to socket inode for all open files for the process running as the instance. An empty map is returned if the process cannot be found.

func SplitName

func SplitName(in string, defaultHost *geneos.Host) (ct *geneos.Component, name string, h *geneos.Host)

SplitName returns the parts of an instance name given an instance name in the format [TYPE:]NAME[@HOST] and a default host, return a *geneos.Component for the TYPE if given, a string for the NAME and a *geneos.Host - the latter being either from the name or the default provided

func Start

func Start(c geneos.Instance) (err error)

Start runs the instance.

func Stop

func Stop(c geneos.Instance, force, kill bool) (err error)

Stop an instance

func TCPListenPorts added in v1.4.3

func TCPListenPorts(c geneos.Instance) (ports []int)

TCPListenPorts returns all TCP ports currently open for the process running as the instance. An empty slice is returned if the process cannot be found. The instance may be on a remote host.

func UnsetMap added in v1.5.0

func UnsetMap(c geneos.Instance, key string, items UnsetCmdValues) (changed bool)

func UnsetMapHex added in v1.5.0

func UnsetMapHex(c geneos.Instance, key string, items UnsetCmdHexKeyed) (changed bool)

func UnsetSlice added in v1.5.0

func UnsetSlice(c geneos.Instance, key string, items []string, cmp func(string, string) bool) (changed bool)

func UnsetValues added in v1.5.0

func UnsetValues(c geneos.Instance, x UnsetConfigValues) (changed bool, err error)

XXX abstract this for a general case

func ValidInstanceName

func ValidInstanceName(name string) (ok bool)

ValidInstanceName returns true if name is considered a valid instance name. It is not checked against the list of reserved names.

XXX used to consume instance names until parameters are then passed down

func Version

func Version(c geneos.Instance) (base string, version string, err error)

Version returns the base package name and the underlying package version for the instance c. If base is not a link, then base is also returned as the symlink. If there are more than 10 levels of symlink then return symlink set to "loop-detected" and err set to syscall.ELOOP to prevent infinite loops.

func WriteCert

func WriteCert(c geneos.Instance, cert *x509.Certificate) (err error)

WriteCert writes the certificate for the instance c

func WriteConfigValues

func WriteConfigValues(c geneos.Instance, values map[string]interface{}) (err error)

WriteConfigValues writes the given values to the configuration file for instance c. It does not merge values with the existing configuration values.

func WriteKey

func WriteKey(c geneos.Instance, key *memguard.Enclave) (err error)

WriteKey writes the key for the instance c

Types

type AttributeValues added in v1.5.0

type AttributeValues []string

attribute - name=value

func (*AttributeValues) Set added in v1.5.0

func (i *AttributeValues) Set(value string) error

func (*AttributeValues) String added in v1.5.0

func (i *AttributeValues) String() string

func (*AttributeValues) Type added in v1.5.0

func (i *AttributeValues) Type() string

type EnvValues added in v1.5.0

type EnvValues []string

env NAME=VALUE - string slice

func (*EnvValues) Set added in v1.5.0

func (i *EnvValues) Set(value string) error

func (*EnvValues) String added in v1.5.0

func (i *EnvValues) String() string

func (*EnvValues) Type added in v1.5.0

func (i *EnvValues) Type() string

type ExtraConfigValues added in v1.5.0

type ExtraConfigValues struct {
	Includes   IncludeValues
	Gateways   GatewayValues
	Attributes AttributeValues
	Envs       EnvValues
	Variables  VarValues
	Types      TypeValues
}

ExtraConfigValues defined the set of non-simple configuration options that can be accepted by various commands

type GatewayValues added in v1.5.0

type GatewayValues map[string]string

gateway - name:port

func (*GatewayValues) Set added in v1.5.0

func (i *GatewayValues) Set(value string) error

func (*GatewayValues) String added in v1.5.0

func (i *GatewayValues) String() string

func (*GatewayValues) Type added in v1.5.0

func (i *GatewayValues) Type() string

type IncludeValues added in v1.5.0

type IncludeValues map[string]string

IncludeValues is a map of include file priority to path include file - priority:url|path

func (*IncludeValues) Set added in v1.5.0

func (i *IncludeValues) Set(value string) error

func (*IncludeValues) String added in v1.5.0

func (i *IncludeValues) String() string

String is the string method for the IncludeValues type

func (*IncludeValues) Type added in v1.5.0

func (i *IncludeValues) Type() string

type Instance

type Instance struct {
	geneos.Instance `json:"-"`
	L               *sync.RWMutex     `json:"-"`
	Conf            *config.Config    `json:"-"`
	InstanceHost    *geneos.Host      `json:"-"`
	Component       *geneos.Component `json:"-"`
	ConfigLoaded    bool              `json:"-"`
	Env             []string          `json:",omitempty"`
}

The Instance type is the common data shared by all instance / component types

type OpenFiles added in v1.4.3

type OpenFiles struct {
	Path   string
	Stat   fs.FileInfo
	FD     string
	FDMode fs.FileMode
}

type TypeValues added in v1.5.0

type TypeValues []string

attribute - name=value

func (*TypeValues) Set added in v1.5.0

func (i *TypeValues) Set(value string) error

func (*TypeValues) String added in v1.5.0

func (i *TypeValues) String() string

func (*TypeValues) Type added in v1.5.0

func (i *TypeValues) Type() string

type UnsetCmdHexKeyed added in v1.5.0

type UnsetCmdHexKeyed []string

func (*UnsetCmdHexKeyed) Set added in v1.5.0

func (i *UnsetCmdHexKeyed) Set(value string) error

func (*UnsetCmdHexKeyed) String added in v1.5.0

func (i *UnsetCmdHexKeyed) String() string

func (*UnsetCmdHexKeyed) Type added in v1.5.0

func (i *UnsetCmdHexKeyed) Type() string

type UnsetCmdValues added in v1.5.0

type UnsetCmdValues []string

unset Var flags take just the key, either a name or a priority for include files

func (*UnsetCmdValues) Set added in v1.5.0

func (i *UnsetCmdValues) Set(value string) error

func (*UnsetCmdValues) String added in v1.5.0

func (i *UnsetCmdValues) String() string

func (*UnsetCmdValues) Type added in v1.5.0

func (i *UnsetCmdValues) Type() string

type UnsetConfigValues added in v1.5.0

type UnsetConfigValues struct {
	Keys       UnsetCmdValues
	Includes   UnsetCmdValues
	Gateways   UnsetCmdValues
	Attributes UnsetCmdValues
	Envs       UnsetCmdValues
	Variables  UnsetCmdHexKeyed
	Types      UnsetCmdValues
}

type VarValue added in v1.5.0

type VarValue struct {
	Type  string
	Name  string
	Value string
}

variables - [TYPE:]NAME=VALUE

func GetVarValue added in v1.5.0

func GetVarValue(in string) (key string, value VarValue)

type VarValues added in v1.5.0

type VarValues map[string]VarValue

func (*VarValues) Set added in v1.5.0

func (i *VarValues) Set(value string) error

func (*VarValues) String added in v1.5.0

func (i *VarValues) String() string

func (*VarValues) Type added in v1.5.0

func (i *VarValues) Type() string

Directories

Path Synopsis
Package ac2 supports installation and control of the Active Console
Package ac2 supports installation and control of the Active Console

Jump to

Keyboard shortcuts

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