types

package
v4.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2017 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SEND_MAIL = iota + 1
	SEND_SMS
	SEND_WECHAT
	SEND_CALL
	SEND_ACTION
)
View Source
const (
	ACTION_ALARM = iota + 1
	ACTION_RESTORE
)
View Source
const (
	EVENT_NEW = iota + 1
	EVENT_AWARE
	EVENT_CLOSED
)
View Source
const (
	PRIORITY_HIGH_LEVEL = iota + 1
	PRIORITY_MIDDLE_LEVEL
	PRIORITY_LOW_LEVEL
)
View Source
const (
	USER = iota
	ADMIN
)

Variables

View Source
var AlarmMessageTypeText map[AlarmMessageType]string = map[AlarmMessageType]string{
	ALAR_MESS_INSPECTOR_HEARTBEAT:    "inspector heartbeat",
	ALAR_MESS_INSPECTOR_TASK_REQUEST: "inspector task request",
	ALAR_MESS_INSPECTOR_TASKS:        "inspector tasks",
	ALAR_MESS_INSPECTOR_RESULT:       "inspector result",
}

报警服务消息类型可读映射

View Source
var MessageTypeText map[MessageType]string = map[MessageType]string{
	MESS_POST_HOST_CONFIG:          "post host config",
	MESS_POST_METRIC:               "post metric",
	MESS_POST_TSD:                  "post time series data",
	MESS_GET_HOST_PLUGIN_LIST:      "get host plugin list",
	MESS_GET_HOST_PLUGIN_LIST_RESP: "get host plugin list response",
	MESS_GET_ALL_PLUGIN_MD5:        "get all plugin md5 list",
	MESS_GET_ALL_PLUGIN_MD5_RESP:   "get all plugin md5 list response",
	MESS_PULL_PLUGIN:               "pull plugin file",
	MESS_POST_HOST_ALIVE:           "post host alive",
}

消息类型可读映射

View Source
var STRATEGY_PRIORITY_MAPPING = map[int]string{1: "严重", 2: "较严重", 3: "注意"}
View Source
var STRATEGY_STATUS_MAPPING = map[int]string{1: "活跃报警", 2: "已知悉报警", 3: "已关闭报警"}

Functions

func AlarmPack

func AlarmPack(t AlarmMessageType, m AlarmMessage) []byte

func Pack

func Pack(t MessageType, m Message) []byte

func ParseTags

func ParseTags(name string) map[string]string

tag1=v1,tag2=v2,tag3=v3 {"tag1":v1,"tag2":v2,"tag3":v3}

Types

type Action

type Action struct {
	ID              int    `json:"-"`
	StrategyID      int    `form:"strategy_id" json:"strategy_id" binding:"required"`
	Type            int    `form:"type" json:"type" binding:"required"`
	FilePath        string `form:"file_path" json:"file_path"`
	AlarmSubject    string `form:"alarm_subject" json:"alarm_subject"`
	RestoreSubject  string `form:"restore_subject" json:"restore_subject"`
	AlarmTemplate   string `form:"alarm_template" json:"alarm_template"`
	RestoreTemplate string `form:"restore_template" json:"restore_template"`
	SendType        int    `form:"send_type" json:"send_type" binding:"require"`
}

func (Action) TableName

func (Action) TableName() string

type ActionResult

type ActionResult struct {
	StrategyEventID int64  `json:"strategy_event_id"`
	ActionID        int    `json:"action_id"`
	ActionType      int    `json:"action_type"`
	ActionSendType  int    `json:"action_send_type"`
	UserID          int    `json:"user_id"`
	Username        string `json:"username"`
	Phone           string `json:"phone"`
	Mail            string `json:"mail"`
	Weixin          string `json:"weixin"`
	Subject         string `json:"subject"`
	Content         string `json:"content"`
	Success         bool   `json:"success"`
	Response        string `json:"response"`
	FilePath        string `json:"file_path"`
}

type ActionUser

type ActionUser struct {
	ID       int `json:"-"`
	ActionID int `json:"-"`
	UserID   int `json:"user_id"`
}

func (ActionUser) TableName

func (ActionUser) TableName() string

type ActionUserGroup

type ActionUserGroup struct {
	ID          int `json:"-"`
	ActionID    int `json:"-"`
	UserGroupID int `form:"user_group_id" json:"user_group_id"`
}

