model

package
v0.16.22 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModeAlwaysTrigger  = 0
	ModeOnetimeTrigger = 1
)
View Source
const (
	ConfigTypeGitHub  = "github"
	ConfigTypeGitee   = "gitee"
	ConfigTypeGitlab  = "gitlab"
	ConfigTypeJihulab = "jihulab"
	ConfigTypeGitea   = "gitea"
)
View Source
const (
	ConfigCoverAll = iota
	ConfigCoverIgnoreAll
)
View Source
const (
	CronCoverIgnoreAll = iota
	CronCoverAll
	CronCoverAlertTrigger
	CronTypeCronTask    = 0
	CronTypeTriggerTask = 1
)
View Source
const (
	TaskTypeHTTPGET
	TaskTypeICMPPing
	TaskTypeTCPPing
	TaskTypeCommand
	TaskTypeTerminal
	TaskTypeUpgrade
	TaskTypeKeepalive
)
View Source
const (
	MonitorCoverAll = iota
	MonitorCoverIgnoreAll
)
View Source
const (
	NotificationRequestTypeJSON
	NotificationRequestTypeForm
)
View Source
const (
	NotificationRequestMethodGET
	NotificationRequestMethodPOST
)
View Source
const (
	RuleCoverAll = iota
	RuleCoverIgnoreAll
)
View Source
const CacheKeyOauth2State = "p:a:state"
View Source
const CtxKeyAuthorizedUser = "ckau"
View Source
const CtxKeyPreferredTheme = "ckpt"
View Source
const CtxKeyViewPasswordVerified = "ckvpv"
View Source
const (
	MTReportHostState
)

Variables

View Source
var DashboardThemes = map[string]string{
	"default": "Default",
	"custom":  "Custom(local)",
}
View Source
var Languages = map[string]string{
	"zh-CN": "简体中文",
	"zh-TW": "繁體中文",
	"en-US": "English",
	"es-ES": "Español",
}
View Source
var Themes = map[string]string{
	"default":       "Default",
	"daynight":      "JackieSung DayNight",
	"mdui":          "Neko Mdui",
	"hotaru":        "Hotaru",
	"angel-kanade":  "AngelKanade",
	"server-status": "SeverStatus",
	"custom":        "Custom(local)",
}

Functions

func IsServiceSentinelNeeded added in v0.10.0

func IsServiceSentinelNeeded(t uint64) bool

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

Types

type AgentConfig added in v0.12.7

type AgentConfig struct {
	HardDrivePartitionAllowlist []string
	NICAllowlist                map[string]bool
	// contains filtered or unexported fields
}

func (*AgentConfig) Read added in v0.12.7

func (c *AgentConfig) Read(path string) error

Read 从给定的文件目录加载配置文件

func (*AgentConfig) Save added in v0.12.7

func (c *AgentConfig) Save() error

type AlertRule

type AlertRule struct {
	Common
	Name                   string
	RulesRaw               string
	Enable                 *bool
	TriggerMode            int      `gorm:"default:0"` // 触发模式: 0-始终触发(默认) 1-单次触发
	NotificationTag        string   // 该报警规则所在的通知组
	FailTriggerTasksRaw    string   `gorm:"default:'[]'"`
	RecoverTriggerTasksRaw string   `gorm:"default:'[]'"`
	Rules                  []Rule   `gorm:"-" json:"-"`
	FailTriggerTasks       []uint64 `gorm:"-" json:"-"` // 失败时执行的触发任务id
	RecoverTriggerTasks    []uint64 `gorm:"-" json:"-"` // 恢复时执行的触发任务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 [][]interface{}) (int, bool)

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

func (*AlertRule) Enabled added in v0.11.3

func (r *AlertRule) Enabled() bool

func (*AlertRule) Snapshot

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

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

type ApiToken added in v0.13.2

type ApiToken struct {
	Common
	UserID uint64 `json:"user_id"`
	Token  string `json:"token"`
	Note   string `json:"note"`
}

type Common

type Common struct {
	ID        uint64         `gorm:"primaryKey"`
	CreatedAt time.Time      `gorm:"index;<-:create"`
	UpdatedAt time.Time      `gorm:"autoUpdateTime"`
	DeletedAt gorm.DeletedAt `gorm:"index"`
}

type Config

type Config struct {
	Debug    bool   // debug模式开关
	Language string // 系统语言,默认 zh-CN
	Site     struct {
		Brand          string // 站点名称
		CookieName     string // 浏览器 Cookie 名称
		Theme          string
		DashboardTheme string
		CustomCode     string
		ViewPassword   string // 前台查看密码
	}
	Oauth2 struct {
		Type         string
		Admin        string // 管理员用户名列表
		ClientID     string
		ClientSecret string
		Endpoint     string
	}
	HTTPPort      uint
	GRPCPort      uint
	GRPCHost      string
	ProxyGRPCPort uint
	TLS           bool

	EnablePlainIPInNotification     bool // 通知信息IP不打码
	DisableSwitchTemplateInFrontend bool // 前台禁用切换模板功能

	// IP变更提醒
	EnableIPChangeNotification bool
	IPChangeNotificationTag    string
	Cover                      uint8  // 覆盖范围(0:提醒未被 IgnoredIPNotification 包含的所有服务器; 1:仅提醒被 IgnoredIPNotification 包含的服务器;)
	IgnoredIPNotification      string // 特定服务器IP(多个服务器用逗号分隔)

	Location string // 时区,默认为 Asia/Shanghai

	IgnoredIPNotificationServerIDs map[uint64]bool // [ServerID] -> bool(值为true代表当前ServerID在特定服务器列表内)
	MaxTCPPingValue                int32
	AvgPingCount                   int

	// 动态域名解析更新
	DDNS struct {
		Enable             bool
		Provider           string
		AccessID           string
		AccessSecret       string
		WebhookURL         string
		WebhookMethod      string
		WebhookRequestBody string
		WebhookHeaders     string
		MaxRetries         uint32
	}
	// contains filtered or unexported fields
}

Config 站点配置

func (*Config) Read

func (c *Config) Read(path string) error

Read 读取配置文件并应用

func (*Config) Save

func (c *Config) Save() error

Save 保存配置文件

type Cron

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

	CronJobID  cron.EntryID `gorm:"-"`
	ServersRaw string
}

