model

package
v1.3.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	ModeAlwaysTrigger  = 0
	ModeOnetimeTrigger = 1
)
View Source
const (
	CtxKeyAuthorizedUser = "ckau"
	CtxKeyRealIPStr      = "ckri"
)
View Source
const (
	ConfigUsePeerIP = "NZ::Use-Peer-IP"
	ConfigCoverAll  = iota
	ConfigCoverIgnoreAll
)
View Source
const (
	CronCoverIgnoreAll = iota
	CronCoverAll
	CronCoverAlertTrigger
	CronTypeCronTask    = 0
	CronTypeTriggerTask = 1
)
View Source
const (
	ProviderDummy        = "dummy"
	ProviderWebHook      = "webhook"
	ProviderCloudflare   = "cloudflare"
	ProviderTencentCloud = "tencentcloud"
)
View Source
const (
	NotificationRequestTypeJSON
	NotificationRequestTypeForm
)
View Source
const (
	NotificationRequestMethodGET
	NotificationRequestMethodPOST
)
View Source
const (
	RuleCoverAll = iota
	RuleCoverIgnoreAll
)
View Source
const (
	TaskTypeHTTPGet
	TaskTypeICMPPing
	TaskTypeTCPPing
	TaskTypeCommand
	TaskTypeTerminal
	TaskTypeUpgrade
	TaskTypeKeepalive
	TaskTypeTerminalGRPC
	TaskTypeNAT
	TaskTypeReportHostInfoDeprecated
	TaskTypeFM
)
View Source
const (
	ServiceCoverAll = iota
	ServiceCoverIgnoreAll
)
View Source
const (
	WAFBlockReasonTypeLoginFail uint8
	WAFBlockReasonTypeBruteForceToken
	WAFBlockReasonTypeAgentAuthFail
)
View Source
const (
	ApiErrorUnauthorized = 10001
)
View Source
const (
	MTReportHostState
)

Variables

Functions

func BatchClearIP

func BatchClearIP(db *gorm.DB, ip []string) error

func BlockIP

func BlockIP(db *gorm.DB, ip string, reason uint8) error

func CheckIP

func CheckIP(db *gorm.DB, ip string) error

func ClearIP

func ClearIP(db *gorm.DB, ip string) error

func IsServiceSentinelNeeded

func IsServiceSentinelNeeded(t uint64) bool

IsServiceSentinelNeeded 判断该任务类型是否需要进行服务监控 需要则返回true

Types

type AlertRule

type AlertRule struct {
	Common
	Name                   string   `json:"name"`
	RulesRaw               string   `json:"-"`
	Enable                 *bool    `json:"enable,omitempty"`
	TriggerMode            uint8    `gorm:"default:0" json:"trigger_mode"` // 触发模式: 0-始终触发(默认) 1-单次触发
	NotificationGroupID    uint64   `json:"notification_group_id"`         // 该报警规则所在的通知组
	FailTriggerTasksRaw    string   `gorm:"default:'[]'" json:"-"`
	RecoverTriggerTasksRaw string   `gorm:"default:'[]'" json:"-"`
	Rules                  []*Rule  `gorm:"-" json:"rules"`
	FailTriggerTasks       []uint64 `gorm:"-" json:"fail_trigger_tasks"`    // 失败时执行的触发任务id
	RecoverTriggerTasks    []uint64 `gorm:"-" json:"recover_trigger_tasks"` // 恢复时执行的触发任务id
}

func (*AlertRule) AfterFind

func (r *AlertRule) AfterFind(tx *gorm.DB) error

func (*AlertRule) BeforeSave

func (r *AlertRule) BeforeSave(tx *gorm.DB) error

func (*AlertRule) Check

func (r *AlertRule) Check(points [][]bool) (maxDuration int, passed bool)

Check 传入包含当前报警规则下所有type检查结果 返回报警持续时间与是否通过报警检查(通过则返回true)

func (*AlertRule) Enabled

func (r *AlertRule) Enabled() bool

func (*AlertRule) Snapshot

func (r *AlertRule) Snapshot(cycleTransferStats *CycleTransferStats, server *Server, db *gorm.DB) []bool

Snapshot 对传入的Server进行该报警规则下所有type的检查 返回每项检查结果

type AlertRuleForm

