Commit 49660de9 authored by 黄智's avatar 黄智

Merge remote-tracking branch 'origin/dev' into dev

parents d8542e2b 6d17138f
......@@ -4,7 +4,8 @@ import (
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/jsontime"
)
type AlertList struct {
// Alert 预警表
type Alert struct {
Id int `json:"id"` // 预警列表ID,主键,自增长
AlertPoint string `json:"alert_point"` // 预警点
AlertRulesId string `json:"alert_rules_id"` // 告警规则id
......@@ -42,6 +43,6 @@ type DisposedList struct {
DisposalTime jsontime.Time `json:"disposal_time"` // 处置时间(工单管理,结果反馈)
}
func (a *AlertList) TableName() string {
return "alert_list"
func (a *Alert) TableName() string {
return "alert"
}
......@@ -4,31 +4,31 @@ import (
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity"
)
type DetailAlertList struct {
type DetailAlert struct {
Id int `json:"id" form:"id" binding:"required"`
}
type UpdateAlertList struct {
type UpdateAlert struct {
RiskLevel int `json:"risk_level" form:"risk_level" binding:"omitempty,oneof=1 2 3 4"` // 风险等级,1:低风险,2:一般风险,3:较大风险,4:重大风险
Status int `json:"status" form:"status" binding:"omitempty,oneof=1 2 3"` // 状态,1:已恢复 2:未恢复 3:已关闭
Keyword string `json:"keyword" form:"keyword"` // 预警点/分类/指标
}
type BatchPushAlertList struct {
type BatchPushAlert struct {
Id string `json:"id" form:"id"`
Ids []string `json:"ids" form:"ids" binding:"required_without=Id"` // 预警ids
NotifyMethod []string `json:"notify_method" form:"notify_method" binding:"max=2,dive,oneof=dingtalk sms"` // 预警通知方式 dingtalk sms
NotifyRecipients []entity.NotifyRecipients `json:"notify_recipients" form:"notify_recipients" binding:"dive"` // 预警推送用户
}
type BatchCloseAlertList struct {
type BatchCloseAlert struct {
Id string `json:"id" form:"id"`
Ids []string `json:"ids" form:"ids" binding:"required_without=Id"` // 预警ids
CloseRemark string `json:"close_remark" form:"close_remark" binding:"required"` // 关闭备注
DeferPush int `json:"defer_push" form:"defer_push" binding:"omitempty,oneof=0 1"` // 延迟三天推送: 0:否 1:是 三天内将不再自动推送该告警信息给处置人员,可手动推送,但告警数据依然会出现
}
type ListAlertList struct {
type ListAlert struct {
Id int `json:"id" form:"id"`
RiskLevel int `json:"risk_level" form:"risk_level" binding:"omitempty,oneof=1 2 3 4"` // 风险等级,1:低风险,2:一般风险,3:较大风险,4:重大风险
Status int `json:"status" form:"status" binding:"omitempty,oneof=1 2 3"` // 状态,1:已恢复 2:未恢复 3:已关闭
......@@ -38,7 +38,7 @@ type ListAlertList struct {
Pagination
}
type DisposeAlertList struct {
type DisposeAlert struct {
Id int `json:"id" form:"id" binding:"required"`
Status int `json:"status" form:"status" binding:"oneof=1 2"` // 状态,1:已恢复 2:未恢复 3:已关闭
DisposalContent string `json:"disposal_content" binding:"required"` // 处置内容(工单管理,结果反馈)
......
......@@ -4,15 +4,15 @@ import (
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity"
)
type AlertListItem struct {
entity.AlertList `xorm:"extends"`
AlertCondition entity.AlertCondition `json:"alert_condition" xorm:"alert_condition"`
PushRecords []PushRecordItem `json:"push_records"`
type AlertItem struct {
entity.Alert `xorm:"extends"`
AlertCondition entity.AlertCondition `json:"alert_condition" xorm:"alert_condition"`
PushRecords []PushRecordItem `json:"push_records"`
}
type AlertListList struct {
TotalCount int64 `json:"total_count"`
List []AlertListItem `json:"list"`
type AlertList struct {
TotalCount int64 `json:"total_count"`
List []AlertItem `json:"list"`
}
type CatIndices struct {
......@@ -46,12 +46,12 @@ type Total struct {
}
type SubHits struct {
Index string `json:"_index"`
Type string `json:"_type"`
ID string `json:"_id"`
Score float64 `json:"_score"`
Ignored []string `json:"_ignored"`
Source AlertListItem `json:"_source"`
Index string `json:"_index"`
Type string `json:"_type"`
ID string `json:"_id"`
Score float64 `json:"_score"`
Ignored []string `json:"_ignored"`
Source AlertItem `json:"_source"`
}
type Hits struct {
Total Total `json:"total"`
......
......@@ -9,8 +9,8 @@ import (
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/service"
)
func UpdateAlertList(c *gin.Context) {
var req request.UpdateAlertList
func UpdateAlert(c *gin.Context) {
var req request.UpdateAlert
if err := c.ShouldBind(&req); err != nil {
SendJsonResponse(c, resp.InvalidParam.TranslateError(err), nil)
return
......@@ -30,8 +30,8 @@ func UpdateAlertList(c *gin.Context) {
SendJsonResponse(c, resp.OK, nil)
}
func BatchPushAlertList(c *gin.Context) {
var req request.BatchPushAlertList
func BatchPushAlert(c *gin.Context) {
var req request.BatchPushAlert
if err := c.ShouldBind(&req); err != nil {
SendJsonResponse(c, resp.InvalidParam.TranslateError(err), nil)
return
......@@ -51,8 +51,8 @@ func BatchPushAlertList(c *gin.Context) {
SendJsonResponse(c, resp.OK, nil)
}
func BatchCloseAlertList(c *gin.Context) {
var req request.BatchCloseAlertList
func BatchCloseAlert(c *gin.Context) {
var req request.BatchCloseAlert
if err := c.ShouldBind(&req); err != nil {
SendJsonResponse(c, resp.InvalidParam.TranslateError(err), nil)
return
......@@ -72,8 +72,8 @@ func BatchCloseAlertList(c *gin.Context) {
SendJsonResponse(c, resp.OK, nil)
}
func DetailAlertList(c *gin.Context) {
var req request.DetailAlertList
func DetailAlert(c *gin.Context) {
var req request.DetailAlert
if err := c.ShouldBind(&req); err != nil {
SendJsonResponse(c, resp.InvalidParam.TranslateError(err), nil)
return
......@@ -88,8 +88,8 @@ func DetailAlertList(c *gin.Context) {
SendJsonResponse(c, resp.OK, data)
}
func ListAlertList(c *gin.Context) {
var req request.ListAlertList
func ListAlert(c *gin.Context) {
var req request.ListAlert
if err := c.ShouldBind(&req); err != nil {
SendJsonResponse(c, resp.InvalidParam.TranslateError(err), nil)
return
......@@ -103,8 +103,8 @@ func ListAlertList(c *gin.Context) {
SendJsonResponse(c, resp.OK, data)
}
func DisposeAlertList(c *gin.Context) {
var req request.DisposeAlertList
func DisposeAlert(c *gin.Context) {
var req request.DisposeAlert
if err := c.ShouldBind(&req); err != nil {
SendJsonResponse(c, resp.InvalidParam.TranslateError(err), nil)
return
......
......@@ -9,8 +9,13 @@ import (
// InitAlertOverviewRouter 初始化预警总览配置路由
func InitAlertOverviewRouter(e *gin.Engine) {
group := e.Group(fmt.Sprintf("%s/alert_overview", conf.Options.Prefix))
overviewGroup := e.Group(fmt.Sprintf("%s/alert_overview", conf.Options.Prefix))
{
group.GET("", controller.DetailAlertOverview)
overviewGroup.GET("", controller.DetailAlertOverview)
}
screensGroup := e.Group(fmt.Sprintf("%s/screens", conf.Options.Prefix))
{
screensGroup.GET("", controller.DetailAlert)
screensGroup.GET("list", controller.ListAlert)
}
}
......@@ -9,12 +9,12 @@ import (
// InitAlertListRouter 初始化预警列表配置路由
func InitAlertListRouter(e *gin.Engine) {
group := e.Group(fmt.Sprintf("%s/alert_list", conf.Options.Prefix))
group := e.Group(fmt.Sprintf("%s/alert", conf.Options.Prefix))
{
group.GET("", controller.DetailAlertList)
group.GET("list", controller.ListAlertList)
group.PUT("", controller.UpdateAlertList)
group.PUT("batch/push", controller.BatchPushAlertList)
group.PUT("batch/close", controller.BatchCloseAlertList)
group.GET("", controller.DetailAlert)
group.GET("list", controller.ListAlert)
group.PUT("", controller.UpdateAlert)
group.PUT("batch/push", controller.BatchPushAlert)
group.PUT("batch/close", controller.BatchCloseAlert)
}
}
......@@ -14,9 +14,9 @@ func InitWorkOrderRouter(e *gin.Engine) {
//预警工单管理
alert := so.Group("/alert", header.SetContext)
{
alert.GET("", controller.DetailAlertList) // 详情
alert.GET("/list", controller.ListAlertList) // 列表
alert.PUT("/dispose", controller.DisposeAlertList) // 处置反馈
alert.GET("", controller.DetailAlert) // 详情
alert.GET("/list", controller.ListAlert) // 列表
alert.PUT("/dispose", controller.DisposeAlert) // 处置反馈
}
//业务工单管理
......
......@@ -238,7 +238,7 @@ func (a *AlertListSvc) Indices() (indices []string, err error) {
return
}
func (a *AlertListSvc) IndexSearch(req request.ListAlertList) (resp response.AlertListList, err error) {
func (a *AlertListSvc) IndexSearch(req request.ListAlert) (resp response.AlertList, err error) {
var (
sources response.OpenSearchSource
)
......@@ -312,9 +312,9 @@ func (a *AlertListSvc) IndexSearch(req request.ListAlertList) (resp response.Ale
return
}
func (a *AlertListSvc) Update(session *xorm.Session, req request.UpdateAlertList) error {
func (a *AlertListSvc) Update(session *xorm.Session, req request.UpdateAlert) error {
now := jsontime.Now()
data := entity.AlertList{
data := entity.Alert{
UpdatedBy: a.User.SystemAccount,
UpdatedAt: now,
}
......@@ -326,7 +326,7 @@ func (a *AlertListSvc) Update(session *xorm.Session, req request.UpdateAlertList
return nil
}
func (a *AlertListSvc) BatchPushAlertList(session *xorm.Session, req request.BatchPushAlertList) error {
func (a *AlertListSvc) BatchPushAlertList(session *xorm.Session, req request.BatchPushAlert) error {
now := jsontime.Now()
_ = now
// TODO 批量推送用户告警
......@@ -334,7 +334,7 @@ func (a *AlertListSvc) BatchPushAlertList(session *xorm.Session, req request.Bat
return nil
}
func (a *AlertListSvc) BatchCloseAlertList(session *xorm.Session, req request.BatchCloseAlertList) error {
func (a *AlertListSvc) BatchCloseAlertList(session *xorm.Session, req request.BatchCloseAlert) error {
now := jsontime.Now()
_ = now
// TODO 批量推送用户告警
......@@ -342,10 +342,10 @@ func (a *AlertListSvc) BatchCloseAlertList(session *xorm.Session, req request.Ba
return nil
}
func (a *AlertListSvc) GetDataById(req request.DetailAlertList) (resp response.AlertListItem, err error) {
func (a *AlertListSvc) GetDataById(req request.DetailAlert) (resp response.AlertItem, err error) {
/*now := jsontime.Now()
data := response.AlertListItem{
AlertList: entity.AlertList{
data := response.AlertItem{
Alert: entity.Alert{
Id: 123,
AlertPoint: "容器云/kube-apiserver",
AlertRulesId: "762ed641-6c0e-4c39-bf7c-7463abb0f8a2",
......@@ -423,17 +423,17 @@ func (a *AlertListSvc) GetDataById(req request.DetailAlertList) (resp response.A
},
},
}*/
list, err := a.IndexSearch(request.ListAlertList{Id: req.Id})
list, err := a.IndexSearch(request.ListAlert{Id: req.Id})
if len(list.List) > 0 {
resp = list.List[0]
}
return
}
func (a *AlertListSvc) List(req request.ListAlertList) (resp response.AlertListList, err error) {
func (a *AlertListSvc) List(req request.ListAlert) (resp response.AlertList, err error) {
/*now := jsontime.Now()
data1 := response.AlertListItem{
AlertList: entity.AlertList{
data1 := response.AlertItem{
Alert: entity.Alert{
Id: 123,
AlertPoint: "容器云/kube-apiserver",
AlertRulesId: "762ed641-6c0e-4c39-bf7c-7463abb0f8a2",
......@@ -517,8 +517,8 @@ func (a *AlertListSvc) List(req request.ListAlertList) (resp response.AlertListL
},
},
}
data2 := response.AlertListItem{
AlertList: entity.AlertList{
data2 := response.AlertItem{
Alert: entity.Alert{
Id: 125,
AlertPoint: "容器云/apaas",
AlertRulesId: "762ed641-6c0e-4c39-bf7c-7463abb0f8a2",
......@@ -605,7 +605,7 @@ func (a *AlertListSvc) List(req request.ListAlertList) (resp response.AlertListL
return
}
func (a *AlertListSvc) DisposeAlertList(session *xorm.Session, req request.DisposeAlertList) error {
func (a *AlertListSvc) DisposeAlertList(session *xorm.Session, req request.DisposeAlert) error {
now := jsontime.Now()
_ = now
// TODO 我的预警工单处置
......
package service
import (
"github.com/jinzhu/copier"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/response"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/client"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/jsontime"
"xorm.io/xorm"
)
type AlertWebhookSvc struct {
User entity.SystemUserInfo
}
// TODO AlertManager 回调接口
func (a *AlertWebhookSvc) WebHook(session *xorm.Session, req request.AddPushRecord) (id string, err error) {
// 报警消息
now := jsontime.Now()
data := entity.PushRecord{
CreatedBy: a.User.SystemAccount,
CreatedAt: now,
UpdatedBy: a.User.SystemAccount,
UpdatedAt: now,
}
_ = copier.Copy(&data, &req)
_, err = session.Insert(&data)
if err != nil {
return
}
return
}
func (a *AlertWebhookSvc) Update(session *xorm.Session, req request.UpdatePushRecord) error {
now := jsontime.Now()
data := entity.PushRecord{
UpdatedBy: a.User.SystemAccount,
UpdatedAt: now,
}
_ = copier.Copy(&data, &req)
_, err := session.ID(req.Id).Update(&data)
if err != nil {
return err
}
return nil
}
func (a *AlertWebhookSvc) GetDataById(req request.DetailPushRecord) (resp response.PushRecordItem, err error) {
now := jsontime.Time{}
data := response.PushRecordItem{
PushRecord: entity.PushRecord{
Id: 1,
AlertRulesId: "83343ef6-4a99-47bd-abb4-bcff52feb2ec",
RiskLevel: 1,
SystemAccount: "xiaowang",
PushTime: now,
PushType: 1,
Status: 1,
CreatedBy: "admin",
CreatedAt: now,
UpdatedBy: "admin",
UpdatedAt: now,
},
NotifyMethod: []string{"dingtalk", "sms"},
}
resp = data
return
}
func (a *AlertWebhookSvc) List(req request.ListPushRecord) (resp response.PushRecordList, err error) {
now := jsontime.Time{}
data1 := response.PushRecordItem{
PushRecord: entity.PushRecord{
Id: 1,
AlertRulesId: "83343ef6-4a99-47bd-abb4-bcff52feb2ec",
RiskLevel: 1,
SystemAccount: "xiaowang",
PushTime: now,
PushType: 1,
Status: 1,
CreatedBy: "admin",
CreatedAt: now,
UpdatedBy: "admin",
UpdatedAt: now,
},
NotifyMethod: []string{"dingtalk", "sms"},
}
data2 := response.PushRecordItem{
PushRecord: entity.PushRecord{
Id: 1,
AlertRulesId: "83343ef6-4a99-47bd-abb4-bcff52feb2ec",
RiskLevel: 2,
SystemAccount: "xiaozhang",
PushTime: now,
PushType: 2,
Status: 2,
CreatedBy: "admin",
CreatedAt: now,
UpdatedBy: "admin",
UpdatedAt: now,
},
NotifyMethod: []string{"dingtalk", "sms"},
}
resp.List = append(resp.List, data1, data2)
resp.TotalCount = int64(len(resp.List))
return
}
func (a *AlertWebhookSvc) Delete(ids []string) (err error) {
db, err := client.GetDbClient()
if err != nil {
return
}
_, err = db.NewSession().In("id", ids).Delete(new(entity.PushRecord))
return
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment