teadb

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: 43 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SortAsc  = "asc"
	SortDesc = "desc"
)

Variables

View Source
var ErrorDBUnavailable = errors.New("database is not available")

Functions

func AddHook

func AddHook(hook *Hook)

func BSONArrayBytes

func BSONArrayBytes(data []byte) (interface{}, error)

func BSONDecode

func BSONDecode(value interface{}) (interface{}, error)

func ChangeDB

func ChangeDB()

切换数据库驱动

func SetupDB

func SetupDB()

建立数据库驱动

Types

type AccessLogDAOInterface

type AccessLogDAOInterface interface {
	// 设置驱动
	SetDriver(driver DriverInterface)

	// 初始化
	Init()

	// 获取表名
	TableName(day string) string

	// 写入一条日志
	InsertOne(accessLog *accesslogs.AccessLog) error

	// 写入一组日志
	InsertAccessLogs(accessLogList []interface{}) error

	// 查找某条访问日志的cookie信息
	FindAccessLogCookie(day string, logId string) (*accesslogs.AccessLog, error)

	// 查找某条访问日志的请求信息
	FindRequestHeaderAndBody(day string, logId string) (*accesslogs.AccessLog, error)

	// 查找某条访问日志的响应信息
	FindResponseHeaderAndBody(day string, logId string) (*accesslogs.AccessLog, error)

	// 列出日志
	ListAccessLogs(day string, serverId string, fromId string, onlyErrors bool, searchIP string, offset int, size int) ([]*accesslogs.AccessLog, error)

	// 检查是否有下一条日志
	HasNextAccessLog(day string, serverId string, fromId string, onlyErrors bool, searchIP string) (bool, error)

	// 判断某个代理服务是否有日志
	HasAccessLog(day string, serverId string) (bool, error)

	// 列出WAF日志
	ListAccessLogsWithWAF(day string, wafId string, fromId string, onlyErrors bool, searchIP string, offset int, size int) ([]*accesslogs.AccessLog, error)

	// 检查WAF是否有下一条日志
	HasNextAccessLogWithWAF(day string, wafId string, fromId string, onlyErrors bool, searchIP string) (bool, error)

	// 判断某日是否有WAF日志
	HasAccessLogWithWAF(day string, wafId string) (bool, error)

	// 统计当前WAF拦截的规则分组
	GroupWAFRuleGroups(day string, wafId string) ([]maps.Map, error)

	// 列出最近的某些日志
	ListLatestAccessLogs(day string, serverId string, fromId string, onlyErrors bool, size int) ([]*accesslogs.AccessLog, error)

	// 列出某天的一些日志
	ListTopAccessLogs(day string, size int) ([]*accesslogs.AccessLog, error)

	// 根据查询条件来查找日志
	QueryAccessLogs(day string, serverId string, query *Query) ([]*accesslogs.AccessLog, error)
}

访问日志DAO

func AccessLogDAO

func AccessLogDAO() AccessLogDAOInterface

获取访问日志DAO

type AgentLogDAOInterface

type AgentLogDAOInterface interface {
	// 设置驱动
	SetDriver(driver DriverInterface)

	// 初始化
	Init()

	// 插入一条数据
	InsertOne(agentId string, log *agents.ProcessLog) error

	// 获取最新任务的日志
	FindLatestTaskLogs(agentId string, taskId string, fromId string, size int) ([]*agents.ProcessLog, error)

	// 获取任务最后一次的执行日志
	FindLatestTaskLog(agentId string, taskId string) (*agents.ProcessLog, error)

	// 删除Agent相关表
	DropAgentTable(agentId string) error
}

Agent任务日志DAO

func AgentLogDAO

func AgentLogDAO() AgentLogDAOInterface

获取Agent日志DAO

type AgentValueDAOInterface

type AgentValueDAOInterface interface {
	// 设置驱动
	SetDriver(driver DriverInterface)

	// 初始化
	Init()

	// 获取表格
	TableName(agentId string) string

	// 插入数据
	Insert(agentId string, value *agents.Value) error

	// 清除数值
	ClearItemValues(agentId string, appId string, itemId string, level notices.NoticeLevel) error

	// 查找最近的一条记录
	FindLatestItemValue(agentId string, appId string, itemId string) (*agents.Value, error)

	// 查找最近的一条非错误的记录
	FindLatestItemValueNoError(agentId string, appId string, itemId string) (*agents.Value, error)

	// 取得最近的数值记录
	FindLatestItemValues(agentId string, appId string, itemId string, noticeLevel notices.NoticeLevel, lastId string, size int) ([]*agents.Value, error)

	// 列出数值
	ListItemValues(agentId string, appId string, itemId string, noticeLevel notices.NoticeLevel, lastId string, offset int, size int) ([]*agents.Value, error)

	// 分组查询
	QueryValues(query *Query) ([]*agents.Value, error)

	// 根据时间对值进行分组查询
	GroupValuesByTime(query *Query, timeField string, result map[string]Expr) ([]*agents.Value, error)

	// 删除Agent相关表
	DropAgentTable(agentId string) error
}

Agent数值记录DAO

func AgentValueDAO

func AgentValueDAO() AgentValueDAOInterface

获取Agent数值记录DAO

type AuditLogDAOInterface

type AuditLogDAOInterface interface {
	// 设置驱动
	SetDriver(driver DriverInterface)

	// 初始化
	Init()

	// 计算审计日志数量
	CountAllAuditLogs() (int64, error)

	// 列出审计日志
	ListAuditLogs(offset int, size int) ([]*audits.Log, error)

	// 插入一条审计日志
	InsertOne(auditLog *audits.Log) error
}

审计日志DAO

func AuditLogDAO

func AuditLogDAO() AuditLogDAOInterface

获取审计日志DAO

type AvgExpr

type AvgExpr struct {
	Field string
}

平均值表达式

func NewAvgExpr

func NewAvgExpr(field string) *AvgExpr

type BaseDAO

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

func (*BaseDAO) SetDriver

func (this *BaseDAO) SetDriver(driver DriverInterface)

type BaseDriver

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

驱动基础

func (*BaseDriver) IsAvailable

func (this *BaseDriver) IsAvailable() bool

是否可用

func (*BaseDriver) SetIsAvailable