type AlertRuleForm struct {
	Name                string   `json:"name" minLength:"1"`
	Rules               []*Rule  `json:"rules"`
	FailTriggerTasks    []uint64 `json:"fail_trigger_tasks"`    // 失败时触发的任务id
	RecoverTriggerTasks []uint64 `json:"recover_trigger_tasks"` // 恢复时触发的任务id
	NotificationGroupID uint64   `json:"notification_group_id"`
	TriggerMode         uint8    `json:"trigger_mode" default:"0"`
	Enable              bool     `json:"enable" validate:"optional"`
}

type Common

type Common struct {
	ID        uint64    `gorm:"primaryKey" json:"id,omitempty"`
	CreatedAt time.Time `gorm:"index;<-:create" json:"created_at,omitempty"`
	UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at,omitempty"`
}

type CommonResponse

type CommonResponse[T any] struct {
	Success bool   `json:"success,omitempty"`
	Data    T      `json:"data,omitempty"`
	Error   string `json:"error,omitempty"`
}

type Config

type Config struct {
	Debug        bool   `mapstructure:"debug" json:"debug,omitempty"`                   // debug模式开关
	RealIPHeader string `mapstructure:"real_ip_header" json:"real_ip_header,omitempty"` // 真实IP

	Language       string `mapstructure:"language" json:"language"` // 系统语言,默认 zh_CN
	SiteName       string `mapstructure:"site_name" json:"site_name"`
	UserTemplate   string `mapstructure:"user_template" json:"user_template,omitempty"`
	AdminTemplate  string `mapstructure:"admin_template" json:"admin_template,omitempty"`
	JWTSecretKey   string `mapstructure:"jwt_secret_key" json:"jwt_secret_key,omitempty"`
	AgentSecretKey string `mapstructure:"agent_secret_key" json:"agent_secret_key,omitempty"`
	ListenPort     uint   `mapstructure:"listen_port" json:"listen_port,omitempty"`
	ListenHost     string `mapstructure:"listen_host" json:"listen_host,omitempty"`
	InstallHost    string `mapstructure:"install_host" json:"install_host,omitempty"`
	TLS            bool   `mapstructure:"tls" json:"tls,omitempty"`
	Location       string `mapstructure:"location" json:"location,omitempty"` // 时区,默认为 Asia/Shanghai

	EnablePlainIPInNotification bool `mapstructure:"enable_plain_ip_in_notification" json:"enable_plain_ip_in_notification,omitempty"` // 通知信息IP不打码

	// IP变更提醒
	EnableIPChangeNotification  bool   `mapstructure:"enable_ip_change_notification" json:"enable_ip_change_notification,omitempty"`
	IPChangeNotificationGroupID uint64 `mapstructure:"ip_change_notification_group_id" json:"ip_change_notification_group_id"`
	Cover                       uint8  `mapstructure:"cover" json:"cover"`                                               // 覆盖范围(0:提醒未被 IgnoredIPNotification 包含的所有服务器; 1:仅提醒被 IgnoredIPNotification 包含的服务器;)
	IgnoredIPNotification       string `mapstructure:"ignored_ip_notification" json:"ignored_ip_notification,omitempty"` // 特定服务器IP(多个服务器用逗号分隔)

	IgnoredIPNotificationServerIDs map[uint64]bool `mapstructure:"ignored_ip_notification_server_ids" json:"ignored_ip_notification_server_ids,omitempty"` // [ServerID] -> bool(值为true代表当前ServerID在特定服务器列表内)
	AvgPingCount                   int             `mapstructure:"avg_ping_count" json:"avg_ping_count,omitempty"`
	DNSServers                     string          `mapstructure:"dns_servers" json:"dns_servers,omitempty"`

	CustomCode          string `mapstructure:"custom_code" json:"custom_code,omitempty"`
	CustomCodeDashboard string `mapstructure:"custom_code_dashboard" json:"custom_code_dashboard,omitempty"`
	// contains filtered or unexported fields
}

func (*Config) Read

func (c *Config) Read(path string, frontendTemplates []FrontendTemplate) error

Read 读取配置文件并应用

func (*Config) Save

func (c *Config) Save() error

Save 保存配置文件

type CreateFMResponse

type CreateFMResponse struct {
	SessionID string `json:"session_id,omitempty"`
}

type CreateTerminalResponse

type CreateTerminalResponse struct {
	SessionID  string `json:"session_id,omitempty"`
	ServerID   uint64 `json:"server_id,omitempty"`
	ServerName string `json:"server_name,omitempty"`
}

type Cron

