global

package
v0.0.0-...-c3423aa Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package global is the package for EaseProbe

Index

Constants

View Source
const (
	// Org is the organization
	Org = "MegaEase"
	// DefaultProg is the program name
	DefaultProg = "EaseProbe"
	// DefaultIconURL is the default icon which used in Slack or Discord
	DefaultIconURL = "https://megaease.com/favicon.png"
)
View Source
const (
	// DefaultRetryTimes is 3 times
	DefaultRetryTimes = 3
	// DefaultRetryInterval is 5 seconds
	DefaultRetryInterval = time.Second * 5
	// DefaultTimeFormat is "2006-01-02 15:04:05 Z0700"
	DefaultTimeFormat = "2006-01-02 15:04:05 Z0700"
	// DefaultTimeZone is "UTC"
	DefaultTimeZone = "UTC"
	// DefaultProbeInterval is 1 minutes
	DefaultProbeInterval = time.Second * 60
	// DefaultTimeOut is 30 seconds
	DefaultTimeOut = time.Second * 30
	// DefaultChannelName  is the default wide channel name
	DefaultChannelName = "__EaseProbe_Channel__"
	// DefaultStatusChangeThresholdSetting is the threshold of status change
	DefaultStatusChangeThresholdSetting = 1
	// DefaultNotificationStrategy is the default notify strategy
	DefaultNotificationStrategy = RegularStrategy
	// DefaultMaxNotificationTimes is the default max notification times
	DefaultMaxNotificationTimes = 1
	// DefaultNotificationFactor is the default notification factor
	DefaultNotificationFactor = 1
	// DefaultConfigFileCheckInterval is the default config file checking interval
	DefaultConfigFileCheckInterval = time.Second * 5
)
View Source
const (
	// DefaultHTTPServerIP is the default ip of the HTTP server
	DefaultHTTPServerIP = "0.0.0.0"
	// DefaultHTTPServerPort is the default port of the HTTP server
	DefaultHTTPServerPort = "8181"
	// DefaultPageSize is the default page size
	DefaultPageSize = 100
	// DefaultAccessLogFile is the default access log file name
	DefaultAccessLogFile = "access.log"
	// DefaultDataFile is the default data file name
	DefaultDataFile = "data/data.yaml"
	// DefaultPIDFile is the default pid file name
	DefaultPIDFile = "easeprobe.pid"
)
View Source
const (
	// DefaultMaxLogSize is the default max log size
	DefaultMaxLogSize = 10 // 10M
	// DefaultMaxLogAge is the default max log age
	DefaultMaxLogAge = 7 // 7 days
	// DefaultMaxBackups is the default backup file number
	DefaultMaxBackups = 5 // file
	// DefaultLogCompress is the default compress log
	DefaultLogCompress = true
)

Variables

View Source
var (
	// Ver is the program version
	// It will be set by the build script
	// go build -ldflags "-X github.com/megaease/easegress/pkg/global.Ver=1.0.0"
	Ver = "v1.7.0"
	//OrgProg combine organization and program
	OrgProg = Org + " " + DefaultProg
	//OrgProgVer combine organization and program and version
	OrgProgVer = Org + " " + DefaultProg + "/" + Ver
)

Functions

func CommandLine

func CommandLine(cmd string, args []string) string

CommandLine will return the whole command line which includes command and all arguments

func DoRetry

func DoRetry(kind, name, tag string, r Retry, fn func() error) error

DoRetry is a help function to retry the function if it returns error

func EnumMarshalJSON

func EnumMarshalJSON[T comparable](m map[T]string, v T, typename string) ([]byte, error)

EnumMarshalJSON is a help function to marshal the enum to JSON

func EnumMarshalYaml

func EnumMarshalYaml[T comparable](m map[T]string, v T, typename string) (interface{}, error)

EnumMarshalYaml is a help function to marshal the enum to yaml

func EnumUnmarshalJSON

func EnumUnmarshalJSON[T comparable](b []byte, m map[string]T, v *T, init T, typename string) error

EnumUnmarshalJSON is a help function to unmarshal the enum from JSON

func EnumUnmarshalYaml

func EnumUnmarshalYaml[T comparable](unmarshal func(interface{}) error, m map[string]T, v *T, init T, typename string) error

EnumUnmarshalYaml is a help function to unmarshal the enum from yaml

func EscapeQuote

func EscapeQuote(str string) string

EscapeQuote escape the string the single quote, double quote, and backtick

func FooterString

func FooterString() string

FooterString return the footer string e.g. "EaseProbe v1.0.0 @ localhost"

func GetTimeFormat

func GetTimeFormat() string

GetTimeFormat return the time format

func GetTimeLocation

func GetTimeLocation() *time.Location

GetTimeLocation return the time zone

func GetWorkDir

func GetWorkDir() string

GetWorkDir return the current working directory

func InitEaseProbe

func InitEaseProbe(name, icon string)

InitEaseProbe the EaseProbe

func InitEaseProbeWithTime

func InitEaseProbeWithTime(name, icon, tf, tz string)

InitEaseProbeWithTime init the EaseProbe with time

func MakeDirectory

func MakeDirectory(filename string) string

MakeDirectory return the writeable filename

func ReverseMap

func ReverseMap[K comparable, V comparable](m map[K]V) map[V]K

ReverseMap just reverse the map from [key, value] to [value, key]

func SetTimeFormat

func SetTimeFormat(tf string)

SetTimeFormat set the time format