func (this *BaseDriver) SetIsAvailable(b bool)

设置是否可用

type DriverInterface

type DriverInterface interface {
	// 初始化
	Init()

	// 设置是否可用
	SetIsAvailable(b bool)

	// 取得是否可用
	IsAvailable() bool

	// 查找单条记录
	FindOne(query *Query, modelPtr interface{}) (interface{}, error)

	// 查找多条记录
	FindOnes(query *Query, modelPtr interface{}) ([]interface{}, error)

	// 插入一条记录
	InsertOne(table string, modelPtr interface{}) error

	// 插入多条记录
	InsertOnes(table string, modelPtrSlice interface{}) error

	// 删除多条记录
	DeleteOnes(query *Query) error

	// 计算总数量
	Count(query *Query) (int64, error)

	// 计算总和
	Sum(query *Query, field string) (float64, error)

	// 计算平均值
	Avg(query *Query, field string) (float64, error)

	// 计算最小值
	Min(query *Query, field string) (float64, error)

	// 计算最大值
	Max(query *Query, field string) (float64, error)

	// 对数据进行分组统计
	Group(query *Query, field string, result map[string]Expr) ([]maps.Map, error)

	// 测试数据库连接
	Test() error

	// 关闭
	Shutdown() error

	// 列出所有表
	ListTables() ([]string, error)

	// 统计数据表信息
	StatTables(tables []string) (map[string]*TableStat, error)

	// 删除表
	DropTable(table string) error
}

数据库驱动

func SharedDB

func SharedDB() DriverInterface

获取共享的数据库驱动

type Expr

type Expr interface {
}

查询中使用的特殊表达式

type Hook

type Hook struct {
	Setup func()
}

type MaxExpr

type MaxExpr struct {
	Field string
}

最大值表达式

func NewMaxExpr

func NewMaxExpr(field string) *MaxExpr

type MinExpr

type MinExpr struct {
	Field string
}

最小值表达式

func NewMinExpr

func NewMinExpr(field string) *MinExpr

type MongoAccessLogDAO

type MongoAccessLogDAO struct {
	BaseDAO
}

func (*MongoAccessLogDAO) FindAccessLogCookie

func (this *MongoAccessLogDAO) FindAccessLogCookie(day string, logId string) (*accesslogs.AccessLog, error)

func (*MongoAccessLogDAO) FindRequestHeaderAndBody

func (this *MongoAccessLogDAO) FindRequestHeaderAndBody(day string, logId string) (*accesslogs.AccessLog, error)

func (*MongoAccessLogDAO) FindResponseHeaderAndBody

func (this *MongoAccessLogDAO) FindResponseHeaderAndBody(day string, logId string) (*accesslogs.AccessLog, error)

func (*MongoAccessLogDAO) GroupWAFRuleGroups

func (this *MongoAccessLogDAO) GroupWAFRuleGroups(day string, wafId string) ([]maps.Map, error)

func (*MongoAccessLogDAO) HasAccessLog

func (this *MongoAccessLogDAO) HasAccessLog(day string, serverId string) (bool, error)

func (*MongoAccessLogDAO) HasAccessLogWithWAF

func (this *MongoAccessLogDAO) HasAccessLogWithWAF(day string, wafId string) (bool, error)

func (*MongoAccessLogDAO) HasNextAccessLog

func (this *MongoAccessLogDAO) HasNextAccessLog(day string, serverId string, fromId string, onlyErrors bool, searchIP string) (bool, error)

func (*MongoAccessLogDAO) HasNextAccessLogWithWAF

func (this *MongoAccessLogDAO) HasNextAccessLogWithWAF(day string, wafId string, fromId string, onlyErrors bool, searchIP string) (bool, error)

func (*MongoAccessLogDAO) Init

func (this *MongoAccessLogDAO) Init()

func (*MongoAccessLogDAO) InsertAccessLogs

func (this *MongoAccessLogDAO) InsertAccessLogs(accessLogList []interface{}) error

写入一组日志

func (*MongoAccessLogDAO) InsertOne

func (this *MongoAccessLogDAO) InsertOne(accessLog *accesslogs.AccessLog) error

写入一条日志

func (*MongoAccessLogDAO) InsertingTableName

func (this *MongoAccessLogDAO) InsertingTableName(day string) string

func (*MongoAccessLogDAO) ListAccessLogs

func (this *MongoAccessLogDAO) ListAccessLogs(day string, serverId string, fromId string, onlyErrors bool, searchIP string, offset int, size int) ([]*accesslogs.AccessLog, error)

func (*MongoAccessLogDAO) ListAccessLogsWithWAF

func (this *MongoAccessLogDAO) ListAccessLogsWithWAF(day string, wafId string, fromId string, onlyErrors bool, searchIP string, offset int, size int) ([]*accesslogs.AccessLog, error)

func (*MongoAccessLogDAO) ListLatestAccessLogs

func (this *MongoAccessLogDAO) ListLatestAccessLogs(day string, serverId string, fromId string, onlyErrors bool, size int) ([]*accesslogs.AccessLog, error)

func (*MongoAccessLogDAO) ListTopAccessLogs

func (this *MongoAccessLogDAO) ListTopAccessLogs(day string, size int) ([]*accesslogs.AccessLog, error)

func (*MongoAccessLogDAO) QueryAccessLogs

func (this *MongoAccessLogDAO) QueryAccessLogs(day string, serverId string, query *Query) ([]*accesslogs.AccessLog, error)

func (*MongoAccessLogDAO) TableName

func (this *MongoAccessLogDAO) TableName(day string) string

type MongoAgentLogDAO

type MongoAgentLogDAO struct {
	BaseDAO
}

func (*MongoAgentLogDAO) DropAgentTable

func (this *MongoAgentLogDAO) DropAgentTable(agentId string) error

删除Agent相关表

func (*MongoAgentLogDAO) FindLatestTaskLog

func (this *MongoAgentLogDAO) FindLatestTaskLog(agentId string, taskId string) (*agents.ProcessLog, error)

获取任务最后一次的执行日志

func (*MongoAgentLogDAO) FindLatestTaskLogs

func (this *MongoAgentLogDAO) FindLatestTaskLogs(agentId string, taskId string, fromId string, size int) ([]*agents.ProcessLog, error)

获取任务的日志

