models

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 13, 2017 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Page        = 1      // 当前页数
	PageSize    = 20     // 每页多少条数据
	MaxPageSize = 100000 // 每次最多取多少条
)
View Source
const DefaultTimeFormat = "2006-01-02 15:04:05"
View Source
const MailCode = "mail"
View Source
const MailServerKey = "server"
View Source
const MailUserKey = "user"
View Source
const PasswordSaltLength = 6
View Source
const SlackChannelKey = "channel"
View Source
const SlackCode = "slack"
View Source
const SlackUrlKey = "url"

Variables

View Source
var TablePrefix string = ""

Functions

func CreateDb

func CreateDb() *xorm.Engine

创建Db

func CreateTmpDb

func CreateTmpDb(config map[string]string) (*xorm.Engine, error)

创建临时数据库连接

Types

type BaseModel

type BaseModel struct {
	Page     int `xorm:"-"`
	PageSize int `xorm:"-"`
}

type Channel

type Channel struct {
	Id   int
	Name string
}

type CommonMap

type CommonMap map[string]interface{}

type Host

type Host struct {
	Id        int16            `xorm:"smallint pk autoincr"`
	Name      string           `xorm:"varchar(64) notnull"`              // 主机名称
	Alias     string           `xorm:"varchar(32) notnull default '' "`  // 主机别名
	Username  string           `xorm:"varchar(32) notnull default '' "`  // ssh 用户名
	Port      int              `xorm:"notnull default 22"`               // 主机端口
	Remark    string           `xorm:"varchar(100) notnull default '' "` // 备注
	AuthType  ssh.HostAuthType `xorm:"tinyint notnull default 1"`        // 认证方式 1: 密码 2: 公钥
	BaseModel `xorm:"-"`
}

主机

func (*Host) AllList

func (host *Host) AllList() ([]Host, error)

func (*Host) Create

func (host *Host) Create() (insertId int16, err error)

新增

func (*Host) Delete

func (host *Host) Delete(id int) (int64, error)

删除

func (*Host) Find

func (host *Host) Find(id int) error

func (*Host) GetPasswordByHost

func (h *Host) GetPasswordByHost(host string) (string, error)

func (*Host) GetPrivateKeyByHost

func (h *Host) GetPrivateKeyByHost(host string) (string, error)

func (*Host) List

func (host *Host) List(params CommonMap) ([]Host, error)

func (*Host) NameExists

func (host *Host) NameExists(name string, id int16) (bool, error)

func (*Host) Total

func (host *Host) Total(params CommonMap) (int64, error)

func (*Host) Update

func (host *Host) Update(id int, data CommonMap) (int64, error)

更新

func (*Host) UpdateBean

func (host *Host) UpdateBean(id int16) (int64, error)

type LoginLog

type LoginLog struct {
	Id        int       `xorm:"pk autoincr notnull "`
	Username  string    `xorm:"varchar(32) notnull"`
	Ip        string    `xorm:"varchar(15) not null"`
	Created   time.Time `xorm:"datetime notnull created"`
	BaseModel `xorm:"-"`
}

func (*LoginLog) Create

func (log *LoginLog) Create() (insertId int, err error)

func (*LoginLog) List

func (log *LoginLog) List(params CommonMap) ([]LoginLog, error)

func (*LoginLog) Total

func (log *LoginLog) Total() (int64, error)

type Mail

type Mail struct {
	Host      string
	Port      int
	User      string
	Password  string
	MailUsers []MailUser
}

type MailUser

type MailUser struct {
	Id       int
	Username string
	Email    string
}

type Migration

type Migration struct{}

func (*Migration) Exec

func (migration *Migration) Exec(dbName string) error

type Setting

type Setting struct {
	Id    int    `xorm:"int pk autoincr"`
	Code  string `xorm:"varchar(32) notnull"`
	Key   string `xorm:"varchar(64) notnull"`
	Value string `xorm:"varchar(4096) notnull default '' "`
}

func (*Setting) CreateChannel

func (setting *Setting) CreateChannel(channel string) (int64, error)

创建slack渠道

func (*Setting) CreateMailUser

func (setting *Setting) CreateMailUser(username, email string) (int64, error)

func (*Setting) InitBasicField

func (setting *Setting) InitBasicField()

初始化基本字段 邮件、slack等

func (*Setting) IsChannelExist

func (setting *Setting) IsChannelExist(channel string) bool

func (*Setting) Mail

func (setting *Setting) Mail() (Mail, error)

region 邮件配置

func (*Setting) RemoveChannel