type Cron struct {
	Common
	Name                string    `json:"name"`
	TaskType            uint8     `gorm:"default:0" json:"task_type"` // 0:计划任务 1:触发任务
	Scheduler           string    `json:"scheduler"`                  // 分钟 小时 天 月 星期
	Command             string    `json:"command,omitempty"`
	Servers             []uint64  `gorm:"-" json:"servers"`
	PushSuccessful      bool      `json:"push_successful,omitempty"`  // 推送成功的通知
	NotificationGroupID uint64    `json:"notification_group_id"`      // 指定通知方式的分组
	LastExecutedAt      time.Time `json:"last_executed_at,omitempty"` // 最后一次执行时间
	LastResult          bool      `json:"last_result,omitempty"`      // 最后一次执行结果
	Cover               uint8     `json:"cover"`                      // 计划任务覆盖范围 (0:仅覆盖特定服务器 1:仅忽略特定服务器 2:由触发该计划任务的服务器执行)

	CronJobID  cron.EntryID `gorm:"-" json:"cron_job_id,omitempty"`
	ServersRaw string       `json:"-"`
}

func (*Cron) AfterFind

func (c *Cron) AfterFind(tx *gorm.DB) error

func (*Cron) BeforeSave

func (c *Cron) BeforeSave(tx *gorm.DB) error

type CronForm

type CronForm struct {
	TaskType            uint8    `json:"task_type,omitempty" default:"0"` // 0:计划任务 1:触发任务
	Name                string   `json:"name,omitempty" minLength:"1"`
	Scheduler           string   `json:"scheduler,omitempty"`
	Command             string   `json:"command,omitempty" validate:"optional"`
	Servers             []uint64 `json:"servers,omitempty"`
	Cover               uint8    `json:"cover,omitempty" default:"0"`
	PushSuccessful      bool     `json:"push_successful,omitempty" validate:"optional"`
	NotificationGroupID uint64   `json:"notification_group_id,omitempty"`
}

type CtxKeyConnectingIP added in v1.2.7

type CtxKeyConnectingIP struct{}

type CtxKeyRealIP

type CtxKeyRealIP struct{}

type CycleTransferStats

type CycleTransferStats struct {
	Name       string               `json:"name"`
	From       time.Time            `json:"from"`
	To         time.Time            `json:"to"`
	Max        uint64               `json:"max"`
	Min        uint64               `json:"min"`
	ServerName map[uint64]string    `json:"server_name,omitempty"`
	Transfer   map[uint64]uint64    `json:"transfer,omitempty"`
	NextUpdate map[uint64]time.Time `json:"next_update,omitempty"`
}

type DDNSForm

type DDNSForm struct {
	MaxRetries         uint64   `json:"max_retries,omitempty" default:"3"`
	EnableIPv4         bool     `json:"enable_ipv4,omitempty" validate:"optional"`
	EnableIPv6         bool     `json:"enable_ipv6,omitempty" validate:"optional"`
	Name               string   `json:"name,omitempty" minLength:"1"`
	Provider           string   `json:"provider,omitempty"`
	Domains            []string `json:"domains,omitempty"`
	AccessID           string   `json:"access_id,omitempty" validate:"optional"`
	AccessSecret       string   `json:"access_secret,omitempty" validate:"optional"`
	WebhookURL         string   `json:"webhook_url,omitempty" validate:"optional"`
	WebhookMethod      uint8    `json:"webhook_method,omitempty" validate:"optional" default:"1"`
	WebhookRequestType uint8    `json:"webhook_request_type,omitempty" validate:"optional" default:"1"`
	WebhookRequestBody string   `json:"webhook_request_body,omitempty" validate:"optional"`
	WebhookHeaders     string   `json:"webhook_headers,omitempty" validate:"optional"`
}

type DDNSProfile

type DDNSProfile struct {
	Common
	EnableIPv4         *bool    `json:"enable_ipv4,omitempty"`
	EnableIPv6         *bool    `json:"enable_ipv6,omitempty"`
	MaxRetries         uint64   `json:"max_retries"`
	Name               string   `json:"name"`
	Provider           string   `json:"provider"`
	AccessID           string   `json:"access_id,omitempty"`
	AccessSecret       string   `json:"access_secret,omitempty"`
	WebhookURL         string   `json:"webhook_url,omitempty"`
	WebhookMethod      uint8    `json:"webhook_method,omitempty"`
	WebhookRequestType uint8    `json:"webhook_request_type,omitempty"`
	WebhookRequestBody string   `json:"webhook_request_body,omitempty"`
	WebhookHeaders     string   `json:"webhook_headers,omitempty"`
	Domains            []string `json:"domains" gorm:"-"`
	DomainsRaw         string   `json:"-"`
}

func (*DDNSProfile) AfterFind

func (d *DDNSProfile) AfterFind(tx *gorm.DB) error

func (*DDNSProfile) BeforeSave

func (d *DDNSProfile) BeforeSave(tx *gorm.DB) error

func (DDNSProfile) TableName

func (d DDNSProfile) TableName() string

type ForceUpdateResponse

type ForceUpdateResponse struct {
	Success []uint64 `json:"success,omitempty" validate:"optional"`
	Failure []uint64 `json:"failure,omitempty" validate:"optional"`
	Offline []uint64 `json:"offline,omitempty" validate:"optional"`
}

type FrontendTemplate added in v1.1.4

type FrontendTemplate struct {
	Path       string `json:"path,omitempty"`
	Name       string `json:"name,omitempty"`
	Repository string `json:"repository,omitempty"`
	Author     string `json:"author,omitempty"`
	Version    string `json:"version,omitempty"`
	IsAdmin    bool   `json:"is_admin,omitempty"`
	IsOfficial bool   `json:"is_official,omitempty"`
}

type GeoIP

type GeoIP struct {
	IP          IP     `json:"ip,omitempty"`
	CountryCode string `json:"country_code,omitempty"`
}

func PB2GeoIP

func PB2GeoIP(p *pb.GeoIP) GeoIP

type Host

type Host struct {
	Platform        string   `json:"platform,omitempty"`
	PlatformVersion string   `json:"platform_version,omitempty"`
	CPU             []string `json:"cpu,omitempty"`
	MemTotal        uint64   `json:"mem_total,omitempty"`
	DiskTotal       uint64   `json:"disk_total,omitempty"`
	SwapTotal       uint64   `json:"swap_total,omitempty"`
	Arch            string   `json:"arch,omitempty"`
	Virtualization  string   `json:"virtualization,omitempty"`
	BootTime        uint64   `json:"boot_time,omitempty"`
	Version         string   `json:"version,omitempty"`
	GPU             []string `json:"gpu,omitempty"`
}

func PB2Host

func PB2Host(h *pb.Host) Host

func (*Host) Filter added in v1.0.19

func (h *Host) Filter() *Host

Filter returns a new instance of Host with some fields redacted.

func (*Host) PB

func (h *Host) PB() *pb.Host

type HostState

type HostState struct {
	CPU            float64             `json:"cpu,omitempty"`
	MemUsed        uint64              `json:"mem_used,omitempty"`
	SwapUsed       uint64              `json:"swap_used,omitempty"`
	DiskUsed       uint64              `json:"disk_used,omitempty"`
	NetInTransfer  uint64              `json:"net_in_transfer,omitempty"`
	NetOutTransfer uint64              `json:"net_out_transfer,omitempty"`
	NetInSpeed     uint64              `json:"net_in_speed,omitempty"`
	NetOutSpeed    uint64              `json:"net_out_speed,omitempty"`
	Uptime         uint64              `json:"uptime,omitempty"`
	Load1          float64             `json:"load_1,omitempty"`
	Load5          float64             `json:"load_5,omitempty"`
	Load15         float64             `json:"load_15,omitempty"`
	TcpConnCount   uint64              `json:"tcp_conn_count,omitempty"`
	UdpConnCount   uint64              `json:"udp_conn_count,omitempty"`
	ProcessCount   uint64              `json:"process_count,omitempty"`
	Temperatures   []SensorTemperature `json:"temperatures,omitempty"`
	GPU            []float64           `json:"gpu,omitempty"`
}

func PB2State

func PB2State(s *pb.State) HostState

func (*HostState) PB

func (s *HostState) PB() *pb.State

type IP

type IP struct {
	IPv4Addr string `json:"ipv4_addr,omitempty"`
	IPv6Addr string `json:"ipv6_addr,omitempty"`
}

func (*IP) Join

func (p *IP) Join() string

type LoginRequest

type LoginRequest struct {
	Username string `json:"username,omitempty"`
	Password string `json:"password,omitempty"`
}

type LoginResponse

type LoginResponse struct {
	Token  string `json:"token,omitempty"`
	Expire string `json:"expire,omitempty"`
}

type NAT

type NAT struct {
	Common
	Name     string `json:"name"`
	ServerID uint64 `json:"server_id"`
	Host     string `json:"host"`
	Domain   string `json:"domain" gorm:"unique"`
}

type NATForm