func (*MongoAgentLogDAO) Init

func (this *MongoAgentLogDAO) Init()

func (*MongoAgentLogDAO) InsertOne

func (this *MongoAgentLogDAO) InsertOne(agentId string, log *agents.ProcessLog) error

插入一条数据

func (*MongoAgentLogDAO) TableName

func (this *MongoAgentLogDAO) TableName(agentId string) string

type MongoAgentValueDAO

type MongoAgentValueDAO struct {
	BaseDAO
}

func (*MongoAgentValueDAO) ClearItemValues

func (this *MongoAgentValueDAO) ClearItemValues(agentId string, appId string, itemId string, level notices.NoticeLevel) error

func (*MongoAgentValueDAO) DropAgentTable

func (this *MongoAgentValueDAO) DropAgentTable(agentId string) error

func (*MongoAgentValueDAO) FindLatestItemValue

func (this *MongoAgentValueDAO) FindLatestItemValue(agentId string, appId string, itemId string) (*agents.Value, error)

func (*MongoAgentValueDAO) FindLatestItemValueNoError

func (this *MongoAgentValueDAO) FindLatestItemValueNoError(agentId string, appId string, itemId string) (*agents.Value, error)

func (*MongoAgentValueDAO) FindLatestItemValues

func (this *MongoAgentValueDAO) FindLatestItemValues(agentId string, appId string, itemId string, noticeLevel notices.NoticeLevel, lastId string, size int) ([]*agents.Value, error)

取得最近的数值记录

func (*MongoAgentValueDAO) GroupValuesByTime

func (this *MongoAgentValueDAO) GroupValuesByTime(query *Query, timeField string, result map[string]Expr) ([]*agents.Value, error)

func (*MongoAgentValueDAO) Init

func (this *MongoAgentValueDAO) Init()

func (*MongoAgentValueDAO) Insert

func (this *MongoAgentValueDAO) Insert(agentId string, value *agents.Value) error

func (*MongoAgentValueDAO) ListItemValues

func (this *MongoAgentValueDAO) ListItemValues(agentId string, appId string, itemId string, noticeLevel notices.NoticeLevel, lastId string, offset int, size int) ([]*agents.Value, error)

func (*MongoAgentValueDAO) QueryValues

func (this *MongoAgentValueDAO) QueryValues(query *Query) ([]*agents.Value, error)

func (*MongoAgentValueDAO) TableName

func (this *MongoAgentValueDAO) TableName(agentId string) string

type MongoAuditLogDAO

type MongoAuditLogDAO struct {
	BaseDAO
}

func (*MongoAuditLogDAO) CountAllAuditLogs

func (this *MongoAuditLogDAO) CountAllAuditLogs() (int64, error)

func (*MongoAuditLogDAO) Init

func (this *MongoAuditLogDAO) Init()

func (*MongoAuditLogDAO) InsertOne

func (this *MongoAuditLogDAO) InsertOne(auditLog *audits.Log) error

func (*MongoAuditLogDAO) ListAuditLogs

func (this *MongoAuditLogDAO) ListAuditLogs(offset int, size int) ([]*audits.Log, error)

type MongoCollection

type MongoCollection struct {
	*mongo.Collection
}

集合定义

func (*MongoCollection) CreateIndex

func (this *MongoCollection) CreateIndex(fields ...*shared.IndexField) error

创建索引

func (*MongoCollection) CreateIndexes

func (this *MongoCollection) CreateIndexes(fields ...[]*shared.IndexField) error

创建一组索引

type MongoDriver

type MongoDriver struct {
	BaseDriver
	// contains filtered or unexported fields
}

func (*MongoDriver) Avg

func (this *MongoDriver) Avg(query *Query, field string) (float64, error)

func (*MongoDriver) Count

func (this *MongoDriver) Count(query *Query) (int64, error)

func (*MongoDriver) DB

func (this *MongoDriver) DB() *mongo.Database

选取数据库

func (*MongoDriver) DeleteOnes

func (this *MongoDriver) DeleteOnes(query *Query) error

func (*MongoDriver) DropTable

func (this *MongoDriver) DropTable(table string) error

删除表

func (*MongoDriver) FindOne

func (this *MongoDriver) FindOne(query *Query, modelPtr interface{}) (interface{}, error)

func (*MongoDriver) FindOnes

func (this *MongoDriver) FindOnes(query *Query, modelPtr interface{}) ([]interface{}, error)

func (*MongoDriver) Group

func (this *MongoDriver) Group(query *Query, field string, result map[string]Expr) ([]maps.Map, error)

func (*MongoDriver) Init

func (this *MongoDriver) Init()

func (*MongoDriver) InsertOne

func (this *MongoDriver) InsertOne(table string, modelPtr interface{}) error

func (*MongoDriver) InsertOnes

func (this *MongoDriver) InsertOnes(table string, modelPtrSlice interface{}) error

func (*MongoDriver) ListTables

func (this *MongoDriver) ListTables() ([]string, error)

列出所有表

func (*MongoDriver) Max

func (this *MongoDriver) Max(query *Query, field string) (float64, error)

func (*MongoDriver) Min

func (this *MongoDriver) Min(query *Query, field string) (float64, error)

func (*MongoDriver) SelectColl

func (this *MongoDriver) SelectColl(name string) (*MongoCollection, error)

选择数据集合

func (*MongoDriver) Shutdown

func (this *MongoDriver) Shutdown() error

关闭服务

func (*MongoDriver) StatTables

func (this *MongoDriver) StatTables(tables []string) (map[string]*TableStat, error)

统计数据表

func (*MongoDriver) Sum

func (this *MongoDriver) Sum(query *Query, field string) (float64, error)

func (*MongoDriver) Test

func (this *MongoDriver) Test() error

测试数据库连接

func (*MongoDriver) TestConfig

func (this *MongoDriver) TestConfig(config *db.MongoConfig) (message string, ok bool)

测试URI

type MongoNoticeDAO

type MongoNoticeDAO struct {
	BaseDAO
}

func (*MongoNoticeDAO) CountAllReadNotices

func (this *MongoNoticeDAO) CountAllReadNotices() (int, error)

func (*MongoNoticeDAO) CountAllUnreadNotices

func (this *MongoNoticeDAO) CountAllUnreadNotices() (int, error)