func (setting *Setting) RemoveChannel(id int) (int64, error)

删除slack渠道

func (*Setting) RemoveMailUser

func (setting *Setting) RemoveMailUser(id int) (int64, error)

func (*Setting) Slack

func (setting *Setting) Slack() (Slack, error)

func (*Setting) UpdateMailServer

func (setting *Setting) UpdateMailServer(config string) (int64, error)

func (*Setting) UpdateSlackUrl

func (setting *Setting) UpdateSlackUrl(url string) (int64, error)

更新slack webhook url

type Slack

type Slack struct {
	Url      string
	Channels []Channel
}

type Status

type Status int8
const (
	Disabled   Status = 0 // 禁用
	Failure    Status = 0 // 失败
	Enabled    Status = 1 // 启用
	Running    Status = 1 // 运行中
	Finish     Status = 2 // 完成
	Cancel     Status = 3 // 取消
	Background Status = 4 // 后台运行
)

type Task

type Task struct {
	Id               int          `xorm:"int pk autoincr"`
	Name             string       `xorm:"varchar(32) notnull"`              // 任务名称
	Spec             string       `xorm:"varchar(64) notnull"`              // crontab
	Protocol         TaskProtocol `xorm:"tinyint notnull"`                  // 协议 1:http 2:ssh-command 3: 系统命令
	Command          string       `xorm:"varchar(256) notnull"`             // URL地址或shell命令
	Timeout          int          `xorm:"mediumint notnull default 0"`      // 任务执行超时时间(单位秒),0不限制
	Multi            int8         `xorm:"tinyint notnull default 1"`        // 是否允许多实例运行
	RetryTimes       int8         `xorm:"tinyint notnull default 0"`        // 重试次数
	HostId           int16        `xorm:"smallint notnull default 0"`       // SSH host id,
	NotifyStatus     int8         `xorm:"smallint notnull default 1"`       // 任务执行结束是否通知 0: 不通知 1: 失败通知 2: 执行结束通知
	NotifyType       int8         `xorm:"smallint notnull default 0"`       // 通知类型 1: 邮件 2: slack
	NotifyReceiverId string       `xorm:"varchar(256) notnull default '' "` // 通知接受者ID, setting表主键ID,多个ID逗号分隔
	Remark           string       `xorm:"varchar(100) notnull default ''"`  // 备注
	Status           Status       `xorm:"tinyint notnull default 0"`        // 状态 1:正常 0:停止
	Created          time.Time    `xorm:"datetime notnull created"`         // 创建时间
	Deleted          time.Time    `xorm:"datetime deleted"`                 // 删除时间
	BaseModel        `xorm:"-"`
}

任务

func (*Task) ActiveList

func (task *Task) ActiveList() ([]TaskHost, error)

获取所有激活任务

func (*Task) ActiveListByHostId

func (task *Task) ActiveListByHostId(hostId int16) ([]TaskHost, error)

获取某个主机下的所有激活任务

func (*Task) Create

func (task *Task) Create() (insertId int, err error)

新增

func (*Task) CreateTestTask

func (task *Task) CreateTestTask()

新增测试任务

func (*Task) Delete

func (task *Task) Delete(id int) (int64, error)

删除

func (*Task) Detail

func (task *Task) Detail(id int) (TaskHost, error)

func (*Task) Disable

func (task *Task) Disable(id int) (int64, error)

禁用

func (*Task) Enable

func (task *Task) Enable(id int) (int64, error)

激活

func (*Task) HostIdExist

func (task *Task) HostIdExist(hostId int16) (bool, error)

判断主机id是否有引用

func (*Task) List

func (task *Task) List(params CommonMap) ([]TaskHost, error)

func (*Task) NameExist

func (task *Task) NameExist(name string, id int) (bool, error)

判断任务名称是否存在

func (*Task) Total

func (task *Task) Total(params CommonMap) (int64, error)

func (*Task) Update

func (task *Task) Update(id int, data CommonMap) (int64, error)

更新

func (*Task) UpdateBean

func (task *Task) UpdateBean(id int) (int64, error)

type TaskHost

type TaskHost struct {
	Task     `xorm:"extends"`
	Name     string
	Port     int
	Username string
	Alias    string
	AuthType ssh.HostAuthType
}

func (TaskHost) TableName

func (TaskHost) TableName() string

type TaskLog

