notices

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2020 License: MIT, MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FormatText     = "text"
	FormatMarkdown = "markdown"
)

常用的内容文本格式

View Source
const (
	NoticeLevelNone    = NoticeLevel(0)
	NoticeLevelInfo    = NoticeLevel(1)
	NoticeLevelWarning = NoticeLevel(2)
	NoticeLevelError   = NoticeLevel(3)
	NoticeLevelSuccess = NoticeLevel(4)
)

通知级别常量

View Source
const (
	NoticeMediaTypeEmail         = "email"
	NoticeMediaTypeWebhook       = "webhook"
	NoticeMediaTypeScript        = "script"
	NoticeMediaTypeDingTalk      = "dingTalk"
	NoticeMediaTypeQyWeixin      = "qyWeixin"
	NoticeMediaTypeQyWeixinRobot = "qyWeixinRobot"
	NoticeMediaTypeAliyunSms     = "aliyunSms"
	NoticeMediaTypeTelegram      = "telegram"
	NoticeMediaTypeTeaSms        = "teaSms"
)

Variables

This section is empty.

Functions

func AllNoticeLevels

func AllNoticeLevels() []maps.Map

所有的通知级别

func AllNoticeMediaTypes

func AllNoticeMediaTypes() []maps.Map

所有媒介

func FindNoticeLevel

func FindNoticeLevel(level NoticeLevel) maps.Map

获取通知级别信息

func FindNoticeLevelName

func FindNoticeLevelName(level NoticeLevel) string

获取通知级别名称

func FindNoticeMediaType

func FindNoticeMediaType(mediaType string) maps.Map

查找媒介类型

func FindNoticeMediaTypeName

func FindNoticeMediaTypeName(mediaType string) string

查找媒介类型名称

func IsFailureLevel

func IsFailureLevel(level NoticeLevel) bool

判断是否为失败级别

Types

type AgentCond

type AgentCond struct {
	AgentId   string `bson:"agentId" json:"agentId"`
	AppId     string `bson:"appId" json:"appId"`
	TaskId    string `bson:"taskId" json:"taskId"`
	ItemId    string `bson:"itemId" json:"itemId"`
	Level     uint8  `bson:"level" json:"level"`
	Threshold string `bson:"threshold" json:"threshold"`
}

Agent条件

type Item

type Item struct {
	On        bool              `yaml:"on" json:"on"` // 是否开启
	Level     NoticeLevel       `yaml:"level" json:"level"`
	Receivers []*NoticeReceiver `yaml:"receivers" json:"receivers"`
	Subject   string            `yaml:"subject" json:"subject"`
	Body      string            `yaml:"body" json:"body"`
}

通知条目配置,用于某个项目的细项通知配置

func NewItem

func NewItem(level NoticeLevel) *Item

获取新对象

func NewItemFromRequest

func NewItemFromRequest(req *http.Request, name string) *Item

从请求中获取新对象

func (*Item) FormatBody

func (this *Item) FormatBody(vars maps.Map) string

取得替换变量后的内容

func (*Item) FormatSubject

func (this *Item) FormatSubject(vars maps.Map) string

取得替换变量后的标题

type Notice

type Notice struct {
	Id          shared.ObjectId `bson:"_id" json:"id"`                  // 数据库存储的ID
	Proxy       ProxyCond       `bson:"proxy" json:"proxy"`             // 代理相关参数
	Agent       AgentCond       `bson:"agent" json:"agent"`             // 主机相关参数
	Timestamp   int64           `bson:"timestamp" json:"timestamp"`     // 时间戳
	Message     string          `bson:"message" json:"message"`         // 消息内容
	MessageHash string          `bson:"messageHash" json:"messageHash"` // 消息内容Hash:crc32(message)
	IsRead      bool            `bson:"isRead" json:"isRead"`           // 已读
	IsNotified  bool            `bson:"isNotified" json:"isNotified"`   // 是否发送通知
	Receivers   []string        `bson:"receivers" json:"receivers"`     // 接收人ID列表
}

通知

func NewNotice

func NewNotice() *Notice

获取通知对象

func (*Notice) DBColumns

func (this *Notice) DBColumns() maps.Map

获取数据库列值

func (*Notice) Hash

func (this *Notice) Hash()

计算Hash

func (*Notice) SetDBColumns

func (this *Notice) SetDBColumns(v maps.Map)

设置数据库列值

func (*Notice) SetTime

func (this *Notice) SetTime(t time.Time)

设置时间

type NoticeAliyunSmsMedia

type NoticeAliyunSmsMedia struct {
	Sign            string             `yaml:"sign" json:"sign"`                       // 签名名称
	TemplateCode    string             `yaml:"templateCode" json:"templateCode"`       // 模板CODE
	Variables       []*shared.Variable `yaml:"variables" json:"variables"`             // 变量
	AccessKeyId     string             `yaml:"accessKeyId" json:"accessKeyId"`         // AccessKeyId
	AccessKeySecret string             `yaml:"accessKeySecret" json:"accessKeySecret"` // AccessKeySecret
}

阿里云短信

func NewNoticeAliyunSmsMedia

func NewNoticeAliyunSmsMedia() *NoticeAliyunSmsMedia

获取新对象

func (*NoticeAliyunSmsMedia) RequireUser

func (this *NoticeAliyunSmsMedia) RequireUser() bool

是否需要用户标识

func (*NoticeAliyunSmsMedia) Send

func (this *NoticeAliyunSmsMedia) Send(user string, subject string, body string) (resp []byte, err error)

type NoticeDingTalkMedia

type NoticeDingTalkMedia struct {
	WebhookURL string `yaml:"webhookURL" json:"webhookURL"`
}

钉钉群机器人媒介

func NewNoticeDingTalkMedia

func NewNoticeDingTalkMedia() *NoticeDingTalkMedia

获取新对象

func (*NoticeDingTalkMedia) RequireUser

func (this *NoticeDingTalkMedia) RequireUser() bool

是否需要用户标识

func (*NoticeDingTalkMedia) Send

func (this *NoticeDingTalkMedia) Send(user string, subject string, body string) (resp []byte, err error)

type NoticeEmailMedia

type NoticeEmailMedia struct {
	SMTP     string `yaml:"smtp" json:"smtp"`
	Username string `yaml:"username" json:"username"`
	Password string `yaml:"password" json:"password"`
	From     string `yaml:"from" json:"from"`
}

邮件媒介

func NewNoticeEmailMedia

func NewNoticeEmailMedia() *NoticeEmailMedia

获取新对象

func (*NoticeEmailMedia) RequireUser

func (this *NoticeEmailMedia) RequireUser() bool

是否需要用户标识

func (*NoticeEmailMedia) Send

func (this *NoticeEmailMedia) Send(user string, subject string, body string) (resp []byte, err error)

func (*NoticeEmailMedia) SendMail

func (this *NoticeEmailMedia) SendMail(from string, to []string, message []byte) error

type NoticeLevel

type NoticeLevel = uint8

通知级别类型

type NoticeLevelConfig

type NoticeLevelConfig struct {
	ShouldNotify bool              `yaml:"shouldNotify" json:"shouldNotify"`
	Receivers    []*NoticeReceiver `yaml:"receivers" json:"receivers"`
}

级别配置

func (*NoticeLevelConfig) AddReceiver

func (this *NoticeLevelConfig) AddReceiver(receiver *NoticeReceiver)

添加接收人

func (*NoticeLevelConfig) FindReceiver

func (this *NoticeLevelConfig) FindReceiver(receiverId string) *NoticeReceiver

查找单个接收人

func (*NoticeLevelConfig) RemoveMediaReceivers

func (this *NoticeLevelConfig) RemoveMediaReceivers(mediaId string)

移除某个媒介的所有接收人

func (*NoticeLevelConfig) RemoveReceiver

func (this *NoticeLevelConfig) RemoveReceiver(receiverId string)

移除接收人

type NoticeMediaConfig

type NoticeMediaConfig struct {
	Id          string                 `yaml:"id" json:"id"`
	On          bool                   `yaml:"on" json:"on"`
	Name        string                 `yaml:"name" json:"name"`
	Type        NoticeMediaType        `yaml:"type" json:"type"`
	Options     map[string]interface{} `yaml:"options" json:"options"`
	TimeFrom    string                 `yaml:"timeFrom" json:"timeFrom"`       // 发送的开始时间
	TimeTo      string                 `yaml:"timeTo" json:"timeTo"`           // 发送的结束时间
	RateMinutes int                    `yaml:"rateMinutes" json:"rateMinutes"` // 速率限制之时间范围
	RateCount   int                    `yaml:"rateCount" json:"rateCount"`     // 速率限制之数量
}

媒介配置定义

func NewNoticeMediaConfig

func NewNoticeMediaConfig() *NoticeMediaConfig

获取新对象

func (*NoticeMediaConfig) Raw

取得原始的媒介

func (*NoticeMediaConfig) ShouldNotify

func (this *NoticeMediaConfig) ShouldNotify(countSent int) bool

是否应该推送

func (*NoticeMediaConfig) Validate

func (this *NoticeMediaConfig) Validate() error