func (*MongoNoticeDAO) CountReadNoticesForAgent

func (this *MongoNoticeDAO) CountReadNoticesForAgent(agentId string) (int, error)

func (*MongoNoticeDAO) CountReceivedNotices

func (this *MongoNoticeDAO) CountReceivedNotices(receiverId string, cond map[string]interface{}, minutes int) (int, error)

func (*MongoNoticeDAO) CountUnreadNoticesForAgent

func (this *MongoNoticeDAO) CountUnreadNoticesForAgent(agentId string) (int, error)

func (*MongoNoticeDAO) DeleteNoticesForAgent

func (this *MongoNoticeDAO) DeleteNoticesForAgent(agentId string) error

func (*MongoNoticeDAO) ExistNoticesWithHash

func (this *MongoNoticeDAO) ExistNoticesWithHash(hash string, cond map[string]interface{}, duration time.Duration) (bool, error)

func (*MongoNoticeDAO) Init

func (this *MongoNoticeDAO) Init()

func (*MongoNoticeDAO) InsertOne

func (this *MongoNoticeDAO) InsertOne(notice *notices.Notice) error

func (*MongoNoticeDAO) ListAgentNotices

func (this *MongoNoticeDAO) ListAgentNotices(agentId string, isRead bool, offset int, size int) ([]*notices.Notice, error)

列出某个Agent相关的消息

func (*MongoNoticeDAO) ListNotices

func (this *MongoNoticeDAO) ListNotices(isRead bool, offset int, size int) ([]*notices.Notice, error)

列出消息

func (*MongoNoticeDAO) NotifyProxyMessage

func (this *MongoNoticeDAO) NotifyProxyMessage(cond notices.ProxyCond, message string) error

func (*MongoNoticeDAO) NotifyProxyServerMessage

func (this *MongoNoticeDAO) NotifyProxyServerMessage(serverId string, level notices.NoticeLevel, message string) error

func (*MongoNoticeDAO) TableName

func (this *MongoNoticeDAO) TableName() string

func (*MongoNoticeDAO) UpdateAgentNoticesRead

func (this *MongoNoticeDAO) UpdateAgentNoticesRead(agentId string, noticeIds []string) error

设置Agent的一组通知已读

func (*MongoNoticeDAO) UpdateAllAgentNoticesRead

func (this *MongoNoticeDAO) UpdateAllAgentNoticesRead(agentId string) error

设置Agent所有通知已读

func (*MongoNoticeDAO) UpdateAllNoticesRead

func (this *MongoNoticeDAO) UpdateAllNoticesRead() error

func (*MongoNoticeDAO) UpdateNoticeReceivers

func (this *MongoNoticeDAO) UpdateNoticeReceivers(noticeId string, receiverIds []string) error

func (*MongoNoticeDAO) UpdateNoticesRead

func (this *MongoNoticeDAO) UpdateNoticesRead(noticeIds []string) error

设置一组通知已读

type MongoServerValueDAO

type MongoServerValueDAO struct {
	BaseDAO
}

func (*MongoServerValueDAO) CreateIndex

func (this *MongoServerValueDAO) CreateIndex(serverId string, fields []*shared.IndexField) error

func (*MongoServerValueDAO) DeleteExpiredValues

func (this *MongoServerValueDAO) DeleteExpiredValues(serverId string, period stats.ValuePeriod, life int) error

func (*MongoServerValueDAO) DropServerTable

func (this *MongoServerValueDAO) DropServerTable(serverId string) error

删除代理服务相关表

func (*MongoServerValueDAO) FindOneWithItem

func (this *MongoServerValueDAO) FindOneWithItem(serverId string, item string) (*stats.Value, error)

func (*MongoServerValueDAO) FindSameItemValue

func (this *MongoServerValueDAO) FindSameItemValue(serverId string, item *stats.Value) (*stats.Value, error)

根据参数查询已有的数据

func (*MongoServerValueDAO) Init

func (this *MongoServerValueDAO) Init()

func (*MongoServerValueDAO) InsertOne

func (this *MongoServerValueDAO) InsertOne(serverId string, value *stats.Value) error

func (*MongoServerValueDAO) QueryValues

func (this *MongoServerValueDAO) QueryValues(query *Query) ([]*stats.Value, error)

func (*MongoServerValueDAO) TableName

func (this *MongoServerValueDAO) TableName(serverId string) string

func (*MongoServerValueDAO) UpdateItemValueAndTimestamp

func (this *MongoServerValueDAO) UpdateItemValueAndTimestamp(serverId string, valueId string, value map[string]interface{}, timestamp int64) error

type MySQLDriver

type MySQLDriver struct {
	SQLDriver
}

func (*MySQLDriver) CheckTableExists

func (this *MySQLDriver) CheckTableExists(table string) (bool, error)

检查表是否存在

func (*MySQLDriver) CreateTable

func (this *MySQLDriver) CreateTable(table string, definitionSQL string) error

创建表

func (*MySQLDriver) Init

func (this *MySQLDriver) Init()

初始化

func (*MySQLDriver) ListTables

func (this *MySQLDriver) ListTables() ([]string, error)

列出所有表

func (*MySQLDriver) StatTables

func (this *MySQLDriver) StatTables(tables []string) (map[string]*TableStat, error)

统计数据表

func (*MySQLDriver) TestDSN

func (this *MySQLDriver) TestDSN(dsn string, autoCreateDB bool) (message string, ok bool)

测试DSN

type NoticeDAOInterface