type NATForm struct {
	Name     string `json:"name,omitempty" minLength:"1"`
	ServerID uint64 `json:"server_id,omitempty"`
	Host     string `json:"host,omitempty"`
	Domain   string `json:"domain,omitempty"`
}

type NResult

type NResult struct {
	N uint64
}

type Notification

type Notification struct {
	Common
	Name          string `json:"name"`
	URL           string `json:"url"`
	RequestMethod uint8  `json:"request_method"`
	RequestType   uint8  `json:"request_type"`
	RequestHeader string `json:"request_header" gorm:"type:longtext"`
	RequestBody   string `json:"request_body" gorm:"type:longtext"`
	VerifyTLS     *bool  `json:"verify_tls,omitempty"`
}

type NotificationForm

type NotificationForm struct {
	Name          string `json:"name,omitempty" minLength:"1"`
	URL           string `json:"url,omitempty"`
	RequestMethod uint8  `json:"request_method,omitempty"`
	RequestType   uint8  `json:"request_type,omitempty"`
	RequestHeader string `json:"request_header,omitempty"`
	RequestBody   string `json:"request_body,omitempty"`
	VerifyTLS     bool   `json:"verify_tls,omitempty" validate:"optional"`
	SkipCheck     bool   `json:"skip_check,omitempty" validate:"optional"`
}

type NotificationGroup

type NotificationGroup struct {
	Common
	Name string `json:"name"`
}

type NotificationGroupForm

type NotificationGroupForm struct {
	Name          string   `json:"name" minLength:"1"`
	Notifications []uint64 `json:"notifications"`
}

type NotificationGroupNotification

type NotificationGroupNotification struct {
	Common
	NotificationGroupID uint64 `json:"notification_group_id" gorm:"uniqueIndex:idx_notification_group_notification"`
	NotificationID      uint64 `json:"notification_id" gorm:"uniqueIndex:idx_notification_group_notification"`
}

type NotificationGroupResponseItem

type NotificationGroupResponseItem struct {
	Group         NotificationGroup `json:"group"`
	Notifications []uint64          `json:"notifications"`
}

type NotificationServerBundle

type NotificationServerBundle struct {
	Notification *Notification
	Server       *Server
	Loc          *time.Location
}

func (*NotificationServerBundle) Send

func (ns *NotificationServerBundle) Send(message string) error

type Profile

type Profile struct {
	User
	LoginIP string `json:"login_ip,omitempty"`
}

type ProfileForm

type ProfileForm struct {
	OriginalPassword string `json:"original_password,omitempty"`
	NewUsername      string `json:"new_username,omitempty"`
	NewPassword      string `json:"new_password,omitempty"`
}

type Response

type Response struct {
	Code    int         `json:"code,omitempty"`
	Message string      `json:"message,omitempty"`
	Result  interface{} `json:"result,omitempty"`
}

type Rule

type Rule struct {
	// 指标类型,cpu、memory、swap、disk、net_in_speed、net_out_speed
	// net_all_speed、transfer_in、transfer_out、transfer_all、offline
	// transfer_in_cycle、transfer_out_cycle、transfer_all_cycle
	Type          string          `json:"type"`
	Min           float64         `json:"min,omitempty" validate:"optional"`                                                        // 最小阈值 (百分比、字节 kb ÷ 1024)
	Max           float64         `json:"max,omitempty" validate:"optional"`                                                        // 最大阈值 (百分比、字节 kb ÷ 1024)
	CycleStart    *time.Time      `json:"cycle_start,omitempty" validate:"optional"`                                                // 流量统计的开始时间
	CycleInterval uint64          `json:"cycle_interval,omitempty" validate:"optional"`                                             // 流量统计周期
	CycleUnit     string          `json:"cycle_unit,omitempty" enums:"hour,day,week,month,year" validate:"optional" default:"hour"` // 流量统计周期单位,默认hour,可选(hour, day, week, month, year)
	Duration      uint64          `json:"duration,omitempty" validate:"optional"`                                                   // 持续时间 (秒)
	Cover         uint64          `json:"cover"`                                                                                    // 覆盖范围 RuleCoverAll/IgnoreAll
	Ignore        map[uint64]bool `json:"ignore,omitempty" validate:"optional"`                                                     // 覆盖范围的排除

	// 只作为缓存使用,记录下次该检测的时间
	NextTransferAt  map[uint64]time.Time `json:"-"`
	LastCycleStatus map[uint64]bool      `json:"-"`
}

func (*Rule) GetTransferDurationEnd

func (u *Rule) GetTransferDurationEnd() time.Time

