notices

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2019 License: MIT Imports: 21 Imported by: 11

Documentation

Index

Constants

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

通知级别常量

View Source
const (
	NoticeMediaTypeEmail   = "email"
	NoticeMediaTypeWebhook = "webhook"
	NoticeMediaTypeScript  = "script"
)

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

查找媒介类型名称

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"`
}

Agent条件

type Notice

type Notice struct {
	Id         primitive.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"`
	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) SetTime

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

设置时间

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) Send

func (this *NoticeEmailMedia) Send(user string, subject string, body string) (resp []byte, err 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)
}

媒介接口

type NoticeMediaType

type NoticeMediaType = string

通知媒介类型

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

获取新对象

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.EnvVariable `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) 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"`
}

通知设置

func SharedNoticeSetting

func SharedNoticeSetting() *NoticeSetting

取得当前的配置

func (*NoticeSetting) AddMedia

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

添加媒介配置

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, message string, counter func(receiverId string, minutes int) int) (receiverIds []string)

发送通知

func (*NoticeSetting) NotifyReceivers

func (this *NoticeSetting) NotifyReceivers(level NoticeLevel, receivers []*NoticeReceiver, 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 NoticeWebhookMedia

type NoticeWebhookMedia struct {
	URL    string `yaml:"url" json:"url"` // URL中可以使用${NoticeSubject}, ${NoticeBody}两个变量
	Method string `yaml:"method" json:"method"`
}

Webhook媒介

func NewNoticeWebhookMedia

func NewNoticeWebhookMedia() *NoticeWebhookMedia

获取新对象

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"`
	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条件

Jump to

Keyboard shortcuts

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