type TaskLog struct {
	Id         int64        `xorm:"bigint pk autoincr"`
	TaskId     int          `xorm:"int notnull index default 0"`      // 任务id
	Name       string       `xorm:"varchar(32) notnull"`              // 任务名称
	Spec       string       `xorm:"varchar(64) notnull"`              // crontab
	Protocol   TaskProtocol `xorm:"tinyint notnull"`                  // 协议 1:http 2:ssh-command 3:系统命令
	Command    string       `xorm:"varchar(256) notnull"`             // URL地址或shell命令
	Timeout    int          `xorm:"mediumint notnull default 0"`      // 任务执行超时时间(单位秒),0不限制
	RetryTimes int8         `xorm:"tinyint notnull default 0"`        // 任务重试次数
	Hostname   string       `xorm:"varchar(128) notnull defalut '' "` // SSH主机名,逗号分隔
	StartTime  time.Time    `xorm:"datetime created"`                 // 开始执行时间
	EndTime    time.Time    `xorm:"datetime updated"`                 // 执行完成(失败)时间
	Status     Status       `xorm:"tinyint notnull default 1"`        // 状态 0:执行失败 1:执行中  2:执行完毕 3:任务取消(上次任务未执行完成) 4:异步执行
	NotifyId   string       `xorm:"varchar(32) notnull default '' "`  // 回调通知ID
	Result     string       `xorm:"mediumtext notnull defalut '' "`   // 执行结果
	TotalTime  int          `xorm:"-"`                                // 执行总时长
	BaseModel  `xorm:"-"`
}

任务执行日志

func (*TaskLog) Clear

func (taskLog *TaskLog) Clear() (int64, error)

清空表

func (*TaskLog) Create

func (taskLog *TaskLog) Create() (insertId int64, err error)

func (*TaskLog) GetTaskIdByNotifyId

func (taskLog *TaskLog) GetTaskIdByNotifyId(notifyId string) (taskId int, err error)

根据通知ID获取任务ID

func (*TaskLog) List

func (taskLog *TaskLog) List(params CommonMap) ([]TaskLog, error)

func (*TaskLog) Remove

func (taskLog *TaskLog) Remove(id int) (int64, error)

删除N个月前的日志

func (*TaskLog) Total

func (taskLog *TaskLog) Total(params CommonMap) (int64, error)

func (*TaskLog) Update

func (taskLog *TaskLog) Update(id int64, data CommonMap) (int64, error)

更新

func (*TaskLog) UpdateStatus

func (taskLog *TaskLog) UpdateStatus(notifyId string, status Status, result string) (int64, error)

type TaskProtocol

type TaskProtocol int8
const (
	TaskHTTP         TaskProtocol = iota + 1 // HTTP协议
	TaskSSH                                  // SSH命令
	TaskLocalCommand                         // 本地命令
)

type TaskType

type TaskType int8

type User

type User struct {
	Id        int       `xorm:"pk autoincr notnull "`
	Name      string    `xorm:"varchar(32) notnull unique"`             // 用户名
	Password  string    `xorm:"char(32) notnull "`                      // 密码
	Salt      string    `xorm:"char(6) notnull "`                       // 密码盐值
	Email     string    `xorm:"varchar(50) notnull unique default '' "` // 邮箱
	Created   time.Time `xorm:"datetime notnull created"`
	Updated   time.Time `xorm:"datetime updated"`
	Deleted   time.Time `xorm:"datetime deleted"`
	IsAdmin   int8      `xorm:"tinyint notnull default 0"` // 是否是管理员 1:管理员 0:普通用户
	Status    Status    `xorm:"tinyint notnull default 1"` // 1: 正常 0:禁用
	BaseModel `xorm:"-"`
}

用户model

func (*User) Create

func (user *User) Create() (insertId int, err error)

新增

func (*User) Delete

func (user *User) Delete(id int) (int64, error)

删除

func (*User) Disable

func (user *User) Disable(id int) (int64, error)

禁用

func (*User) EmailExists

func (user *User) EmailExists(email string) (int64, error)

邮箱地址是否存在

func (*User) Enable

func (user *User) Enable(id int) (int64, error)

激活

func (*User) List

func (user *User) List() ([]User, error)

func (*User) Match

func (user *User) Match(username, password string) bool

验证用户名和密码

func (*User) Total

func (user *User) Total() (int64, error)

func (*User) Update

func (user *User) Update(id int, data CommonMap) (int64, error)

更新

func (*User) UpdatePassword

func (user *User) UpdatePassword(id int, password string) (int64, error)

func (*User) UsernameExists

func (user *User) UsernameExists(username string) (int64, error)

用户名是否存在

Jump to

Keyboard shortcuts

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