func SetTimeZone

func SetTimeZone(tz string)

SetTimeZone set the time zone

Types

type EaseProbe

type EaseProbe struct {
	Name       string         `yaml:"name"`
	IconURL    string         `yaml:"icon"`
	Version    string         `yaml:"version"`
	Host       string         `yaml:"host"`
	TimeFormat string         `yaml:"time_format"`
	TimeZone   string         `yaml:"time_zone"`
	TimeLoc    *time.Location `yaml:"-"`
}

EaseProbe is the information of the program

func GetEaseProbe

func GetEaseProbe() *EaseProbe

GetEaseProbe return the EaseProbe

type ErrNoRetry

type ErrNoRetry struct {
	Message string
}

ErrNoRetry is the error need not retry

func (*ErrNoRetry) Error

func (e *ErrNoRetry) Error() string

type IntervalStrategy

type IntervalStrategy int

IntervalStrategy is the notification strategy

const (
	UnknownStrategy     IntervalStrategy = iota
	RegularStrategy                      // the same period of time between each notification
	IncrementStrategy                    // the period of time between each notification is increased by a fixed value
	ExponentialStrategy                  // the period of time between each notification is increased exponentially
)

The notification strategy enum

func (*IntervalStrategy) IntervalStrategy

func (n *IntervalStrategy) IntervalStrategy(s string)

IntervalStrategy returns the IntervalStrategy value of the string

func (IntervalStrategy) MarshalJSON

func (n IntervalStrategy) MarshalJSON() ([]byte, error)

MarshalJSON is marshal the NotificationIntervalStrategy.

func (IntervalStrategy) MarshalYAML

func (n IntervalStrategy) MarshalYAML() (interface{}, error)

MarshalYAML is marshal the IntervalStrategy.

func (IntervalStrategy) String

func (n IntervalStrategy) String() string

String returns the string value of the NotificationIntervalStrategy

func (*IntervalStrategy) UnmarshalJSON

func (n *IntervalStrategy) UnmarshalJSON(data []byte) error

UnmarshalJSON is unmarshal the NotificationIntervalStrategy.

func (*IntervalStrategy) UnmarshalYAML

func (n *IntervalStrategy) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML is unmarshal the IntervalStrategy.

type NotificationStrategySettings

type NotificationStrategySettings struct {
	Strategy IntervalStrategy `` /* 226-byte string literal not displayed */
	Factor   int              `` /* 138-byte string literal not displayed */
	MaxTimes int              `yaml:"max" json:"max" jsonschema:"title=Max Times,description=the max times to send notification,default=1"`
}

NotificationStrategySettings is the notification strategy settings

type NotifySettings

type NotifySettings struct {
	TimeFormat string
	Timeout    time.Duration
	Retry      Retry
}

NotifySettings is the global notification setting

func (*NotifySettings) NormalizeRetry

func (n *NotifySettings) NormalizeRetry(retry Retry) Retry

NormalizeRetry return a normalized retry value

func (*NotifySettings) NormalizeTimeOut

func (n *NotifySettings) NormalizeTimeOut(t time.Duration) time.Duration

NormalizeTimeOut return a normalized timeout value

type ProbeSettings

type ProbeSettings struct {
	Interval time.Duration
	Timeout  time.Duration
	StatusChangeThresholdSettings
	NotificationStrategySettings
}

ProbeSettings is the global probe setting

func (*ProbeSettings) NormalizeInterval

func (p *ProbeSettings) NormalizeInterval(t time.Duration) time.Duration

NormalizeInterval return a normalized time interval value

func (*ProbeSettings) NormalizeNotificationStrategy

func (p *ProbeSettings) NormalizeNotificationStrategy(t NotificationStrategySettings) NotificationStrategySettings

NormalizeNotificationStrategy return a normalized notification strategy value

func (*ProbeSettings) NormalizeThreshold

NormalizeThreshold return a normalized threshold value

func (*ProbeSettings) NormalizeTimeOut

func (p *ProbeSettings) NormalizeTimeOut(t time.Duration) time.Duration

NormalizeTimeOut return a normalized timeout value

type Retry

type Retry struct {
	Times    int           `yaml:"times" json:"times,omitempty" jsonschema:"title=Retry Times,description=how many times need to retry,minimum=1"`
	Interval time.Duration `` /* 147-byte string literal not displayed */
}

Retry is the settings of retry

type StatusChangeThresholdSettings

type StatusChangeThresholdSettings struct {
	// the failures threshold such as 2, 5
	Failure int `` /* 162-byte string literal not displayed */
	// the success threshold such as 2, 5
	Success int `` /* 161-byte string literal not displayed */
}

StatusChangeThresholdSettings is the settings for probe threshold

type TLS

type TLS struct {
	CA       string `yaml:"ca" json:"ca,omitempty" jsonschema:"title=CA File,description=the CA file path"`
	Cert     string `yaml:"cert" json:"cert,omitempty" jsonschema:"title=Cert File,description=the Cert file path"`
	Key      string `yaml:"key" json:"key,omitempty" jsonschema:"title=Key File,description=the Key file path"`
	Insecure bool   `yaml:"insecure" json:"insecure,omitempty" jsonschema:"title=Insecure,description=whether to skip the TLS verification"`
}

TLS is the configuration for TLS files

func (*TLS) Config

func (t *TLS) Config() (*tls.Config, error)

Config return a tls.Config object

Jump to

Keyboard shortcuts

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