dialtesting

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 48 Imported by: 0

Documentation

Overview

Package dialtesting defined dialtesting tasks and task implements.

Index

Constants

View Source
const (
	DefaultGRPCTimeout     = 30 * time.Second
	HealthCheckServiceName = "grpc.health.v1.Health"
	HealthCheckMethodName  = "Check"
)
View Source
const (
	MaxBodySize        = 10 * 1024
	DefaultHTTPTimeout = 60 * time.Second
)
View Source
const (
	PingTimeout    = 3 * time.Second
	DefaultICMPTTL = 64
)
View Source
const (
	StatusStop = "stop"

	ClassHTTP      = "HTTP"
	ClassTCP       = "TCP"
	ClassWebsocket = "WEBSOCKET"
	ClassICMP      = "ICMP"
	ClassGRPC      = "GRPC"
	ClassDNS       = "DNS"
	ClassHeadless  = "BROWSER"
	ClassOther     = "OTHER"
	ClassWait      = "WAIT"
	ClassMulti     = "MULTI"

	ScheduleTypeCron      = "crontab"
	ScheduleTypeFrequency = "frequency"
)
View Source
const (
	MaxTimeout = 10 * time.Second
	MaxHops    = 60
	MaxRetry   = 3
)
View Source
const MaxErrorMessageSize = 1024

Variables

View Source
var (
	MaxMsgSize       = 100 * 1024
	ICMPConcurrentCh chan struct{}
)
View Source
var TypeVariableGlobal = "global"

Functions

func IsEnabledTraceroute

func IsEnabledTraceroute(enabled bool) bool

IsEnabledTraceroute return true when traceroute enabled and not windows.

func Setup

func Setup(c *TaskConfig)

Types

type ConfigVar

type ConfigVar struct {
	ID      string `json:"id,omitempty"`
	Type    string `json:"type,omitempty"`
	Name    string `json:"name"`
	Value   string `json:"value,omitempty"`
	Example string `json:"example,omitempty"`
	Secure  bool   `json:"secure"`
}

type DialResult

type DialResult struct {
	Success bool
	Reasons []string
}

type GRPCAdvanceOption

type GRPCAdvanceOption struct {
	RequestOptions *GRPCOptRequest     `json:"request_options,omitempty"`
	Certificate    *GRPCOptCertificate `json:"certificate,omitempty"`
	Secret         *GRPCSecret         `json:"secret,omitempty"`
}

type GRPCHealthCheckDiscovery

type GRPCHealthCheckDiscovery struct {
	Service string `json:"service,omitempty"`
}

type GRPCOptCertificate

type GRPCOptCertificate struct {
	IgnoreServerCertificateError bool   `json:"ignore_server_certificate_error,omitempty"`
	PrivateKey                   string `json:"private_key,omitempty"`
	Certificate                  string `json:"certificate,omitempty"`
	CaCert                       string `json:"ca,omitempty"`
}

type GRPCOptRequest

type GRPCOptRequest struct {
	Metadata       map[string]string         `json:"metadata,omitempty"`
	RequestTimeout string                    `json:"request_timeout,omitempty"`
	ProtoFiles     *GRPCProtoFilesDiscovery  `json:"proto_files,omitempty"`
	Reflection     *GRPCReflectionDiscovery  `json:"reflection,omitempty"`
	HealthCheck    *GRPCHealthCheckDiscovery `json:"health_check,omitempty"`
}

type GRPCProtoFilesDiscovery

type GRPCProtoFilesDiscovery struct {
	ProtoFiles  map[string]string `json:"protofiles"`
	FullMethod  string            `json:"full_method"`
	JSONRequest string            `json:"request,omitempty"`
}

type GRPCReflectionDiscovery

type GRPCReflectionDiscovery struct {
	FullMethod  string `json:"full_method"`
	JSONRequest string `json:"request,omitempty"`
}

type GRPCSecret

type GRPCSecret struct {
	NoSaveResponseBody bool `json:"not_save,omitempty"`
}

type GRPCSuccess