func (*Cron) AfterFind

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

type CycleTransferStats added in v0.11.3

type CycleTransferStats struct {
	Name       string
	From       time.Time
	To         time.Time
	Max        uint64
	Min        uint64
	ServerName map[uint64]string
	Transfer   map[uint64]uint64
	NextUpdate map[uint64]time.Time
}

type Host

type Host struct {
	Platform        string
	PlatformVersion string
	CPU             []string
	MemTotal        uint64
	DiskTotal       uint64
	SwapTotal       uint64
	Arch            string
	Virtualization  string
	BootTime        uint64
	IP              string `json:"-"`
	CountryCode     string
	Version         string
}

func PB2Host

func PB2Host(h *pb.Host) Host

func (*Host) PB

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

type HostState

type HostState struct {
	CPU            float64
	MemUsed        uint64
	SwapUsed       uint64
	DiskUsed       uint64
	NetInTransfer  uint64
	NetOutTransfer uint64
	NetInSpeed     uint64
	NetOutSpeed    uint64
	Uptime         uint64
	Load1          float64
	Load5          float64
	Load15         float64
	TcpConnCount   uint64
	UdpConnCount   uint64
	ProcessCount   uint64
}

func PB2State

func PB2State(s *pb.State) HostState

func (*HostState) PB

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

type Monitor