func (ActionUserGroup) TableName

func (ActionUserGroup) TableName() string

type AlarmMessage

type AlarmMessage interface {
	Encode() []byte
}

报警服务消息接口

type AlarmMessageType

type AlarmMessageType byte
const (
	ALAR_MESS_INSPECTOR_HEARTBEAT AlarmMessageType = iota + 1
	ALAR_MESS_INSPECTOR_TASK_REQUEST
	ALAR_MESS_INSPECTOR_TASKS
	ALAR_MESS_INSPECTOR_RESULT
)

报警服务消息类型定义

type AlarmTask

type AlarmTask struct {
	ID       string
	Host     *Host
	Strategy *Strategy
	Triggers map[string]*Trigger
}

func NewAlarmTask

func NewAlarmTask(host *Host, strategy *Strategy, triggers map[string]*Trigger) *AlarmTask

type Chart

type Chart struct {
	ID         int       `json:"id"`
	Name       string    `json:"name"`
	UserID     int       `json:"-"`
	Size       int       `json:"size"`
	ReferCount int       `json:"refer_count"`
	Thumbnail  string    `json:"thumbnail"`
	CreateAt   time.Time `json:"create_at"`
	UpdateAt   time.Time `json:"update_at"`

	Elements []*ChartElement `json:"elements"`
}

func (Chart) TableName

func (Chart) TableName() string

type ChartElement

type ChartElement struct {
	ID      int    `json:"id"`
	ChartID int    `json:"-"`
	Name    string `json:"name"`
	Metric  string `json:"metric"`
	Tags    string `json:"tags"`
}

func (ChartElement) TableName

func (ChartElement) TableName() string

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewTsdbClient

func NewTsdbClient(addr string, timeout time.Duration) (*Client, error)

func (*Client) Close

func (c *Client) Close() error

func (*Client) Query

func (c *Client) Query(q *QueryParams) ([]Result, error)

type Counter

type Counter struct {
	Last, Prev uint64
}

type ErrorResp

type ErrorResp struct {
	Error InnerError `json:"error"`
}

func (ErrorResp) String

func (this ErrorResp) String() string

type GetPluginResp

type GetPluginResp struct {
	HostID  string   `json:"host_id"`
	Plugins []Plugin `json:"plugins"`
}

func (*GetPluginResp) Decode

func (this *GetPluginResp) Decode(data []byte) error

func (*GetPluginResp) Encode

func (this *GetPluginResp) Encode() []byte

type GetTasksResp

type GetTasksResp struct {
	AlarmTasks []*AlarmTask
}

func (*GetTasksResp) Decode

func (this *GetTasksResp) Decode(data []byte) error

func (*GetTasksResp) Encode

func (this *GetTasksResp) Encode() []byte

type Group

type Group struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

func (Group) TableName

func (Group) TableName() string

type HeartBeat

type HeartBeat struct {
	IP       string `json:"ip"`
	Hostname string `json:"hostname"`
}

func NewHeartBeat

func NewHeartBeat(ip, hostname string) *HeartBeat

func (*HeartBeat) Decode

func (this *HeartBeat) Decode(data []byte) error

func (*HeartBeat) Encode

func (this *HeartBeat) Encode() []byte

type Host

type Host struct {
	ID           string    `json:"id"`
	Name         string    `json:"name"`
	IP           string    `json:"ip"`
	SN           string    `json:"sn"`
	Hostname     string    `json:"hostname"`
	AgentVersion string    `json:"agent_version"`
	Status       string    `json:"status"`
	CreateAt     time.Time `json:"-"`
	UpdateAt     time.Time `json:"-"`
}

func (*Host) Decode

func (this *Host) Decode(data []byte) error

func (*Host) Encode

func (this *Host) Encode() []byte

func (*Host) IsAlive

func (this *Host) IsAlive() bool

func (Host) TableName

func (Host) TableName() string

type InnerError

type InnerError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Details string `json:"details"`
}

type Interface

type Interface struct {
	Index       string  `json:"index"`
	Name        string  `json:"name"`
	OperStatus  uint64  `json:"oper_starus"`
	InBytes     Counter `json:"in_bytes"`
	OutBytes    Counter `json:"out_bytes"`
	InDiscards  Counter `json:"in_discards"`
	OutDiscards Counter `json:"out_discards"`
	InErrors    Counter `json:"in_errors"`
	OutErrors   Counter `json:"out_errors"`
	Speed       uint64  `json:"speed"`
}