校验

type NoticeMediaInterface

type NoticeMediaInterface interface {
	// 发送
	Send(user string, subject string, body string) (resp []byte, err error)

	// 是否可以需要用户标识
	RequireUser() bool
}

媒介接口

type NoticeMediaType

type NoticeMediaType = string

通知媒介类型

type NoticeQyWeixinMedia

type NoticeQyWeixinMedia struct {
	CorporateId string     `yaml:"corporateId" json:"corporateId"`
	AgentId     string     `yaml:"agentId" json:"agentId"`
	AppSecret   string     `yaml:"appSecret" json:"appSecret"`
	TextFormat  TextFormat `yaml:"textFormat" json:"textFormat"`
}

企业微信媒介

func NewNoticeQyWeixinMedia

func NewNoticeQyWeixinMedia() *NoticeQyWeixinMedia

获取新对象

func (*NoticeQyWeixinMedia) RequireUser

func (this *NoticeQyWeixinMedia) RequireUser() bool

是否需要用户标识

func (*NoticeQyWeixinMedia) Send

func (this *NoticeQyWeixinMedia) Send(user string, subject string, body string) (respData []byte, err error)

type NoticeQyWeixinRobotMedia

type NoticeQyWeixinRobotMedia struct {
	WebhookURL string     `yaml:"webhookURL" json:"webhookURL"`
	TextFormat TextFormat `yaml:"textFormat" json:"textFormat"`
}

企业微信群机器人媒介

func NewNoticeQyWeixinRobotMedia

func NewNoticeQyWeixinRobotMedia() *NoticeQyWeixinRobotMedia

获取新对象

func (*NoticeQyWeixinRobotMedia) RequireUser

func (this *NoticeQyWeixinRobotMedia) RequireUser() bool

是否需要用户标识

func (*NoticeQyWeixinRobotMedia) Send

func (this *NoticeQyWeixinRobotMedia) Send(user string, subject string, body string) (resp []byte, err error)

type NoticeReceiver

type NoticeReceiver struct {
	Id      string `yaml:"id" json:"id"`
	On      bool   `yaml:"on" json:"on"`
	Name    string `yaml:"name" json:"name"`
	MediaId string `yaml:"mediaId" json:"mediaId"`
	User    string `yaml:"user" json:"user"` // 用户标识
}

接收者

func NewNoticeReceiver

func NewNoticeReceiver() *NoticeReceiver

获取新对象

func (*NoticeReceiver) Key

func (this *NoticeReceiver) Key() string

获取唯一的Key

type NoticeScriptMedia

type NoticeScriptMedia struct {
	Path       string             `yaml:"path" json:"path"`
	ScriptType string             `yaml:"scriptType" json:"scriptType"` // 脚本类型,可以为path, code
	ScriptLang string             `yaml:"scriptLang" json:"scriptLang"` // 脚本语言
	Script     string             `yaml:"script" json:"script"`         // 脚本代码
	Cwd        string             `yaml:"cwd" json:"cwd"`
	Env        []*shared.Variable `yaml:"env" json:"env"`
}

脚本媒介

func NewNoticeScriptMedia

func NewNoticeScriptMedia() *NoticeScriptMedia

获取新对象

func (*NoticeScriptMedia) AddEnv

func (this *NoticeScriptMedia) AddEnv(name, value string)

添加环境变量

func (*NoticeScriptMedia) FormattedScript

func (this *NoticeScriptMedia) FormattedScript() string

格式化脚本

func (*NoticeScriptMedia) Generate

func (this *NoticeScriptMedia) Generate(id string) (path string, err error)

保存到本地

func (*NoticeScriptMedia) RequireUser

func (this *NoticeScriptMedia) RequireUser() bool

是否需要用户标识

func (*NoticeScriptMedia) Send

func (this *NoticeScriptMedia) Send(user string, subject string, body string) (resp []byte, err error)

发送

type NoticeSetting

type NoticeSetting struct {
	Levels map[NoticeLevel]*NoticeLevelConfig `yaml:"levels" json:"levels"`
	Medias []*NoticeMediaConfig               `yaml:"medias" json:"medias"`

	SoundOn bool `yaml:"soundOn" json:"soundOn"` // 提示声音
}

通知设置

func SharedNoticeSetting

func SharedNoticeSetting() *NoticeSetting

取得当前的配置

func (*NoticeSetting) AddMedia

func (this *NoticeSetting) AddMedia(mediaConfig *NoticeMediaConfig)

添加媒介配置

func (*NoticeSetting) FindAllNoticeReceivers

