Documentation
¶
Index ¶
- Constants
- Variables
- func CreateDb() *gorm.DB
- func CreateTmpDb(setting *setting.Setting) (*gorm.DB, error)
- func RepairSettings() error
- type AgentToken
- type BaseModel
- type Channel
- type CommonMap
- type Host
- func (host *Host) AllList() ([]Host, error)
- func (host *Host) Create() (insertId int16, err error)
- func (host *Host) Delete(id int) (int64, error)
- func (host *Host) Find(id int) error
- func (host *Host) List(params CommonMap) ([]Host, error)
- func (host *Host) NameExists(name string, id int16) (bool, error)
- func (host *Host) Total(params CommonMap) (int64, error)
- func (host *Host) Update(id int, data CommonMap) (int64, error)
- func (host *Host) UpdateBean(id int16) (int64, error)
- type LocalTime
- type LoginLog
- type Mail
- type MailUser
- type Migration
- type Setting
- func (setting *Setting) CreateChannel(channel string) (int64, error)
- func (setting *Setting) CreateMailUser(username, email string) (int64, error)
- func (setting *Setting) GetLogCleanupTime() string
- func (setting *Setting) GetLogFileSizeLimit() int
- func (setting *Setting) GetLogRetentionDays() int
- func (setting *Setting) IsChannelExist(channel string) bool
- func (setting *Setting) Mail() (Mail, error)
- func (setting *Setting) RemoveChannel(id int) (int64, error)
- func (setting *Setting) RemoveMailUser(id int) (int64, error)
- func (setting *Setting) Slack() (Slack, error)
- func (setting *Setting) UpdateLogCleanupTime(cleanupTime string) error
- func (setting *Setting) UpdateLogFileSizeLimit(size int) error
- func (setting *Setting) UpdateLogRetentionDays(days int) error
- func (setting *Setting) UpdateMail(config, template string) error
- func (setting *Setting) UpdateSlack(url, template string) error
- func (setting *Setting) UpdateWebHook(url, template string) error
- func (setting *Setting) Webhook() (WebHook, error)
- type Slack
- type Status
- type Task
- func (task *Task) ActiveList(page, pageSize int) ([]Task, error)
- func (task *Task) ActiveListByHostId(hostId int16) ([]Task, error)
- func (task *Task) Create() (insertId int, err error)
- func (task *Task) Delete(id int) (int64, error)
- func (task *Task) Detail(id int) (Task, error)
- func (task *Task) Disable(id int) (int64, error)
- func (task *Task) Enable(id int) (int64, error)
- func (task *Task) GetDependencyTaskList(ids string) ([]Task, error)
- func (task *Task) GetStatus(id int) (Status, error)
- func (task *Task) List(params CommonMap) ([]Task, error)
- func (task *Task) NameExist(name string, id int) (bool, error)
- func (task *Task) Total(params CommonMap) (int64, error)
- func (task *Task) Update(id int, data CommonMap) (int64, error)
- func (task *Task) UpdateBean(id int) (int64, error)
- type TaskDependencyStatus
- type TaskHTTPMethod
- type TaskHost
- func (th *TaskHost) Add(taskId int, hostIds []int) error
- func (th *TaskHost) GetHostIdsByTaskId(taskId int) ([]TaskHostDetail, error)
- func (th *TaskHost) GetTaskIdsByHostId(hostId int16) ([]interface{}, error)
- func (th *TaskHost) HostIdExist(hostId int16) (bool, error)
- func (th *TaskHost) Remove(taskId int) error
- type TaskHostDetail
- type TaskLevel
- type TaskLog
- func (taskLog *TaskLog) Clear() (int64, error)
- func (taskLog *TaskLog) Create() (insertId int64, err error)
- func (taskLog *TaskLog) List(params CommonMap) ([]TaskLog, error)
- func (taskLog *TaskLog) Remove(id int) (int64, error)
- func (taskLog *TaskLog) RemoveByDays(days int) (int64, error)
- func (taskLog *TaskLog) Total(params CommonMap) (int64, error)
- func (taskLog *TaskLog) Update(id int64, data CommonMap) (int64, error)
- type TaskProtocol
- type TaskType
- type User
- func (user *User) Create() (insertId int, err error)
- func (user *User) Delete(id int) (int64, error)
- func (user *User) Disable(id int) (int64, error)
- func (user *User) EmailExists(email string, uid int) (int64, error)
- func (user *User) Enable(id int) (int64, error)
- func (user *User) Find(id int) error
- func (user *User) List(params CommonMap) ([]User, error)
- func (user *User) Match(username, password string) bool
- func (user *User) Total() (int64, error)
- func (user *User) Update(id int, data CommonMap) (int64, error)
- func (user *User) UpdatePassword(id int, password string) (int64, error)
- func (user *User) UsernameExists(username string, uid int) (int64, error)
- type WebHook
Constants ¶
View Source
const ( Page = 1 // 当前页数 PageSize = 20 // 每页多少条数据 MaxPageSize = 1000 // 每次最多取多少条 )
View Source
const ( SlackCode = "slack" SlackUrlKey = "url" SlackTemplateKey = "template" SlackChannelKey = "channel" )
View Source
const ( MailCode = "mail" MailTemplateKey = "template" MailServerKey = "server" MailUserKey = "user" )
View Source
const ( WebhookCode = "webhook" WebhookTemplateKey = "template" WebhookUrlKey = "url" )
View Source
const ( SystemCode = "system" LogRetentionDaysKey = "log_retention_days" LogCleanupTimeKey = "log_cleanup_time" LogFileSizeLimitKey = "log_file_size_limit" )
View Source
const DefaultTimeFormat = "2006-01-02 15:04:05"
View Source
const PasswordSaltLength = 6
Variables ¶
View Source
var Db *gorm.DB
View Source
var TablePrefix = ""
Functions ¶
func RepairSettings ¶ added in v1.3.1
func RepairSettings() error
RepairSettings 修复缺失的 Setting 配置记录 用于解决数据库迁移或升级过程中可能出现的配置缺失问题
Types ¶
type AgentToken ¶ added in v1.3.15
type AgentToken struct {
Id int `json:"id" gorm:"primaryKey;autoIncrement"`
Token string `json:"token" gorm:"type:varchar(64);uniqueIndex;not null"`
ExpiresAt time.Time `json:"expires_at" gorm:"not null"`
Used bool `json:"used" gorm:"default:false"`
UsedAt *time.Time `json:"used_at" gorm:"default:null"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
}
AgentToken agent注册token
func (*AgentToken) CleanExpired ¶ added in v1.3.15
func (t *AgentToken) CleanExpired() error
CleanExpired 清理过期token
func (*AgentToken) Create ¶ added in v1.3.15
func (t *AgentToken) Create() error
func (*AgentToken) FindByToken ¶ added in v1.3.15
func (t *AgentToken) FindByToken(token string) error
func (*AgentToken) IsValid ¶ added in v1.3.15
func (t *AgentToken) IsValid() bool
func (*AgentToken) MarkAsUsed ¶ added in v1.3.15
func (t *AgentToken) MarkAsUsed() error
type Host ¶
type Host struct {
Id int16 `json:"id" gorm:"primaryKey;autoIncrement;type:smallint"`
Name string `json:"name" gorm:"type:varchar(64);not null"`
Alias string `json:"alias" gorm:"type:varchar(32);not null;default:''"`
Port int `json:"port" gorm:"not null;default:5921"`
Remark string `json:"remark" gorm:"type:varchar(100);not null;default:''"`
BaseModel `json:"-" gorm:"-"`
Selected bool `json:"-" gorm:"-"`
}
主机
type LocalTime ¶ added in v1.3.1
func (LocalTime) MarshalJSON ¶ added in v1.3.1
func (*LocalTime) UnmarshalJSON ¶ added in v1.3.1
type LoginLog ¶
type LoginLog struct {
Id int `json:"id" gorm:"primaryKey;autoIncrement"`
Username string `json:"username" gorm:"type:varchar(32);not null"`
Ip string `json:"ip" gorm:"type:varchar(15);not null"`
CreatedAt time.Time `json:"created" gorm:"column:created;autoCreateTime"`
BaseModel `json:"-" gorm:"-"`
}
用户登录日志
type Setting ¶
type Setting struct {
Id int `gorm:"primaryKey;autoIncrement"`
Code string `gorm:"type:varchar(32);not null"`
Key string `gorm:"type:varchar(64);not null"`
Value string `gorm:"type:varchar(4096);not null;default:''"`
}
func (*Setting) CreateChannel ¶
创建slack渠道
func (*Setting) CreateMailUser ¶
func (*Setting) GetLogCleanupTime ¶
func (*Setting) GetLogFileSizeLimit ¶
func (*Setting) IsChannelExist ¶
func (*Setting) RemoveChannel ¶
删除slack渠道
func (*Setting) UpdateLogCleanupTime ¶
func (*Setting) UpdateLogFileSizeLimit ¶
func (*Setting) UpdateLogRetentionDays ¶
func (*Setting) UpdateMail ¶
func (*Setting) UpdateSlack ¶
func (*Setting) UpdateWebHook ¶
type Task ¶
type Task struct {
Id int `json:"id" gorm:"primaryKey;autoIncrement"`
Name string `json:"name" gorm:"type:varchar(32);not null"`
Level TaskLevel `json:"level" gorm:"type:tinyint;not null;index;default:1"`
DependencyTaskId string `json:"dependency_task_id" gorm:"type:varchar(64);not null;default:''"`
DependencyStatus TaskDependencyStatus `json:"dependency_status" gorm:"type:tinyint;not null;default:1"`
Spec string `json:"spec" gorm:"type:varchar(64);not null"`
Protocol TaskProtocol `json:"protocol" gorm:"type:tinyint;not null;index"`
Command string `json:"command" gorm:"type:varchar(256);not null"`
HttpMethod TaskHTTPMethod `json:"http_method" gorm:"type:tinyint;not null;default:1"`
Timeout int `json:"timeout" gorm:"type:mediumint;not null;default:0"`
Multi int8 `json:"multi" gorm:"type:tinyint;not null;default:1"`
RetryTimes int8 `json:"retry_times" gorm:"type:tinyint;not null;default:0"`
RetryInterval int16 `json:"retry_interval" gorm:"type:smallint;not null;default:0"`
NotifyStatus int8 `json:"notify_status" gorm:"type:tinyint;not null;default:1"`
NotifyType int8 `json:"notify_type" gorm:"type:tinyint;not null;default:0"`
NotifyReceiverId string `json:"notify_receiver_id" gorm:"type:varchar(256);not null;default:''"`
NotifyKeyword string `json:"notify_keyword" gorm:"type:varchar(128);not null;default:''"`
Tag string `json:"tag" gorm:"type:varchar(32);not null;default:''"`
Remark string `json:"remark" gorm:"type:varchar(100);not null;default:''"`
Status Status `json:"status" gorm:"type:tinyint;not null;index;default:0"`
CreatedAt time.Time `json:"created" gorm:"column:created;autoCreateTime"`
DeletedAt *time.Time `json:"deleted" gorm:"column:deleted;index"`
BaseModel `json:"-" gorm:"-"`
Hosts []TaskHostDetail `json:"hosts" gorm:"-"`
NextRunTime time.Time `json:"next_run_time" gorm:"-"`
}
任务
func (*Task) ActiveListByHostId ¶
获取某个主机下的所有激活任务
func (*Task) GetDependencyTaskList ¶
获取依赖任务列表
type TaskDependencyStatus ¶
type TaskDependencyStatus int8
const ( TaskDependencyStatusStrong TaskDependencyStatus = 1 // 强依赖 TaskDependencyStatusWeak TaskDependencyStatus = 2 // 弱依赖 )
type TaskHTTPMethod ¶
type TaskHTTPMethod int8
const ( TaskHTTPMethodGet TaskHTTPMethod = 1 TaskHttpMethodPost TaskHTTPMethod = 2 )
type TaskHost ¶
type TaskHost struct {
Id int `json:"id" gorm:"primaryKey;autoIncrement"`
TaskId int `json:"task_id" gorm:"not null;index"`
HostId int16 `json:"host_id" gorm:"type:smallint;not null;index"`
}
func (*TaskHost) GetHostIdsByTaskId ¶
func (th *TaskHost) GetHostIdsByTaskId(taskId int) ([]TaskHostDetail, error)
func (*TaskHost) GetTaskIdsByHostId ¶
func (*TaskHost) HostIdExist ¶
判断主机id是否有引用
type TaskHostDetail ¶
type TaskHostDetail struct {
TaskHost
Name string `json:"name"`
Port int `json:"port"`
Alias string `json:"alias"`
}
func (TaskHostDetail) TableName ¶
func (TaskHostDetail) TableName() string
type TaskLog ¶
type TaskLog struct {
Id int64 `json:"id" gorm:"primaryKey;autoIncrement;type:bigint"`
TaskId int `json:"task_id" gorm:"not null;index;default:0"`
Name string `json:"name" gorm:"type:varchar(32);not null"`
Spec string `json:"spec" gorm:"type:varchar(64);not null"`
Protocol TaskProtocol `json:"protocol" gorm:"type:tinyint;not null;index"`
Command string `json:"command" gorm:"type:varchar(256);not null"`
Timeout int `json:"timeout" gorm:"type:mediumint;not null;default:0"`
RetryTimes int8 `json:"retry_times" gorm:"type:tinyint;not null;default:0"`
Hostname string `json:"hostname" gorm:"type:varchar(128);not null;default:''"`
StartTime LocalTime `json:"start_time" gorm:"column:start_time;autoCreateTime"`
EndTime LocalTime `json:"end_time" gorm:"column:end_time;autoUpdateTime"`
Status Status `json:"status" gorm:"type:tinyint;not null;index;default:1"`
Result string `json:"result" gorm:"type:mediumtext;not null"`
TotalTime int `json:"total_time" gorm:"-"`
BaseModel `json:"-" gorm:"-"`
}
任务执行日志
func (*TaskLog) RemoveByDays ¶
删除N天前的日志
type TaskProtocol ¶
type TaskProtocol int8
const ( TaskHTTP TaskProtocol = iota + 1 // HTTP协议 TaskRPC // RPC方式执行命令 )
type User ¶
type User struct {
Id int `json:"id" gorm:"primaryKey;autoIncrement"`
Name string `json:"name" gorm:"type:varchar(32);not null;uniqueIndex"`
Password string `json:"-" gorm:"type:char(32);not null"`
Salt string `json:"-" gorm:"type:char(6);not null"`
Email string `json:"email" gorm:"type:varchar(50);not null;uniqueIndex;default:''"`
TwoFactorKey string `json:"-" gorm:"column:two_factor_key;type:varchar(100);default:''"`
TwoFactorOn int8 `json:"two_factor_on" gorm:"column:two_factor_on;type:tinyint;not null;default:0"`
CreatedAt time.Time `json:"created" gorm:"column:created;autoCreateTime"`
UpdatedAt time.Time `json:"updated" gorm:"column:updated;autoUpdateTime"`
IsAdmin int8 `json:"is_admin" gorm:"type:tinyint;not null;default:0"`
Status Status `json:"status" gorm:"type:tinyint;not null;default:1"`
BaseModel `json:"-" gorm:"-"`
}
用户model
func (*User) EmailExists ¶
邮箱地址是否存在
func (*User) UpdatePassword ¶
Click to show internal directories.
Click to hide internal directories.