type Message

type Message interface {
	Encode() []byte
}

消息接口

type MessageType

type MessageType byte
const (
	MESS_POST_HOST_CONFIG MessageType = iota
	MESS_POST_METRIC
	MESS_POST_TSD
	MESS_GET_HOST_PLUGIN_LIST
	MESS_GET_HOST_PLUGIN_LIST_RESP
	MESS_GET_ALL_PLUGIN_MD5
	MESS_GET_ALL_PLUGIN_MD5_RESP
	MESS_PULL_PLUGIN
	MESS_POST_HOST_ALIVE
)

消息类型定义

type MetricConfig

type MetricConfig struct {
	HostID     string         `json:"host_id"`
	SeriesData TimeSeriesData `json:"time_series_data"`
}

func (*MetricConfig) Decode

func (this *MetricConfig) Decode(data []byte) error

func (*MetricConfig) Encode

func (this *MetricConfig) Encode() []byte

type Node

type Node struct {
	IP       string
	Hostname string
	Update   time.Time
}

func (*Node) Encode

func (this *Node) Encode() []byte

type NodePool

type NodePool struct {
	Nodes map[string]*Node
	Lock  *sync.Mutex
}

func NewNodePool

func NewNodePool() *NodePool

type Options

type Options struct {
	Addr    string
	Timeout time.Duration
}

type Panel

type Panel struct {
	ID        int       `json:"id"`
	Name      string    `json:"name"`
	Thumbnail string    `json:"thumbnail"`
	UserID    int       `json:"-"`
	Favor     int       `json:"-"`
	CreateAt  time.Time `json:"create_at"`
	UpdateAt  time.Time `json:"update_at"`
	Charts    []*Chart  `json:"charts" gorm:"many2many:panel_chart"`
}

func (Panel) TableName

func (Panel) TableName() string

type Plugin

type Plugin struct {
	ID       int    `json:"id"`
	Name     string `json:"name"`
	Args     string `json:"args"`
	Interval int    `json:"interval"`
	Timeout  int    `json:"timeout"`
}

func (*Plugin) Decode

func (this *Plugin) Decode(data []byte) error

func (*Plugin) Encode

func (this *Plugin) Encode() []byte

func (Plugin) String

func (this Plugin) String() string

func (Plugin) TableName

func (Plugin) TableName() string

type PostMetric

type PostMetric struct {
	HostID  string           `json:"host_id"`
	Metrics []TimeSeriesData `json:"metrics"` // cpu.idle/ip=10.10.32.10,cpu=1
}

func (*PostMetric) Encode

func (this *PostMetric) Encode() []byte

type Query

type Query struct {
	Aggregator string            `json:"aggregator"`
	Metric     string            `json:"metric"`
	Rate       bool              `json:"rate,omitempty"`
	Tags       map[string]string `json:"tags,omitempty"`
}

type QueryParams

type QueryParams struct {
	Start             interface{} `json:"start"`
	End               interface{} `json:"end,omitempty"`
	Queries           []Query     `json:"queries,omitempty"`
	NoAnnotations     bool        `json:"no_annotations,omitempty"`
	GlobalAnnotations bool        `json:"global_annotations,omitempty"`
	MsResolution      bool        `json:"ms,omitempty"`
	ShowTSUIDs        bool        `json:"show_tsuids,omitempty"`
	ShowSummary       bool        `json:"show_summary,omitempty"`
	ShowQuery         bool        `json:"show_query,omitempty"`
	Delete            bool        `json:"delete,omitempty"`
}

func NewQueryParams

func NewQueryParams(start, end string, rawTags string, aggregator string, metric string) *QueryParams

type Result

type Result struct {
	Metric        string             `json:"metric"`
	Tags          map[string]string  `json:"tags"`
	AggregateTags []string           `json:"aggregateTags"`
	Dps           map[string]float64 `json:"dps"`
}

type SnmpConfig

type SnmpConfig struct {
	Port      int    `json:"port"`
	Version   string `json:"version"`
	Community string `json:"community"`
	Timeout   int    `json:"timeout"`
}

type Strategy