GetTransferDurationEnd 获取周期流量结束时间

func (*Rule) GetTransferDurationStart

func (u *Rule) GetTransferDurationStart() time.Time

GetTransferDurationStart 获取周期流量的起始时间

func (*Rule) IsTransferDurationRule

func (u *Rule) IsTransferDurationRule() bool

IsTransferDurationRule 判断该规则是否属于周期流量规则 属于则返回true

func (*Rule) Snapshot

func (u *Rule) Snapshot(cycleTransferStats *CycleTransferStats, server *Server, db *gorm.DB) bool

Snapshot 未通过规则返回 false, 通过返回 true

type SensorTemperature

type SensorTemperature struct {
	Name        string
	Temperature float64
}

type Server

type Server struct {
	Common

	Name            string `json:"name"`
	UUID            string `json:"uuid,omitempty" gorm:"unique"`
	Note            string `json:"note,omitempty"`           // 管理员可见备注
	PublicNote      string `json:"public_note,omitempty"`    // 公开备注
	DisplayIndex    int    `json:"display_index"`            // 展示排序,越大越靠前
	HideForGuest    bool   `json:"hide_for_guest,omitempty"` // 对游客隐藏
	EnableDDNS      bool   `json:"enable_ddns,omitempty"`    // 启用DDNS
	DDNSProfilesRaw string `gorm:"default:'[]';column:ddns_profiles_raw" json:"-"`

	DDNSProfiles []uint64 `gorm:"-" json:"ddns_profiles,omitempty" validate:"optional"` // DDNS配置

	Host       *Host      `gorm:"-" json:"host,omitempty"`
	State      *HostState `gorm:"-" json:"state,omitempty"`
	GeoIP      *GeoIP     `gorm:"-" json:"geoip,omitempty"`
	LastActive time.Time  `gorm:"-" json:"last_active,omitempty"`

	TaskStream pb.NezhaService_RequestTaskServer `gorm:"-" json:"-"`

	PrevTransferInSnapshot  int64 `gorm:"-" json:"-"` // 上次数据点时的入站使用量
	PrevTransferOutSnapshot int64 `gorm:"-" json:"-"` // 上次数据点时的出站使用量
}

func (*Server) AfterFind

func (s *Server) AfterFind(tx *gorm.DB) error

func (*Server) CopyFromRunningServer

func (s *Server) CopyFromRunningServer(old *Server)

type ServerForm

type ServerForm struct {
	Name         string   `json:"name,omitempty"`
	Note         string   `json:"note,omitempty" validate:"optional"`                   // 管理员可见备注
	PublicNote   string   `json:"public_note,omitempty" validate:"optional"`            // 公开备注
	DisplayIndex int      `json:"display_index,omitempty" default:"0"`                  // 展示排序,越大越靠前
	HideForGuest bool     `json:"hide_for_guest,omitempty" validate:"optional"`         // 对游客隐藏
	EnableDDNS   bool     `json:"enable_ddns,omitempty" validate:"optional"`            // 启用DDNS
	DDNSProfiles []uint64 `gorm:"-" json:"ddns_profiles,omitempty" validate:"optional"` // DDNS配置
}

type ServerGroup

type ServerGroup struct {
	Common

	Name string `json:"name"`
}

type ServerGroupForm

type ServerGroupForm struct {
	Name    string   `json:"name" minLength:"1"`
	Servers []uint64 `json:"servers"`
}

type ServerGroupResponseItem

type ServerGroupResponseItem struct {
	Group   ServerGroup `json:"group"`
	Servers []uint64    `json:"servers"`
}

type ServerGroupServer

type ServerGroupServer struct {
	Common
	ServerGroupId uint64 `json:"server_group_id" gorm:"uniqueIndex:idx_server_group_server"`
	ServerId      uint64 `json:"server_id" gorm:"uniqueIndex:idx_server_group_server"`
}

type Service