type GRPCSuccess struct {
	Body         []*SuccessOption `json:"body,omitempty"`
	ResponseTime string           `json:"response_time,omitempty"`
	// contains filtered or unexported fields
}

type GRPCTask

type GRPCTask struct {
	*Task
	Server           string             `json:"server"`
	PostScript       string             `json:"post_script,omitempty"`
	SuccessWhenLogic string             `json:"success_when_logic"`
	SuccessWhen      []*GRPCSuccess     `json:"success_when"`
	AdvanceOptions   *GRPCAdvanceOption `json:"advance_options,omitempty"`
	// contains filtered or unexported fields
}

type HTTPAdvanceOption

type HTTPAdvanceOption struct {
	RequestOptions *HTTPOptRequest     `json:"request_options,omitempty"`
	RequestBody    *HTTPOptBody        `json:"request_body,omitempty"`
	Certificate    *HTTPOptCertificate `json:"certificate,omitempty"`
	Proxy          *HTTPOptProxy       `json:"proxy,omitempty"`
	Secret         *HTTPSecret         `json:"secret,omitempty"`
	RequestTimeout string              `json:"request_timeout,omitempty"`
}

type HTTPOptAuth

type HTTPOptAuth struct {
	// basic auth
	Username string `json:"username,omitempty"`
	Password string `json:"password,omitempty"`
}

type HTTPOptBody

type HTTPOptBody struct {
	BodyType string            `json:"body_type,omitempty"`
	Body     string            `json:"body,omitempty"`
	Files    []HTTPOptBodyFile `json:"files,omitempty"`
	Form     map[string]string `json:"form,omitempty"`
	// contains filtered or unexported fields
}

type HTTPOptBodyFile

type HTTPOptBodyFile struct {
	Name             string `json:"name"`                // field name
	Content          string `json:"content"`             // file content in base64
	Type             string `json:"type"`                // file type, e.g. image/jpeg
	Size             int64  `json:"size"`                // Content size
	Encoding         string `json:"encoding"`            // Content encoding, base64 only
	OriginalFileName string `json:"original_file_name"`  // Original file name
	FilePath         string `json:"file_path,omitempty"` // file path in storage

	Hash string `json:"_"`
}

type HTTPOptCertificate

type HTTPOptCertificate struct {
	IgnoreServerCertificateError bool   `json:"ignore_server_certificate_error,omitempty"`
	PrivateKey                   string `json:"private_key,omitempty"`
	Certificate                  string `json:"certificate,omitempty"`
	CaCert                       string `json:"ca,omitempty"`
}

type HTTPOptProxy

type HTTPOptProxy struct {
	URL     string            `json:"url,omitempty"`
	Headers map[string]string `json:"headers,omitempty"`
}

type HTTPOptRequest

type HTTPOptRequest struct {
	FollowRedirect bool              `json:"follow_redirect,omitempty"`
	Headers        map[string]string `json:"headers,omitempty"`
	Cookies        string            `json:"cookies,omitempty"`
	Auth           *HTTPOptAuth      `json:"auth,omitempty"`
}

type HTTPSecret

type HTTPSecret struct {
	NoSaveResponseBody bool `json:"not_save,omitempty"`
}

type HTTPSuccess

type HTTPSuccess struct {
	Body []*SuccessOption `json:"body,omitempty"`

	ResponseTime string `json:"response_time,omitempty"`

	Header     map[string][]*SuccessOption `json:"header,omitempty"`
	StatusCode []*SuccessOption            `json:"status_code,omitempty"`
	// contains filtered or unexported fields
}

type HTTPTask

type HTTPTask struct {
	*Task
	URL              string             `json:"url"`
	Method           string             `json:"method"`
	PostScript       string             `json:"post_script,omitempty"`
	SuccessWhenLogic string             `json:"success_when_logic"`
	SuccessWhen      []*HTTPSuccess     `json:"success_when"`
	AdvanceOptions   *HTTPAdvanceOption `json:"advance_options,omitempty"`
	// contains filtered or unexported fields
}

type ICMP