type Strategy struct {
	ID          int    `json:"id"`
	Name        string `form:"name" json:"name" binding:"required"`
	Priority    int    `form:"priority" json:"priority" binding:"required"`
	Pid         int    `form:"pid" json:"pid"`
	AlarmCount  int    `form:"alarm_count" json:"alarm_count" binding:"required"`
	Cycle       int    `form:"cycle" json:"cycle" binding:"required"`
	Expression  string `form:"expression" json:"expression" binding:"required"`
	Description string `form:"description" json:"description"`
	UserID      int    `json:"user_id"`
	Enable      bool   `json:"enable"`
}

func (Strategy) TableName

func (Strategy) TableName() string

type StrategyEvent

type StrategyEvent struct {
	ID              int64     `json:"id"`
	StrategyID      int       `json:"strategy_id"`
	StrategyName    string    `json:"strategy_name"`
	Priority        int       `json:"priority"`
	Cycle           int       `json:"cycle"`
	AlarmCount      int       `json:"alarm_count"`
	Expression      string    `json:"expression"`
	CreateTime      time.Time `json:"create_time"`
	UpdateTime      time.Time `json:"update_time"`
	Count           int       `json:"count"`
	Status          int       `json:"status"`
	HostID          string    `json:"host_id"`
	HostCname       string    `json:"host_cname"`
	HostName        string    `json:"host_name"`
	IP              string    `json:"ip"`
	SN              string    `json:"sn"`
	ProcessUser     string    `json:"process_user"`
	ProcessComments string    `json:"process_comments"`
	ProcessTime     time.Time `json:"process_time"`
}

func NewStrategyEvent

func NewStrategyEvent(strategy_id int,
	strategy_name string,
	priority int,
	cycle int,
	alarm_count int,
	expression string,
	create_time time.Time,
	host_id string,
	host_cname string,
	host_name string,
	ip string,
	sn string) *StrategyEvent

func (StrategyEvent) MarshalJSON

func (s StrategyEvent) MarshalJSON() ([]byte, error)

func (StrategyEvent) TableName

func (StrategyEvent) TableName() string

type StrategyGroup

type StrategyGroup struct {
	ID         int64 `json:"-"`
	StrategyID int   `json:"-"`
	GroupID    int   `json:"group_id"`
}

func (StrategyGroup) TableName

func (StrategyGroup) TableName() string

type StrategyHost

type StrategyHost struct {
	ID         int64  `json:"-"`
	StrategyID int    `json:"-"`
	HostID     string `json:"host_id"`
}

func (StrategyHost) TableName

func (StrategyHost) TableName() string

type StrategyResult

type StrategyResult struct {
	TaskID            string
	Priority          int
	TriggerResultSets map[string]*TriggerResultSet
	ErrorMessage      string
	Triggered         bool
	CreateTime        time.Time
}

func NewStrategyResult

func NewStrategyResult(task_id string, priority int, trigger_results map[string]*TriggerResultSet, error_message string, triggered bool, create_time time.Time) *StrategyResult

func (*StrategyResult) Decode

func (this *StrategyResult) Decode(data []byte) error

func (*StrategyResult) Encode

func (this *StrategyResult) Encode() []byte

type Switch

type Switch struct {
	ID              string   `json:"id"`
	IP              string   `json:"ip"`
	Hostname        string   `json:"hostname"`
	AgentVersion    string   `json:"agent_version"`
	CollectInterval int      `json:"collect_interval"`
	LegalPrefix     []string `json:"legal_prefix"`

	//采集数据成功更新
	LastUpdate time.Time             `json:"last_update"`
	Snmp       SnmpConfig            `json:"snmp"`
	Interfaces map[string]*Interface `json:"interfaces"`
}

func (*Switch) BuildInterfaceIndex

func (this *Switch) BuildInterfaceIndex() error

func (*Switch) CollectIfaceSpeed

func (this *Switch) CollectIfaceSpeed() error

func (*Switch) CollectInterfaceName

func (this *Switch) CollectInterfaceName() error

func (*Switch) CollectPerformanceData

func (this *Switch) CollectPerformanceData(oid string)

func (*Switch) CollectTraffic

func (this *Switch) CollectTraffic()

func (*Switch) Do

func (this *Switch) Do(buf1 chan<- *TimeSeriesData, buf2 chan<- *MetricConfig)