type Service struct {
	Common
	Name                string `json:"name"`
	Type                uint8  `json:"type"`
	Target              string `json:"target"`
	SkipServersRaw      string `json:"-"`
	Duration            uint64 `json:"duration"`
	Notify              bool   `json:"notify,omitempty"`
	NotificationGroupID uint64 `json:"notification_group_id"` // 当前服务监控所属的通知组 ID
	Cover               uint8  `json:"cover"`

	EnableTriggerTask      bool   `gorm:"default: false" json:"enable_trigger_task,omitempty"`
	EnableShowInService    bool   `gorm:"default: false" json:"enable_show_in_service,omitempty"`
	FailTriggerTasksRaw    string `gorm:"default:'[]'" json:"-"`
	RecoverTriggerTasksRaw string `gorm:"default:'[]'" json:"-"`

	FailTriggerTasks    []uint64 `gorm:"-" json:"fail_trigger_tasks"`    // 失败时执行的触发任务id
	RecoverTriggerTasks []uint64 `gorm:"-" json:"recover_trigger_tasks"` // 恢复时执行的触发任务id

	MinLatency    float32 `json:"min_latency"`
	MaxLatency    float32 `json:"max_latency"`
	LatencyNotify bool    `json:"latency_notify,omitempty"`

	SkipServers map[uint64]bool `gorm:"-" json:"skip_servers"`
	CronJobID   cron.EntryID    `gorm:"-" json:"-"`
}

func (*Service) AfterFind

func (m *Service) AfterFind(tx *gorm.DB) error

func (*Service) BeforeSave

func (m *Service) BeforeSave(tx *gorm.DB) error

func (*Service) CronSpec

func (m *Service) CronSpec() string

CronSpec 返回服务监控请求间隔对应的 cron 表达式

func (*Service) PB

func (m *Service) PB() *pb.Task

type ServiceForm

type ServiceForm struct {
	Name                string          `json:"name,omitempty" minLength:"1"`
	Target              string          `json:"target,omitempty"`
	Type                uint8           `json:"type,omitempty"`
	Cover               uint8           `json:"cover,omitempty"`
	Notify              bool            `json:"notify,omitempty" validate:"optional"`
	Duration            uint64          `json:"duration,omitempty"`
	MinLatency          float32         `json:"min_latency,omitempty" default:"0.0"`
	MaxLatency          float32         `json:"max_latency,omitempty" default:"0.0"`
	LatencyNotify       bool            `json:"latency_notify,omitempty" validate:"optional"`
	EnableTriggerTask   bool            `json:"enable_trigger_task,omitempty" validate:"optional"`
	EnableShowInService bool            `json:"enable_show_in_service,omitempty" validate:"optional"`
	FailTriggerTasks    []uint64        `json:"fail_trigger_tasks,omitempty"`
	RecoverTriggerTasks []uint64        `json:"recover_trigger_tasks,omitempty"`
	SkipServers         map[uint64]bool `json:"skip_servers,omitempty"`
	NotificationGroupID uint64          `json:"notification_group_id,omitempty"`
}

type ServiceHistory

type ServiceHistory struct {
	ID        uint64    `gorm:"primaryKey" json:"id,omitempty"`
	CreatedAt time.Time `gorm:"index;<-:create;index:idx_server_id_created_at_service_id_avg_delay" json:"created_at,omitempty"`
	UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at,omitempty"`
	ServiceID uint64    `gorm:"index:idx_server_id_created_at_service_id_avg_delay" json:"service_id,omitempty"`
	ServerID  uint64    `gorm:"index:idx_server_id_created_at_service_id_avg_delay" json:"server_id,omitempty"`
	AvgDelay  float32   `gorm:"index:idx_server_id_created_at_service_id_avg_delay" json:"avg_delay,omitempty"` // 平均延迟,毫秒
	Up        uint64    `json:"up,omitempty"`                                                                   // 检查状态良好计数
	Down      uint64    `json:"down,omitempty"`                                                                 // 检查状态异常计数
	Data      string    `json:"data,omitempty"`
}

type ServiceInfos

type ServiceInfos struct {
	ServiceID   uint64    `json:"monitor_id"`
	ServerID    uint64    `json:"server_id"`
	ServiceName string    `json:"monitor_name"`
	ServerName  string    `json:"server_name"`
	CreatedAt   []int64   `json:"created_at"`
	AvgDelay    []float32 `json:"avg_delay"`
}

type ServiceResponse

type ServiceResponse struct {
	Services           map[uint64]ServiceResponseItem `json:"services,omitempty"`
	CycleTransferStats map[uint64]CycleTransferStats  `json:"cycle_transfer_stats,omitempty"`
}

type ServiceResponseItem

type ServiceResponseItem struct {
	ServiceName string       `json:"service_name,omitempty"`
	CurrentUp   uint64       `json:"current_up"`
	CurrentDown uint64       `json:"current_down"`
	TotalUp     uint64       `json:"total_up"`
	TotalDown   uint64       `json:"total_down"`
	Delay       *[30]float32 `json:"delay,omitempty"`
	Up          *[30]int     `json:"up,omitempty"`
	Down        *[30]int     `json:"down,omitempty"`
}