type ICMP struct {
	Type        uint8
	Code        uint8
	Checksum    uint16
	Identifier  uint16
	SequenceNum uint16
}

type ICMPSuccess

type ICMPSuccess struct {
	PacketLossPercent []*ValueSuccess       `json:"packet_loss_percent,omitempty"`
	ResponseTime      []*ResponseTimeSucess `json:"response_time,omitempty"`
	Hops              []*ValueSuccess       `json:"hops,omitempty"`
	Packets           []*ValueSuccess       `json:"packets,omitempty"`
}

type ICMPTask

type ICMPTask struct {
	*Task
	Host             string            `json:"host"`
	PacketCount      int               `json:"packet_count"`
	Timeout          string            `json:"timeout"`
	EnableTraceroute bool              `json:"enable_traceroute"`
	TracerouteConfig *TracerouteOption `json:"traceroute_config"`
	SuccessWhen      []*ICMPSuccess    `json:"success_when"`
	SuccessWhenLogic string            `json:"success_when_logic"`
	// contains filtered or unexported fields
}

type ITask

type ITask interface {
	ID() string
	Status() string
	Run() error
	Clear()
	CheckResult() ([]string, bool)
	Class() string
	GetResults() (map[string]string, map[string]interface{})
	PostURLStr() string
	MetricName() string
	Stop()
	RegionName() string
	AccessKey() string
	Check() error
	CheckTask() error
	UpdateTimeUs() int64
	GetFrequency() string
	GetOwnerExternalID() string
	GetExternalID() string
	SetOwnerExternalID(string)
	GetLineData() string
	GetHostName() ([]string, error)
	GetWorkspaceLanguage() string
	GetDFLabel() string
	GetScheduleType() string
	GetCrontab() string

	SetOption(map[string]string)
	GetOption() map[string]string
	SetRegionID(string)
	SetAk(string)
	SetStatus(string)
	SetUpdateTime(int64)
	SetChild(TaskChild)
	SetTaskJSONString(string)
	GetTaskJSONString() string
	SetDisabled(uint8)

	GetVariableValue(Variable) (string, error)
	GetGlobalVars() []string
	RenderTemplateAndInit(globalVariables map[string]Variable) error
	AddExtractedVar(*ConfigVar)
	SetCustomVars([]*ConfigVar)
	GetPostScriptVars() Vars
	GetIsTemplate() bool
	SetIsTemplate(bool)
	SetBeforeRun(func(*Task) error)

	String() string
}

func NewTask

func NewTask(taskString string, task TaskChild) (ITask, error)

type MultiExtractedVar

type MultiExtractedVar struct {
	Name   string `json:"name"`
	Field  string `json:"field"`
	Secure bool   `json:"secure"`
	Value  string `json:"value,omitempty"`
}

type MultiStep

type MultiStep struct {
	Type          string              `json:"type"` // http or wait
	Name          string              `json:"name"` // name
	AllowFailure  bool                `json:"allow_failure"`
	Retry         *MultiStepRetry     `json:"retry"`
	TaskString    string              `json:"task,omitempty"`
	Value         int                 `json:"value,omitempty"` // wait seconds for wait task
	ExtractedVars []MultiExtractedVar `json:"extracted_vars,omitempty"`
	// contains filtered or unexported fields
}

type MultiStepRetry

type MultiStepRetry struct {
	Retry    int `json:"retry"`    // retry times
	Interval int `json:"interval"` // ms
}

type MultiTask

type MultiTask struct {
	*Task
	Steps []*MultiStep `json:"steps"`
	// contains filtered or unexported fields
}

type Packet

type Packet struct {
	ID  int
	Dst net.IP
	// contains filtered or unexported fields
}

Packet represent sent packet.

type Response

type Response struct {
	From         net.IP
	ResponseTime time.Duration
	// contains filtered or unexported fields
}

Response for sent packet, may be failed response when timeout.

type ResponseTimeSucess

type ResponseTimeSucess struct {
	Func   string `json:"func,omitempty"`
	Op     string `json:"op,omitempty"`
	Target string `json:"target,omitempty"`
	// contains filtered or unexported fields
}