func (*Switch) IsLegalPrefix

func (this *Switch) IsLegalPrefix(name string) bool

type Template

type Template struct {
	STRATEGY TemplateStrategy
	HOST     TemplateHost
}

type TemplateHost

type TemplateHost struct {
	CNAME  string
	NAME   string
	IP     string
	STATUS string
	SN     string
}

type TemplateStrategy

type TemplateStrategy struct {
	ID                int64
	NAME              string
	TYPE              string
	CYCLE             int
	PRIORITY          string
	STATUS            string
	ALARM_COUNT       int
	COUNT             int
	UPDATE_TIME       string
	EXPRESSION        string
	EXPRESSION_DETAIL string
}

type TimeSeriesData

type TimeSeriesData struct {
	Metric    string            `json:"metric"`    //sys.cpu.idle
	DataType  string            `json:"data_type"` //COUNTER,GAUGE,DERIVE
	Value     float64           `json:"value"`     //99.00
	Timestamp int64             `json:"timestamp"` //unix timestamp
	Cycle     int               `json:"cycle"`
	Tags      map[string]string `json:"tags"` //{"product":"app01", "group":"dev02"}
}

func (*TimeSeriesData) Decode

func (this *TimeSeriesData) Decode(data []byte) error

func (*TimeSeriesData) Encode

func (this *TimeSeriesData) Encode() []byte

func (*TimeSeriesData) GetMetric

func (this *TimeSeriesData) GetMetric() string

func (*TimeSeriesData) PK

func (this *TimeSeriesData) PK() string

func (TimeSeriesData) String

func (this TimeSeriesData) String() string

func (*TimeSeriesData) Tags2String

func (this *TimeSeriesData) Tags2String() string

type Trigger

type Trigger struct {
	ID          int64   `form:"id" json:"-" `
	StrategyID  int     `form:"strategy_id" json:"strategy_id"`
	Metric      string  `form:"metric" json:"metric"`
	Tags        string  `form:"tags" json:"tags"`
	Number      int     `form:"number" json:"number"`
	Index       string  `form:"index" json:"index" `
	Name        string  `form:"name" json:"name"`
	Method      string  `form:"method" json:"method" `
	Symbol      string  `form:"symbol" json:"symbol" `
	Threshold   float64 `form:"threshold" json:"threshold" `
	Description string  `form:"description" json:"description"`
}

func (Trigger) TableName

func (Trigger) TableName() string

type TriggerEvent

type TriggerEvent struct {
	StrategyEventID  int64   `json:"strategy_event_id"`
	Index            string  `json:"index"`
	Metric           string  `json:"metric"`
	Tags             string  `json:"tags"`
	Number           int     `json:"number"`
	AggregateTags    string  `json:"aggregate_tags"`
	CurrentThreshold float64 `json:"current_threshold"`
	Method           string  `json:"method"`
	Symbol           string  `json:"symbol"`
	Threshold        float64 `json:"threshold"`
	Triggered        bool    `json:"triggered"`
}

func NewTriggerEvent

func NewTriggerEvent(strategy_event_id int64, index, metric, tags, aggregate_tags, symbol, method string, number int, threshold, current_threshold float64, triggered bool) *TriggerEvent

func (*TriggerEvent) String

func (this *TriggerEvent) String() string

type TriggerResult

type TriggerResult struct {
	Index            string
	Tags             string
	AggregateTags    string
	CurrentThreshold float64
	Triggered        bool
}

func NewTriggerResult

func NewTriggerResult(index string, tags map[string]string, aggregate_tags []string, current_threshold float64, triggered bool) *TriggerResult

type TriggerResultSet

type TriggerResultSet struct {
	TriggerResults []*TriggerResult
	Triggered      bool
}

type User

type User struct {
	ID       int    `json:"id"`
	Username string `json:"username"`
	Password string `json:"-"`
	Role     int    `json:"role"`
	Phone    string `json:"phone"`
	Mail     string `json:"mail"`
	Weixin   string `json:"weixin"`
	Status   int    `json:"status"`
}

func (*User) IsAdmin

func (this *User) IsAdmin() bool

func (User) TableName

func (User) TableName() string

type UserGroup

type UserGroup struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

func (UserGroup) TableName

func (UserGroup) TableName() string

Jump to

Keyboard shortcuts

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