type NoticeDAOInterface interface {
	// 设置驱动
	SetDriver(driver DriverInterface)

	// 初始化
	Init()

	// 写入一个通知
	InsertOne(notice *notices.Notice) error

	// 发送一个代理的通知(形式1)
	NotifyProxyMessage(cond notices.ProxyCond, message string) error

	// 发送一个代理的通知(形式2)
	NotifyProxyServerMessage(serverId string, level notices.NoticeLevel, message string) error

	// 获取所有未读通知数
	CountAllUnreadNotices() (int, error)

	// 获取所有已读通知数
	CountAllReadNotices() (int, error)

	// 获取某个Agent的未读通知数
	CountUnreadNoticesForAgent(agentId string) (int, error)

	// 获取某个Agent已读通知数
	CountReadNoticesForAgent(agentId string) (int, error)

	// 获取某个接收人在某个时间段内接收的通知数
	CountReceivedNotices(receiverId string, cond map[string]interface{}, minutes int) (int, error)

	// 通过Hash判断是否存在相同的消息
	ExistNoticesWithHash(hash string, cond map[string]interface{}, duration time.Duration) (bool, error)

	// 列出消息
	ListNotices(isRead bool, offset int, size int) ([]*notices.Notice, error)

	// 列出某个Agent相关的消息
	ListAgentNotices(agentId string, isRead bool, offset int, size int) ([]*notices.Notice, error)

	// 删除Agent相关通知
	DeleteNoticesForAgent(agentId string) error

	// 更改某个通知的接收人
	UpdateNoticeReceivers(noticeId string, receiverIds []string) error

	// 设置全部已读
	UpdateAllNoticesRead() error

	// 设置一组通知已读
	UpdateNoticesRead(noticeIds []string) error

	// 设置Agent的一组通知已读
	UpdateAgentNoticesRead(agentId string, noticeIds []string) error

	// 设置Agent所有通知已读
	UpdateAllAgentNoticesRead(agentId string) error
}

通知DAO

func NoticeDAO

func NoticeDAO() NoticeDAOInterface

获取通知DAO

type Operand

type Operand struct {
	Code  OperandCode
	Value interface{}
}

func NewOperand

func NewOperand(code OperandCode, value interface{}) *Operand

type OperandCode

type OperandCode = string

操作符类型

const (
	OperandEq    OperandCode = "eq"
	OperandLt    OperandCode = "lt"
	OperandLte   OperandCode = "lte"
	OperandGt    OperandCode = "gt"
	OperandGte   OperandCode = "gte"
	OperandIn    OperandCode = "in"
	OperandNotIn OperandCode = "nin"
	OperandNeq   OperandCode = "ne"
	OperandOr    OperandCode = "or"
)

常用操作符

type OperandList

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

字段操作符列表

func NewOperandList

func NewOperandList() *OperandList

获取新对象

func (*OperandList) Add

func (this *OperandList) Add(field string, operand ...*Operand) *OperandList

添加字段操作符

func (*OperandList) Len

func (this *OperandList) Len() int

所有字段数量

func (*OperandList) Range

func (this *OperandList) Range(f func(field string, operands []*Operand))

循环所有字段

type PostgresDriver

type PostgresDriver struct {
	SQLDriver
}

func (*PostgresDriver) CheckTableExists

func (this *PostgresDriver) CheckTableExists(table string) (bool, error)

检查表是否存在

func (*PostgresDriver) CreateTable

func (this *PostgresDriver) CreateTable(table string, definitionSQL string) error

创建表

func (*PostgresDriver) Init

func (this *PostgresDriver) Init()

初始化

func (*PostgresDriver) ListTables

func (this *PostgresDriver) ListTables() ([]string, error)

列出所有表

func (*PostgresDriver) StatTables

func (this *PostgresDriver) StatTables(tables []string) (map[string]*TableStat, error)

统计数据表

func (*PostgresDriver) TestDSN

func (this *PostgresDriver) TestDSN(dsn string, autoCreateDB bool) (message string, ok bool)

测试DSN

type Query

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

查询对象

func NewQuery

func NewQuery(table string) *Query

构造新查询

func (*Query) Asc

func (this *Query) Asc(field string) *Query

func (*Query) Attr

func (this *Query) Attr(field string, value interface{}) *Query

func (*Query) Avg

func (this *Query) Avg(field string) (float64, error)

func (*Query) Count

func (this *Query) Count() (int64, error)

func (*Query) Debug

func (this *Query) Debug() *Query

func (*Query) Delete

func (this *Query) Delete() error

func (*Query) Desc

func (this *Query) Desc(field string) *Query

func (*Query) FieldMap

func (this *Query) FieldMap(mapping func(field string) string) *Query

func (*Query) FindOne

func (this *Query) FindOne(modelPtr interface{}) (interface{}, error)

func (*Query) FindOnes

func (this *Query) FindOnes(modelPtr interface{}) ([]interface{}, error)

func (*Query) Group

func (this *Query) Group(field string, result map[string]Expr) ([]maps.Map, error)

func (*Query) Gt

func (this *Query) Gt(field string, value interface{}) *Query

func (*Query) Gte

func (this *Query) Gte(field string, value interface{}) *Query

func (*Query) Init

func (this *Query) Init() *Query

func (*Query) InsertOne

func (this *Query) InsertOne(modelPtr interface{}) error

func (*Query) InsertOnes

func (this *Query) InsertOnes(modelPtrSlice interface{}) error

func (*Query) Limit

func (this *Query) Limit(size int) *Query

func (*Query) Lt

func (this *Query) Lt(field string, value interface{}) *Query

func (*Query) Lte

func (this *Query) Lte(field string, value interface{}) *Query

func (*Query) Max

func (this *Query) Max(field string) (float64, error)

func (*Query) Min

func (this *Query) Min(field string) (float64, error)

func (*Query) Node

func (this *Query) Node() *Query

func (*Query) Not

func (this *Query) Not(field string, value interface{}) *Query

func (*Query) Offset

func (this *Query) Offset(offset int) *Query

func (*Query) Op

func (this *Query) Op(field string, operandCode OperandCode, value interface{}) *Query

func (*Query) Or

func (this *Query) Or(fieldValues []*OperandList) *Query

func (*Query) Result

func (this *Query) Result(field ...string) *Query

func (*Query) Sum

func (this *Query) Sum(field string) (float64, error)

func (*Query) Table

func (this *Query) Table(table string) *Query

func (*Query) Timeout

func (this *Query) Timeout(timeout time.Duration) *Query

type SQLAccessLogDAO

type SQLAccessLogDAO struct {
	BaseDAO
}

func (*SQLAccessLogDAO) FindAccessLogCookie

func (this *SQLAccessLogDAO) FindAccessLogCookie(day string, logId string) (*accesslogs.AccessLog, error)

查找某条访问日志的cookie信息

func (*SQLAccessLogDAO) FindRequestHeaderAndBody

func (this *SQLAccessLogDAO) FindRequestHeaderAndBody(day string, logId string) (*accesslogs.AccessLog, error)

