utils

package
v0.0.0-...-57116ba Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BYTE = 1 << (10 * iota)
	KILOBYTE
	MEGABYTE
	GIGABYTE
	TERABYTE
)

Variables

View Source
var ExtraLabelNames, ExtraLabelValues []string

Functions

func SpectrumLogger

func SpectrumLogger() *log.Logger

func ToBool

func ToBool(s string) (float64, error)

ToBool parses a string formatted to bool, but prometheus only accepts float64 formatted data, so this function retuns float64 formatted.

func ToBytes

func ToBytes(s string) (uint64, error)

ToBytes parses a string formatted by ByteSize as bytes. Note binary-prefixed and SI prefixed units both mean a base-2 units KB = K = KiB = 1024 MB = M = MiB = 1024 * K GB = G = GiB = 1024 * M TB = T = TiB = 1024 * G

Types

type AuthToken

type AuthToken struct {
	Token      string
	Hostname   string
	UpdateTime time.Time
}

type Config

type Config struct {
	Targets         []Target        `yaml:"targets"`
	ExtraLabels     []Label         `yaml:"extra_labels"`
	TlsServerConfig TlsServerConfig `yaml:"tls_server_config"`
	// contains filtered or unexported fields
}

func GetConfig

func GetConfig(filename string) (*Config, error)

func (*Config) SetFilename

func (cfg *Config) SetFilename(filename string)

type Counter

type Counter struct {
	AuthTokenRenewIntervalSeconds int
	AuthTokenRenewSuccessCount    int
	AuthTokenRenewFailureCount    int
}

type Label

type Label struct {
	Name  string `yaml:"name"`
	Value string `yaml:"value"`
}

type SpectrumClient

type SpectrumClient struct {
	UserName       string
	Password       string
	IpAddress      string
	ErrorCount     float64
	Hostname       string
	VerifyCert     bool
	AuthTokenCache *AuthToken
	AuthTokenMutex *sync.Mutex
	ColCounter     *Counter //shared cross all SpectrumClients of a target
}

func (*SpectrumClient) CallSpectrumAPI

func (s *SpectrumClient) CallSpectrumAPI(restCmd string, autoRenewToken bool) (body string, err error)

func (*SpectrumClient) RenewAuthToken

func (s *SpectrumClient) RenewAuthToken(needVerify bool) (Counter, int)

type Target

type Target struct {
	IpAddress  string `yaml:"ipAddress"`
	Userid     string `yaml:"userid"`
	Password   string `yaml:"password"`
	VerifyCert bool   `yaml:"VerifyCert"`
}

type TlsServerConfig

type TlsServerConfig struct {
	CaCert     string `yaml:"ca_cert"`
	ServerCert string `yaml:"server_cert"`
	ServerKey  string `yaml:"server_key"`
}

Jump to

Keyboard shortcuts

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