type Route

type Route struct {
	Total   int          `json:"total"`
	Failed  int          `json:"failed"`
	Loss    float64      `json:"loss"`
	AvgCost float64      `json:"avg_cost"`
	MinCost float64      `json:"min_cost"`
	MaxCost float64      `json:"max_cost"`
	StdCost float64      `json:"std_cost"`
	Items   []*RouteItem `json:"items"`
}

Route is summary for each hop.

func TracerouteIP

func TracerouteIP(ip string, opt *TracerouteOption) (routes []*Route, err error)

type RouteItem

type RouteItem struct {
	IP           string  `json:"ip"`
	ResponseTime float64 `json:"response_time"`
}

RouteItem represent each retry response.

type ScriptGRPCMessage

type ScriptGRPCMessage struct {
	Response *ScriptGRPCRequestResponse `json:"response"`
	Vars     *Vars                      `json:"vars"`
}

type ScriptGRPCRequestResponse

type ScriptGRPCRequestResponse struct {
	Body string `json:"body"`
}

func (*ScriptGRPCRequestResponse) String

func (h *ScriptGRPCRequestResponse) String() (string, error)

type ScriptHTTPMessage

type ScriptHTTPMessage struct {
	Response *ScriptHTTPRequestResponse `json:"response"`
	Vars     *Vars                      `json:"vars"`
}

func (*ScriptHTTPMessage) String

func (m *ScriptHTTPMessage) String() (string, error)

type ScriptHTTPRequestResponse

type ScriptHTTPRequestResponse struct {
	Header     http.Header `json:"header"`
	Body       string      `json:"body"`
	StatusCode int         `json:"status_code"`
}

func (*ScriptHTTPRequestResponse) String

func (h *ScriptHTTPRequestResponse) String() (string, error)

type ScriptHTTPResult

type ScriptHTTPResult struct {
	IsFailed     bool   `json:"is_failed"`
	ErrorMessage string `json:"error_message"`
}

type ScriptResult

type ScriptResult struct {
	Result ScriptHTTPResult `json:"result"`
	Vars   Vars             `json:"vars"`
}

type SuccessOption

type SuccessOption struct {
	Is    string `json:"is,omitempty"`
	IsNot string `json:"is_not,omitempty"`

	MatchRegex    string `json:"match_regex,omitempty"`
	NotMatchRegex string `json:"not_match_regex,omitempty"`

	Contains    string `json:"contains,omitempty"`
	NotContains string `json:"not_contains,omitempty"`
	// contains filtered or unexported fields
}

type TCPResponseTime

type TCPResponseTime struct {
	IsContainDNS bool   `json:"is_contain_dns"`
	Target       string `json:"target"`
	// contains filtered or unexported fields
}

type TCPSuccess

type TCPSuccess struct {
	ResponseTime    []*TCPResponseTime `json:"response_time,omitempty"`
	Hops            []*ValueSuccess    `json:"hops,omitempty"`
	ResponseMessage []*SuccessOption   `json:"response_message,omitempty"`
}

type TCPTask

type TCPTask struct {
	*Task
	Host             string            `json:"host"`
	Port             string            `json:"port"`
	Message          string            `json:"message"`
	Timeout          string            `json:"timeout"`
	EnableTraceroute bool              `json:"enable_traceroute"`
	TracerouteConfig *TracerouteOption `json:"traceroute_config"`
	SuccessWhen      []*TCPSuccess     `json:"success_when"`
	SuccessWhenLogic string            `json:"success_when_logic"`
	// contains filtered or unexported fields
}

type Task