查找某条访问日志的请求信息

func (*SQLAccessLogDAO) FindResponseHeaderAndBody

func (this *SQLAccessLogDAO) FindResponseHeaderAndBody(day string, logId string) (*accesslogs.AccessLog, error)

查找某条访问日志的响应信息

func (*SQLAccessLogDAO) GroupWAFRuleGroups

func (this *SQLAccessLogDAO) GroupWAFRuleGroups(day string, wafId string) ([]maps.Map, error)

func (*SQLAccessLogDAO) HasAccessLog

func (this *SQLAccessLogDAO) HasAccessLog(day string, serverId string) (bool, error)

判断某个代理服务是否有日志

func (*SQLAccessLogDAO) HasAccessLogWithWAF

func (this *SQLAccessLogDAO) HasAccessLogWithWAF(day string, wafId string) (bool, error)

判断某个WAF是否有日志

func (*SQLAccessLogDAO) HasNextAccessLog

func (this *SQLAccessLogDAO) HasNextAccessLog(day string, serverId string, fromId string, onlyErrors bool, searchIP string) (bool, error)

检查是否有下一条日志

func (*SQLAccessLogDAO) HasNextAccessLogWithWAF

func (this *SQLAccessLogDAO) HasNextAccessLogWithWAF(day string, wafId string, fromId string, onlyErrors bool, searchIP string) (bool, error)

检查是否有下一条日志

func (*SQLAccessLogDAO) Init

func (this *SQLAccessLogDAO) Init()

初始化

func (*SQLAccessLogDAO) InsertAccessLogs

func (this *SQLAccessLogDAO) InsertAccessLogs(accessLogList []interface{}) error

写入一组日志

func (*SQLAccessLogDAO) InsertOne

func (this *SQLAccessLogDAO) InsertOne(accessLog *accesslogs.AccessLog) error

写入一条日志

func (*SQLAccessLogDAO) ListAccessLogs

func (this *SQLAccessLogDAO) ListAccessLogs(day string, serverId string, fromId string, onlyErrors bool, searchIP string, offset int, size int) ([]*accesslogs.AccessLog, error)

列出日志

func (*SQLAccessLogDAO) ListAccessLogsWithWAF

func (this *SQLAccessLogDAO) ListAccessLogsWithWAF(day string, wafId string, fromId string, onlyErrors bool, searchIP string, offset int, size int) ([]*accesslogs.AccessLog, error)

列出WAF日志

func (*SQLAccessLogDAO) ListLatestAccessLogs

func (this *SQLAccessLogDAO) ListLatestAccessLogs(day string, serverId string, fromId string, onlyErrors bool, size int) ([]*accesslogs.AccessLog, error)

列出最近的某些日志

func (*SQLAccessLogDAO) ListTopAccessLogs

func (this *SQLAccessLogDAO) ListTopAccessLogs(day string, size int) ([]*accesslogs.AccessLog, error)

列出某天的一些日志

func (*SQLAccessLogDAO) QueryAccessLogs

func (this *SQLAccessLogDAO) QueryAccessLogs(day string, serverId string, query *Query) ([]*accesslogs.AccessLog, error)

根据查询条件来查找日志

func (*SQLAccessLogDAO) TableName

func (this *SQLAccessLogDAO) TableName(day string) string

获取表名

func (*SQLAccessLogDAO) TodayTableName

func (this *SQLAccessLogDAO) TodayTableName() string

获取当前时间表名

type SQLAction

type SQLAction = int

SQL动作类型

const (
	SQLInsert SQLAction = 1
	SQLSelect SQLAction = 2
	SQLDelete SQLAction = 3
	SQLUpdate SQLAction = 4
)

SQL动作列表

type SQLAgentLogDAO

type SQLAgentLogDAO struct {
	BaseDAO
}

func (*SQLAgentLogDAO) DropAgentTable

func (this *SQLAgentLogDAO) DropAgentTable(agentId string) error

删除Agent相关表

func (*SQLAgentLogDAO) FindLatestTaskLog

func (this *SQLAgentLogDAO) FindLatestTaskLog(agentId string, taskId string) (*agents.ProcessLog, error)

获取任务最后一次的执行日志

func (*SQLAgentLogDAO) FindLatestTaskLogs

func (this *SQLAgentLogDAO) FindLatestTaskLogs(agentId string, taskId string, fromId string, size int) ([]*agents.ProcessLog, error)

获取最新任务的日志

func (*SQLAgentLogDAO) Init

func (this *SQLAgentLogDAO) Init()

初始化

func (*SQLAgentLogDAO) InsertOne

func (this *SQLAgentLogDAO) InsertOne(agentId string, log *agents.ProcessLog) error

插入一条数据

func (*SQLAgentLogDAO) TableName

func (this *SQLAgentLogDAO) TableName(agentId string) string

type SQLAgentValueDAO

type SQLAgentValueDAO struct {
	BaseDAO
}

func (*SQLAgentValueDAO) ClearItemValues

func (this *SQLAgentValueDAO) ClearItemValues(agentId string, appId string, itemId string, level notices.NoticeLevel) error

清除数值

func (*SQLAgentValueDAO) DropAgentTable

func (this *SQLAgentValueDAO) DropAgentTable(agentId string) error

删除Agent相关表

func (*SQLAgentValueDAO) FindLatestItemValue

func (this *SQLAgentValueDAO) FindLatestItemValue(agentId string, appId string, itemId string) (*agents.Value, error)

查找最近的一条记录

func (*SQLAgentValueDAO) FindLatestItemValueNoError

func (this *SQLAgentValueDAO) FindLatestItemValueNoError(agentId string, appId string, itemId string) (*agents.Value, error)

查找最近的一条非错误的记录

func (*SQLAgentValueDAO) FindLatestItemValues

func (this *SQLAgentValueDAO) FindLatestItemValues(agentId string, appId string, itemId string, noticeLevel notices.NoticeLevel, lastId string, size int) ([]*agents.Value, error)

取得最近的数值记录

func (*SQLAgentValueDAO) GroupValuesByTime

func (this *SQLAgentValueDAO) GroupValuesByTime(query *Query, timeField string, result map[string]Expr) ([]*agents.Value, error)

根据时间对值进行分组查询