func (ServiceResponseItem) TotalUptime

func (r ServiceResponseItem) TotalUptime() float32

type SettingForm

type SettingForm struct {
	DNSServers                  string `json:"dns_servers,omitempty" validate:"optional"`
	IgnoredIPNotification       string `json:"ignored_ip_notification,omitempty" validate:"optional"`
	IPChangeNotificationGroupID uint64 `json:"ip_change_notification_group_id,omitempty"` // IP变更提醒的通知组
	Cover                       uint8  `json:"cover,omitempty"`
	SiteName                    string `json:"site_name,omitempty" minLength:"1"`
	Language                    string `json:"language,omitempty" minLength:"2"`
	InstallHost                 string `json:"install_host,omitempty" validate:"optional"`
	CustomCode                  string `json:"custom_code,omitempty" validate:"optional"`
	CustomCodeDashboard         string `json:"custom_code_dashboard,omitempty" validate:"optional"`
	RealIPHeader                string `json:"real_ip_header,omitempty" validate:"optional"` // 真实IP
	UserTemplate                string `json:"user_template,omitempty" validate:"optional"`

	TLS                         bool `json:"tls,omitempty" validate:"optional"`
	EnableIPChangeNotification  bool `json:"enable_ip_change_notification,omitempty" validate:"optional"`
	EnablePlainIPInNotification bool `json:"enable_plain_ip_in_notification,omitempty" validate:"optional"`
}

type SettingResponse added in v1.0.19

type SettingResponse struct {
	Config

	Version           string             `json:"version,omitempty"`
	FrontendTemplates []FrontendTemplate `json:"frontend_templates,omitempty"`
}

type StreamServer

type StreamServer struct {
	ID           uint64 `json:"id,omitempty"`
	Name         string `json:"name,omitempty"`
	PublicNote   string `json:"public_note,omitempty"`   // 公开备注,只第一个数据包有值
	DisplayIndex int    `json:"display_index,omitempty"` // 展示排序,越大越靠前

	Host        *Host      `json:"host,omitempty"`
	State       *HostState `json:"state,omitempty"`
	CountryCode string     `json:"country_code,omitempty"`
	LastActive  time.Time  `json:"last_active,omitempty"`
}

type StreamServerData

type StreamServerData struct {
	Now     int64          `json:"now,omitempty"`
	Online  uint64         `json:"online,omitempty"`
	Servers []StreamServer `json:"servers,omitempty"`
}

type TaskFM

type TaskFM struct {
	StreamID string
}

type TaskNAT

type TaskNAT struct {
	StreamID string
	Host     string
}

type TerminalForm

type TerminalForm struct {
	Protocol string `json:"protocol,omitempty"`
	ServerID uint64 `json:"server_id,omitempty"`
}

type TerminalTask

type TerminalTask struct {
	StreamID string
}

type Transfer

type Transfer struct {
	Common
	ServerID uint64 `json:"server_id"`
	In       uint64 `json:"in"`
	Out      uint64 `json:"out"`
}

type User

type User struct {
	Common
	Username string `json:"username,omitempty" gorm:"uniqueIndex"`
	Password string `json:"password,omitempty" gorm:"type:char(72)"`
}

type UserForm

type UserForm struct {
	Username string `json:"username,omitempty"`
	Password string `json:"password,omitempty" gorm:"type:char(72)"`
}

type UserGroup

type UserGroup struct {
	Common
	Name string `json:"name"`
}

type UserGroupUser

type UserGroupUser struct {
	Common
	UserGroupId uint64 `json:"user_group_id"`
	UserId      uint64 `json:"user_id"`
}

type WAF

type WAF struct {
	IP                 []byte `gorm:"type:binary(16);primaryKey" json:"ip,omitempty"`
	Count              uint64 `json:"count,omitempty"`
	LastBlockReason    uint8  `json:"last_block_reason,omitempty"`
	LastBlockTimestamp uint64 `json:"last_block_timestamp,omitempty"`
}

func (*WAF) TableName

func (w *WAF) TableName() string

type WAFApiMock added in v1.0.11

type WAFApiMock struct {
	IP                 string `json:"ip,omitempty"`
	Count              uint64 `json:"count,omitempty"`
	LastBlockReason    uint8  `json:"last_block_reason,omitempty"`
	LastBlockTimestamp uint64 `json:"last_block_timestamp,omitempty"`
}

Jump to

Keyboard shortcuts

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