type Task struct {
	ExternalID        string `json:"external_id"`
	Name              string `json:"name"`
	AK                string `json:"access_key"`
	PostURL           string `json:"post_url"`
	CurStatus         string `json:"status"`
	Frequency         string `json:"frequency"`
	Region            string `json:"region"`
	OwnerExternalID   string `json:"owner_external_id"`
	WorkspaceLanguage string `json:"workspace_language,omitempty"`
	TagsInfo          string `json:"tags_info,omitempty"` // deprecated
	DFLabel           string `json:"df_label,omitempty"`
	ScheduleType      string `json:"schedule_type,omitempty"` // "frequency" or "crontab"
	Crontab           string `json:"crontab,omitempty"`       // crontab expression like "0 0 * * *"

	Tags          map[string]string `json:"tags,omitempty"`
	Labels        []string          `json:"labels,omitempty"`
	UpdateTime    int64             `json:"update_time,omitempty"`
	ConfigVars    []*ConfigVar      `json:"config_vars,omitempty"`
	ExtractedVars []*ConfigVar
	CustomVars    []*ConfigVar

	Disabled uint8 `json:"disabled"`
	// contains filtered or unexported fields
}

func (*Task) AccessKey

func (t *Task) AccessKey() string

func (*Task) AddExtractedVar

func (t *Task) AddExtractedVar(v *ConfigVar)

func (*Task) Check

func (t *Task) Check() error

func (*Task) CheckResult

func (t *Task) CheckResult() ([]string, bool)

func (*Task) CheckTask

func (t *Task) CheckTask() error

func (*Task) Class

func (t *Task) Class() string

func (*Task) Clear

func (t *Task) Clear()

func (*Task) GetCrontab

func (t *Task) GetCrontab() string

func (*Task) GetDFLabel

func (t *Task) GetDFLabel() string

func (*Task) GetExternalID

func (t *Task) GetExternalID() string

func (*Task) GetFrequency

func (t *Task) GetFrequency() string

func (*Task) GetGlobalVars

func (t *Task) GetGlobalVars() []string

func (*Task) GetHostName

func (t *Task) GetHostName() ([]string, error)

func (*Task) GetIsTemplate

func (t *Task) GetIsTemplate() bool

func (*Task) GetLineData

func (t *Task) GetLineData() string

func (*Task) GetOption

func (t *Task) GetOption() map[string]string

func (*Task) GetOwnerExternalID

func (t *Task) GetOwnerExternalID() string

func (*Task) GetParsedString

func (t *Task) GetParsedString(text string, fm template.FuncMap) (string, error)

func (*Task) GetPostScriptVars

func (t *Task) GetPostScriptVars() Vars

func (*Task) GetResults

func (t *Task) GetResults() (tags map[string]string, fields map[string]interface{})

func (*Task) GetScheduleType

func (t *Task) GetScheduleType() string

func (*Task) GetTaskJSONString

func (t *Task) GetTaskJSONString() string

func (*Task) GetVariableValue

func (t *Task) GetVariableValue(variable Variable) (string, error)

func (*Task) GetWorkspaceLanguage

func (t *Task) GetWorkspaceLanguage() string

func (*Task) ID

func (t *Task) ID() string

func (*Task) Init

func (t *Task) Init() error

func (*Task) MetricName

func (t *Task) MetricName() string

func (*Task) NewRawTask

func (t *Task) NewRawTask(child TaskChild) error

func (*Task) PostURLStr

func (t *Task) PostURLStr() string

func (*Task) RegionName

func (t *Task) RegionName() string

func (*Task) RenderTemplateAndInit

func (t *Task) RenderTemplateAndInit(globalVariables map[string]Variable) error

RenderTemplateAndInit render template and init task.

func (*Task) Run

func (t *Task) Run() error

func (*Task) SetAk

func (t *Task) SetAk(ak string)

func (*Task) SetBeforeRun

func (t *Task) SetBeforeRun(beforeRun func(*Task) error)

func (*Task) SetChild

func (t *Task) SetChild(child TaskChild)

func (*Task) SetCustomVars

func (t *Task) SetCustomVars(vars []*ConfigVar)

func (*Task) SetDisabled

func (t *Task) SetDisabled(disabled uint8)

func (*Task) SetIsTemplate

func (t *Task) SetIsTemplate(isTemplate bool)

func (*Task) SetOption

func (t *Task) SetOption(opt map[string]string)

func (*Task) SetOwnerExternalID

func (t *Task) SetOwnerExternalID(exid string)

func (*Task) SetRegionID