func (*SQLAgentValueDAO) Init

func (this *SQLAgentValueDAO) Init()

初始化

func (*SQLAgentValueDAO) Insert

func (this *SQLAgentValueDAO) Insert(agentId string, value *agents.Value) error

插入数据

func (*SQLAgentValueDAO) ListItemValues

func (this *SQLAgentValueDAO) ListItemValues(agentId string, appId string, itemId string, noticeLevel notices.NoticeLevel, lastId string, offset int, size int) ([]*agents.Value, error)

列出数值

func (*SQLAgentValueDAO) QueryValues

func (this *SQLAgentValueDAO) QueryValues(query *Query) ([]*agents.Value, error)

分组查询

func (*SQLAgentValueDAO) TableName

func (this *SQLAgentValueDAO) TableName(agentId string) string

获取表格

type SQLAuditLogDAO

type SQLAuditLogDAO struct {
	BaseDAO
}

func (*SQLAuditLogDAO) CountAllAuditLogs

func (this *SQLAuditLogDAO) CountAllAuditLogs() (int64, error)

计算审计日志数量

func (*SQLAuditLogDAO) Init

func (this *SQLAuditLogDAO) Init()

初始化

func (*SQLAuditLogDAO) InsertOne

func (this *SQLAuditLogDAO) InsertOne(auditLog *audits.Log) error

插入一条审计日志

func (*SQLAuditLogDAO) ListAuditLogs

func (this *SQLAuditLogDAO) ListAuditLogs(offset int, size int) ([]*audits.Log, error)

列出审计日志

func (*SQLAuditLogDAO) TableName

func (this *SQLAuditLogDAO) TableName() string

type SQLCond

type SQLCond struct {
	Expr   string
	Params map[string]interface{}
}

SQL条件

type SQLDriver

type SQLDriver struct {
	BaseDriver
	// contains filtered or unexported fields
}

func (*SQLDriver) Avg

func (this *SQLDriver) Avg(query *Query, field string) (float64, error)

计算平均值

func (*SQLDriver) Count

func (this *SQLDriver) Count(query *Query) (int64, error)

计算总数量

func (*SQLDriver) DeleteOnes

func (this *SQLDriver) DeleteOnes(query *Query) error

删除多条记录

func (*SQLDriver) DropTable

func (this *SQLDriver) DropTable(table string) error

删除表

func (*SQLDriver) FindOne

func (this *SQLDriver) FindOne(query *Query, modelPtr interface{}) (interface{}, error)

查找单条记录

func (*SQLDriver) FindOnes

func (this *SQLDriver) FindOnes(query *Query, modelPtr interface{}) ([]interface{}, error)

查找多条记录

func (*SQLDriver) Group

func (this *SQLDriver) Group(query *Query, groupField string, result map[string]Expr) ([]maps.Map, error)

对数据进行分组统计

func (*SQLDriver) InsertOne

func (this *SQLDriver) InsertOne(table string, modelPtr interface{}) error

插入一条记录

func (*SQLDriver) InsertOnes

func (this *SQLDriver) InsertOnes(table string, modelPtrSlice interface{}) error

插入多条记录

func (*SQLDriver) JSONExtract

func (this *SQLDriver) JSONExtract(field string, path string) string

读取JSON字段

func (*SQLDriver) JSONExtractNumeric

func (this *SQLDriver) JSONExtractNumeric(field string, path string) string

读取JSON字段

func (*SQLDriver) Max

func (this *SQLDriver) Max(query *Query, field string) (float64, error)

计算最大值

func (*SQLDriver) Min

func (this *SQLDriver) Min(query *Query, field string) (float64, error)

计算最小值

func (*SQLDriver) Shutdown

func (this *SQLDriver) Shutdown() error

重启服务

func (*SQLDriver) Sum

func (this *SQLDriver) Sum(query *Query, field string) (float64, error)

计算总和

func (*SQLDriver) Test

func (this *SQLDriver) Test() error

测试数据库连接

func (*SQLDriver) UpdateOnes

func (this *SQLDriver) UpdateOnes(query *Query, values map[string]interface{}) error

修改多条记录

type SQLDriverInterface

type SQLDriverInterface interface {
	// 创建表格
	CreateTable(table string, definitionSQL string) error

	// 修改多条记录
	UpdateOnes(query *Query, values map[string]interface{}) error

	// 读取JSON字段
	JSONExtract(field string, path string) string
}

SQL相关接口

type SQLNoticeDAO

type SQLNoticeDAO struct {
	BaseDAO
}

func (*SQLNoticeDAO) CountAllReadNotices

func (this *SQLNoticeDAO) CountAllReadNotices() (int, error)

获取所有已读通知数

func (*SQLNoticeDAO) CountAllUnreadNotices

func (this *SQLNoticeDAO) CountAllUnreadNotices() (int, error)

获取所有未读通知数

func (*SQLNoticeDAO) CountReadNoticesForAgent

func (this *SQLNoticeDAO) CountReadNoticesForAgent(agentId string) (int, error)

获取某个Agent已读通知数

func (*SQLNoticeDAO) CountReceivedNotices

func (this *SQLNoticeDAO) CountReceivedNotices(receiverId string, cond map[string]interface{}, minutes int) (int, error)

获取某个接收人在某个时间段内接收的通知数

func (*SQLNoticeDAO) CountUnreadNoticesForAgent

func (this *SQLNoticeDAO) CountUnreadNoticesForAgent(agentId string) (int, error)

获取某个Agent的未读通知数

func (*SQLNoticeDAO) DeleteNoticesForAgent

func (this *SQLNoticeDAO) DeleteNoticesForAgent(agentId string) error

删除Agent相关通知

func (*SQLNoticeDAO) ExistNoticesWithHash

func (this *SQLNoticeDAO) ExistNoticesWithHash(hash string, cond map[string]interface{}, duration time.Duration) (bool, error)

通过Hash判断是否存在相同的消息

func (*SQLNoticeDAO) Init

func (this *SQLNoticeDAO) Init()

初始化

func (*SQLNoticeDAO) InsertOne

func (this *SQLNoticeDAO) InsertOne(notice *notices.Notice) error

写入一个通知

func (*SQLNoticeDAO) ListAgentNotices