func (this *NoticeSetting) FindAllNoticeReceivers(level ...NoticeLevel) []*NoticeReceiver

查找一个或多个级别对应的接收者,并合并相同的接收者

func (*NoticeSetting) FindMedia

func (this *NoticeSetting) FindMedia(mediaId string) *NoticeMediaConfig

查找媒介

func (*NoticeSetting) FindReceiver

func (this *NoticeSetting) FindReceiver(receiverId string) (level NoticeLevel, receiver *NoticeReceiver)

查找接收人

func (*NoticeSetting) LevelConfig

func (this *NoticeSetting) LevelConfig(level NoticeLevel) *NoticeLevelConfig

查找级别配置

func (*NoticeSetting) Notify

func (this *NoticeSetting) Notify(level NoticeLevel, subject string, message string, counter func(receiverId string, minutes int) int) (receiverIds []string)

发送通知

func (*NoticeSetting) NotifyReceivers

func (this *NoticeSetting) NotifyReceivers(level NoticeLevel, receivers []*NoticeReceiver, subject string, message string, counter func(receiverId string, minutes int) int) (receiverIds []string)

发送通知给一组接收者

func (*NoticeSetting) RemoveMedia

func (this *NoticeSetting) RemoveMedia(mediaId string)

删除媒介

func (*NoticeSetting) Save

func (this *NoticeSetting) Save() error

保存配置

type NoticeTeaSmsMedia

type NoticeTeaSmsMedia struct {
	Sign         string `yaml:"sign" json:"sign"`                 // 签名名称
	AccessId     string `yaml:"accessId" json:"accessId"`         // AccessId
	AccessSecret string `yaml:"accessSecret" json:"accessSecret"` // AccessSecret
}

TeaOS云短信

func NewNoticeTeaSmsMedia

func NewNoticeTeaSmsMedia() *NoticeTeaSmsMedia

获取新对象

func (*NoticeTeaSmsMedia) RequireUser

func (this *NoticeTeaSmsMedia) RequireUser() bool

是否需要用户标识

func (*NoticeTeaSmsMedia) Send

func (this *NoticeTeaSmsMedia) Send(user string, subject string, body string) (respBytes []byte, err error)

type NoticeTelegramMedia

type NoticeTelegramMedia struct {
	Token string `yaml:"token" json:"token"`
}

Telegram媒介

func NewNoticeTelegramMedia

func NewNoticeTelegramMedia() *NoticeTelegramMedia

获取新对象

func (*NoticeTelegramMedia) RequireUser

func (this *NoticeTelegramMedia) RequireUser() bool

是否需要用户标识

func (*NoticeTelegramMedia) Send

func (this *NoticeTelegramMedia) Send(user string, subject string, body string) (respBytes []byte, err error)

发送消息

type NoticeWebhookMedia

type NoticeWebhookMedia struct {
	URL         string             `yaml:"url" json:"url"` // URL中可以使用${NoticeSubject}, ${NoticeBody}两个变量
	Method      string             `yaml:"method" json:"method"`
	ContentType string             `yaml:"contentType" json:"contentType"` // 内容类型:params|body
	Headers     []*shared.Variable `yaml:"headers" json:"headers"`
	Params      []*shared.Variable `yaml:"params" json:"params"`
	Body        string             `yaml:"body" json:"body"`
}

Webhook媒介

func NewNoticeWebhookMedia

func NewNoticeWebhookMedia() *NoticeWebhookMedia

获取新对象

func (*NoticeWebhookMedia) AddHeader

func (this *NoticeWebhookMedia) AddHeader(name string, value string)

添加Header

func (*NoticeWebhookMedia) AddParam

func (this *NoticeWebhookMedia) AddParam(name string, value string)

添加参数

func (*NoticeWebhookMedia) RequireUser

func (this *NoticeWebhookMedia) RequireUser() bool

是否需要用户标识

func (*NoticeWebhookMedia) Send

func (this *NoticeWebhookMedia) Send(user string, subject string, body string) (resp []byte, err error)

发送

type ProxyCond

type ProxyCond struct {
	ServerId   string `bson:"serverId" json:"serverId"`
	Websocket  bool   `bson:"websocket" json:"websocket"`
	LocationId string `bson:"locationId" json:"serverId"`
	RewriteId  string `bson:"rewriteId" json:"serverId"`
	BackendId  string `bson:"backendId" json:"serverId"`
	FastcgiId  string `bson:"fastcgiId" json:"serverId"`
	Level      uint8  `bson:"level" json:"level"`
}

Proxy条件

type TextFormat

type TextFormat = string

内容文本格式类型定义

Jump to

Keyboard shortcuts

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