func (t *Task) SetRegionID(regionID string)

func (*Task) SetStatus

func (t *Task) SetStatus(status string)

func (*Task) SetTaskJSONString

func (t *Task) SetTaskJSONString(s string)

func (*Task) SetUpdateTime

func (t *Task) SetUpdateTime(ts int64)

func (*Task) Status

func (t *Task) Status() string

func (*Task) Stop

func (t *Task) Stop()

func (*Task) String

func (t *Task) String() string

func (*Task) UpdateTimeUs

func (t *Task) UpdateTimeUs() int64

type TaskChild

type TaskChild interface {
	ITask
	// contains filtered or unexported methods
}

func CreateTaskChild

func CreateTaskChild(taskType string) (TaskChild, error)

type TaskConfig

type TaskConfig struct {
	MaxMsgSize        int `json:"max_msg_size,omitempty"`
	MaxICMPConcurrent int `json:"max_icmp_concurrent,omitempty"`
	Logger            *log.Logger
}

type Traceroute

type Traceroute struct {
	Host    string
	Hops    int
	Retry   int
	Timeout time.Duration
	// contains filtered or unexported fields
}

Traceroute specified host with max hops and timeout.

func (*Traceroute) Run

func (t *Traceroute) Run() error

type TracerouteOption

type TracerouteOption struct {
	Hops    int
	Retry   int
	Timeout string
	// contains filtered or unexported fields
}

TracerouteOption represent traceroute option.

type ValueSuccess

type ValueSuccess struct {
	Op     string  `json:"op,omitempty"`
	Target float64 `json:"target,omitempty"`
}

type Variable

type Variable struct {
	ID          int    `json:"id,omitempty"`
	Name        string `json:"name,omitempty"`
	UUID        string `json:"uuid,omitempty"`
	TaskID      string `json:"task_id,omitempty"`
	TaskVarName string `json:"task_var_name,omitempty"`
	Value       string `json:"value,omitempty"`
	Secure      bool   `json:"secure,omitempty"`
	PostScript  string `json:"post_script,omitempty"`

	UpdatedAt       int64  `json:"updated_at,omitempty"`       // update time
	ValueUpdatedAt  int64  `json:"value_updated_at,omitempty"` // update value time
	FailCount       int    `json:"fail_count,omitempty"`       // update fail count
	DeletedAt       int64  `json:"deleted_at,omitempty"`
	OwnerExternalID string `json:"owner_external_id,omitempty"`
	CreatedAt       int64  `json:"-"`
}

type Vars

type Vars map[string]interface{}

type WebsocketAdvanceOption

type WebsocketAdvanceOption struct {
	RequestOptions *WebsocketOptRequest `json:"request_options,omitempty"`
	Auth           *WebsocketOptAuth    `json:"auth,omitempty"`
}

type WebsocketOptAuth

type WebsocketOptAuth struct {
	// basic auth
	Username string `json:"username,omitempty"`
	Password string `json:"password,omitempty"`
}

type WebsocketOptRequest

type WebsocketOptRequest struct {
	Timeout string            `json:"timeout,omitempty"`
	Headers map[string]string `json:"headers,omitempty"`
}

type WebsocketResponseTime

type WebsocketResponseTime struct {
	IsContainDNS bool   `json:"is_contain_dns"`
	Target       string `json:"target"`
	// contains filtered or unexported fields
}

type WebsocketSuccess

type WebsocketSuccess struct {
	ResponseTime    []*WebsocketResponseTime    `json:"response_time,omitempty"`
	ResponseMessage []*SuccessOption            `json:"response_message,omitempty"`
	Header          map[string][]*SuccessOption `json:"header,omitempty"`
}

type WebsocketTask

type WebsocketTask struct {
	*Task
	URL              string                  `json:"url"`
	Message          string                  `json:"message"`
	SuccessWhen      []*WebsocketSuccess     `json:"success_when"`
	AdvanceOptions   *WebsocketAdvanceOption `json:"advance_options,omitempty"`
	SuccessWhenLogic string                  `json:"success_when_logic"`
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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