instance

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2023 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

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

given a filename or path, prepend the instance home directory if not absolute, and clean

func AllNames

func AllNames(h *host.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 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, options ...geneos.GeneosOptions) (err error)

func CompareVersion added in v1.4.1

func CompareVersion(version1, version2 string) int

CompareVersion takes two Geneos package versions and returns an int that is 0 if they are identical, negative if version1 < version2 and positive is version1 > version2. If the version is prefixed with non numeric values then "GA" is always greater thn "RA" (general versus restricted availability) for the same numeric version, otherwise a lexical comparison is done on the prefixes.

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)

func ConfigFileTypes added in v1.4.1

func ConfigFileTypes() []string

func CopyInstance

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

func CreateCert

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

create a new certificate for an instance

this also creates a new private key

skip if certificate exists (no expiry check)

func CreateCertKey

func CreateCertKey(template, parent *x509.Certificate, parentKey *rsa.PrivateKey, existingKey *rsa.PrivateKey) (cert *x509.Certificate, key *rsa.PrivateKey, err error)

wrapper to create a new certificate given the sign cert and private key and an optional private key to (re)use for the created certificate itself. returns a certificate and private key

func CreateConfigFromTemplate

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

load 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 DisplayName

func DisplayName(c geneos.Instance) string

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, 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)

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

func GetAll

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

return a slice of instances for a given component type

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 int64, err error)

func GetPorts

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

get 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 *host.Host, ct *geneos.Component, common string, params []string) (filename string, err error)

func ImportFile

func ImportFile(h *host.Host, home string, user string, source string, options ...geneos.GeneosOptions) (filename string, err error)

func IsDisabled

func IsDisabled(c geneos.Instance) bool

func IsProtected

func IsProtected(c geneos.Instance) bool

func LoadConfig

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

loadConfig will load the JSON config file is 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)

logdir = LogD relative to Home or absolute

func Match

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

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)

construct and return a slice of a/all component types that have a matching name

func MatchKeyValue

func MatchKeyValue(h *host.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 config from .rc to .json, but check first

func NextPort

func NextPort(r *host.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, err error)

read the instance certificate

func ReadConfig

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

ReadConfig reads the instance configuration from the standard file for that instance type. First try the preferred file type and if that fails loop through all types and if they all fail then try the legacy file.

func ReadKey

func ReadKey(c geneos.Instance) (key *rsa.PrivateKey, err error)

read the instance RSA private key

func ReadRootCert

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

read the rootCA certificate from the installation directory

func ReadSigningCert

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

read the signing certificate from the installation directory

func RemovePaths

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

given a pathlist (typically ':') seperated list of paths, remove all files and directories

func ReservedName

func ReservedName(in string) (ok bool)

separate reserved words and invalid syntax

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 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 Signal

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

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 *host.Host) (ct *geneos.Component, name string, h *host.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 *host.Host - the latter being either from the name or the default provided

func Start

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

func Stop

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

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 ValidInstanceName

func ValidInstanceName(in string) (ok bool)

return true while a string is considered a valid instance name

used to consume instance names until parameters are then passed down

func Version

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

Version returns the base package name and the version it links to. If base is not a link, then symlink is returned the same as base. 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)

func WriteConfig

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

WriteConfig writes out the existing configuration for 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 *rsa.PrivateKey) (err error)

Types

type Instance

type Instance struct {
	geneos.Instance `json:"-"`
	L               *sync.RWMutex     `json:"-"`
	Conf            *config.Config    `json:"-"`
	InstanceHost    *host.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
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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