type Monitor struct {
	Common
	Name            string
	Type            uint8
	Target          string
	SkipServersRaw  string
	Duration        uint64
	Notify          bool
	NotificationTag string // 当前服务监控所属的通知组
	Cover           uint8

	EnableTriggerTask      bool     `gorm:"default: false"`
	EnableShowInService    bool     `gorm:"default: false"`
	FailTriggerTasksRaw    string   `gorm:"default:'[]'"`
	RecoverTriggerTasksRaw string   `gorm:"default:'[]'"`
	FailTriggerTasks       []uint64 `gorm:"-" json:"-"` // 失败时执行的触发任务id
	RecoverTriggerTasks    []uint64 `gorm:"-" json:"-"` // 恢复时执行的触发任务id

	MinLatency    float32
	MaxLatency    float32
	LatencyNotify bool

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

func (*Monitor) AfterFind added in v0.4.11

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

func (*Monitor) BeforeSave added in v0.14.12

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

func (*Monitor) CronSpec added in v0.10.0

func (m *Monitor) CronSpec() string

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

func (*Monitor) InitSkipServers added in v0.12.1

func (m *Monitor) InitSkipServers() error

func (*Monitor) PB

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

type MonitorHistory

type MonitorHistory struct {
	ID        uint64         `gorm:"primaryKey"`
	CreatedAt time.Time      `gorm:"index;<-:create;index:idx_server_id_created_at_monitor_id_avg_delay"`
	UpdatedAt time.Time      `gorm:"autoUpdateTime"`
	DeletedAt gorm.DeletedAt `gorm:"index"`
	MonitorID uint64         `gorm:"index:idx_server_id_created_at_monitor_id_avg_delay"`
	ServerID  uint64         `gorm:"index:idx_server_id_created_at_monitor_id_avg_delay"`
	AvgDelay  float32        `gorm:"index:idx_server_id_created_at_monitor_id_avg_delay"` // 平均延迟,毫秒
	Up        uint64         // 检查状态良好计数
	Down      uint64         // 检查状态异常计数
	Data      string
}

MonitorHistory 历史监控记录

type NResult added in v0.8.0

type NResult struct {
	N uint64
}

type Notification

type Notification struct {
	Common
	Name          string
	Tag           string // 分组名
	URL           string
	RequestMethod int
	RequestType   int
	RequestHeader string `gorm:"type:longtext" `
	RequestBody   string `gorm:"type:longtext" `
	VerifySSL     *bool
}

type NotificationServerBundle added in v0.12.15

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

func (*NotificationServerBundle) Send added in v0.12.15

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

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,omitempty"`
	Min           float64         `json:"min,omitempty"`            // 最小阈值 (百分比、字节 kb ÷ 1024)
	Max           float64         `json:"max,omitempty"`            // 最大阈值 (百分比、字节 kb ÷ 1024)
	CycleStart    *time.Time      `json:"cycle_start,omitempty"`    // 流量统计的开始时间
	CycleInterval uint64          `json:"cycle_interval,omitempty"` // 流量统计周期
	CycleUnit     string          `json:"cycle_unit,omitempty"`     // 流量统计周期单位,默认hour,可选(hour, day, week, month, year)
	Duration      uint64          `json:"duration,omitempty"`       // 持续时间 (秒)
	Cover         uint64          `json:"cover,omitempty"`          // 覆盖范围 RuleCoverAll/IgnoreAll
	Ignore        map[uint64]bool `json:"ignore,omitempty"`         // 覆盖范围的排除

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

func (Rule) GetTransferDurationEnd added in v0.12.1

func (rule Rule) GetTransferDurationEnd() time.Time

GetTransferDurationEnd 获取周期流量结束时间

func (Rule) GetTransferDurationStart added in v0.8.0

func (rule Rule) GetTransferDurationStart() time.Time

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

func (Rule) IsTransferDurationRule added in v0.8.0

func (rule Rule) IsTransferDurationRule() bool

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

func (*Rule) Snapshot

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

Snapshot 未通过规则返回 struct{}{}, 通过返回 nil

type Server

type Server struct {
	Common
	Name         string
	Tag          string // 分组名
	Secret       string `gorm:"uniqueIndex" json:"-"`
	Note         string `json:"-"` // 管理员可见备注
	DisplayIndex int    // 展示排序,越大越靠前
	HideForGuest bool   // 对游客隐藏
	EnableDDNS   bool   // 是否启用DDNS 未在配置文件中启用DDNS 或 DDNS检查时间为0时此项无效
	EnableIPv4   bool   // 是否启用DDNS IPv4
	EnableIpv6   bool   // 是否启用DDNS IPv6
	DDNSDomain   string // DDNS中的前缀 如基础域名为abc.oracle DDNSName为mjj 就会把mjj.abc.oracle解析服务器IP 为空则停用

	Host       *Host      `gorm:"-"`
	State      *HostState `gorm:"-"`
	LastActive time.Time  `gorm:"-"`

	TaskClose  chan error                        `gorm:"-" json:"-"`
	TaskStream pb.NezhaService_RequestTaskServer `gorm:"-" json:"-"`

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

func (*Server) CopyFromRunningServer added in v0.8.5

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

func (Server) Marshal

func (s Server) Marshal() template.JS

type ServiceItemResponse added in v0.4.11

type ServiceItemResponse struct {
	Monitor     *Monitor
	CurrentUp   uint64
	CurrentDown uint64
	TotalUp     uint64
	TotalDown   uint64
	Delay       *[30]float32
	Up          *[30]int
	Down        *[30]int
}

func (ServiceItemResponse) TotalUptime added in v0.13.0

func (r ServiceItemResponse) TotalUptime() float32

type TerminalTask added in v0.8.8

type TerminalTask struct {
	// websocket 主机名
	Host string `json:"host,omitempty"`
	// 是否启用 SSL
	UseSSL bool `json:"use_ssl,omitempty"`
	// 会话标识
	Session string `json:"session,omitempty"`
	// Agent在连接Server时需要的额外Cookie信息
	Cookie string `json:"cookie,omitempty"`
}

type Transfer added in v0.8.0

type Transfer struct {
	Common
	ServerID uint64
	In       uint64
	Out      uint64
}

type User

type User struct {
	Common
	Login     string `json:"login,omitempty"`      // 登录名
	AvatarURL string `json:"avatar_url,omitempty"` // 头像地址
	Name      string `json:"name,omitempty"`       // 昵称
	Blog      string `json:"blog,omitempty"`       // 网站链接
	Email     string `json:"email,omitempty"`      // 邮箱
	Hireable  bool   `json:"hireable,omitempty"`
	Bio       string `json:"bio,omitempty"` // 个人简介

	Token        string    `json:"-"`                       // 认证 Token
	TokenExpired time.Time `json:"token_expired,omitempty"` // Token 过期时间
	SuperAdmin   bool      `json:"super_admin,omitempty"`   // 超级管理员
}

func NewUserFromGitHub

func NewUserFromGitHub(gu *github.User) User

func NewUserFromGitea added in v0.14.2

func NewUserFromGitea(gu *gitea.User) User

func NewUserFromGitlab added in v0.13.3

func NewUserFromGitlab(gu *gitlab.User) User

Jump to

Keyboard shortcuts

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