func (this *SQLNoticeDAO) ListAgentNotices(agentId string, isRead bool, offset int, size int) ([]*notices.Notice, error)

列出某个Agent相关的消息

func (*SQLNoticeDAO) ListNotices

func (this *SQLNoticeDAO) ListNotices(isRead bool, offset int, size int) ([]*notices.Notice, error)

列出消息

func (*SQLNoticeDAO) NotifyProxyMessage

func (this *SQLNoticeDAO) NotifyProxyMessage(cond notices.ProxyCond, message string) error

发送一个代理的通知(形式1)

func (*SQLNoticeDAO) NotifyProxyServerMessage

func (this *SQLNoticeDAO) NotifyProxyServerMessage(serverId string, level notices.NoticeLevel, message string) error

发送一个代理的通知(形式2)

func (*SQLNoticeDAO) TableName

func (this *SQLNoticeDAO) TableName() string

表名

func (*SQLNoticeDAO) UpdateAgentNoticesRead

func (this *SQLNoticeDAO) UpdateAgentNoticesRead(agentId string, noticeIds []string) error

设置Agent的一组通知已读

func (*SQLNoticeDAO) UpdateAllAgentNoticesRead

func (this *SQLNoticeDAO) UpdateAllAgentNoticesRead(agentId string) error

设置Agent所有通知已读

func (*SQLNoticeDAO) UpdateAllNoticesRead

func (this *SQLNoticeDAO) UpdateAllNoticesRead() error

设置全部已读

func (*SQLNoticeDAO) UpdateNoticeReceivers

func (this *SQLNoticeDAO) UpdateNoticeReceivers(noticeId string, receiverIds []string) error

更改某个通知的接收人

func (*SQLNoticeDAO) UpdateNoticesRead

func (this *SQLNoticeDAO) UpdateNoticesRead(noticeIds []string) error

设置一组通知已读

type SQLParamsHolder

type SQLParamsHolder struct {
	Params map[string]interface{} // holder => value
	Args   []interface{}
	// contains filtered or unexported fields
}

SQL参数holder

func NewSQLParamsHolder

func NewSQLParamsHolder(driver string) *SQLParamsHolder

获取新对象

func (*SQLParamsHolder) Add

func (this *SQLParamsHolder) Add(value interface{}) (holder string)

添加参数值

func (*SQLParamsHolder) AddHolder

func (this *SQLParamsHolder) AddHolder(holder string, value interface{})

添加自定义参数值

func (*SQLParamsHolder) AddSlice

func (this *SQLParamsHolder) AddSlice(s interface{}) (holder string)

参加slice参数值

func (*SQLParamsHolder) Parse

func (this *SQLParamsHolder) Parse(sqlString string) string

分析数据

type SQLServerValueDAO

type SQLServerValueDAO struct {
	BaseDAO
}

func (*SQLServerValueDAO) CreateIndex

func (this *SQLServerValueDAO) CreateIndex(serverId string, fields []*shared.IndexField) error

创建索引

func (*SQLServerValueDAO) DeleteExpiredValues

func (this *SQLServerValueDAO) DeleteExpiredValues(serverId string, period stats.ValuePeriod, life int) error

删除过期的数据

func (*SQLServerValueDAO) DropServerTable

func (this *SQLServerValueDAO) DropServerTable(serverId string) error

删除代理服务相关表

func (*SQLServerValueDAO) FindOneWithItem

func (this *SQLServerValueDAO) FindOneWithItem(serverId string, item string) (*stats.Value, error)

根据item查找一条数据

func (*SQLServerValueDAO) FindSameItemValue

func (this *SQLServerValueDAO) FindSameItemValue(serverId string, item *stats.Value) (*stats.Value, error)

查询相同的数值记录

func (*SQLServerValueDAO) Init

func (this *SQLServerValueDAO) Init()

初始化

func (*SQLServerValueDAO) InsertOne

func (this *SQLServerValueDAO) InsertOne(serverId string, value *stats.Value) error

插入新数据

func (*SQLServerValueDAO) QueryValues

func (this *SQLServerValueDAO) QueryValues(query *Query) ([]*stats.Value, error)

查询数据

func (*SQLServerValueDAO) TableName

func (this *SQLServerValueDAO) TableName(serverId string) string

表名

func (*SQLServerValueDAO) UpdateItemValueAndTimestamp

func (this *SQLServerValueDAO) UpdateItemValueAndTimestamp(serverId string, valueId string, value map[string]interface{}, timestamp int64) error

修改值和时间戳

type ServerValueDAOInterface

type ServerValueDAOInterface interface {
	// 设置驱动
	SetDriver(driver DriverInterface)

	// 初始化
	Init()

	// 表名
	TableName(serverId string) string

	// 插入新数据
	InsertOne(serverId string, value *stats.Value) error

	// 删除过期的数据
	DeleteExpiredValues(serverId string, period stats.ValuePeriod, life int) error

	// 查询相同的数值记录
	FindSameItemValue(serverId string, item *stats.Value) (*stats.Value, error)

	// 修改值和时间戳
	UpdateItemValueAndTimestamp(serverId string, valueId string, value map[string]interface{}, timestamp int64) error

	// 创建索引
	CreateIndex(serverId string, fields []*shared.IndexField) error

	// 查询数据
	QueryValues(query *Query) ([]*stats.Value, error)

	// 根据item查找一条数据
	FindOneWithItem(serverId string, item string) (*stats.Value, error)

	// 删除代理服务相关表
	DropServerTable(serverId string) error
}

代理统计DAO

func ServerValueDAO

func ServerValueDAO() ServerValueDAOInterface

获取代理统计数值DAO

type SortField

type SortField struct {
	Name string
	Type SortType
}

排序字段

func (*SortField) IsAsc

func (this *SortField) IsAsc() bool

func (*SortField) IsDesc

func (this *SortField) IsDesc() bool

type SortType

type SortType = string

type SumExpr

type SumExpr struct {
	Field string
}

总和表达式

func NewSumExpr

func NewSumExpr(field string) *SumExpr

type TableStat

type TableStat struct {
	Count         int64  `yaml:"count" json:"count"`
	Size          int64  `yaml:"size" json:"size"`
	FormattedSize string `yaml:"formattedSize" json:"formattedSize"`
}

表格统计

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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