Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
so-operation-api
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
smart-operation
so-operation-api
Commits
ef1ffd7b
Commit
ef1ffd7b
authored
Jul 06, 2023
by
李科
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 预警列表
parent
48b7e7d0
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
289 additions
and
10 deletions
+289
-10
src/bean/entity/alert_class.go
src/bean/entity/alert_class.go
+9
-9
src/bean/entity/alert_list.go
src/bean/entity/alert_list.go
+29
-0
src/bean/entity/alert_rules.go
src/bean/entity/alert_rules.go
+1
-1
src/bean/entity/push_record.go
src/bean/entity/push_record.go
+18
-0
src/bean/vo/request/alert_list.go
src/bean/vo/request/alert_list.go
+20
-0
src/bean/vo/response/alert_list.go
src/bean/vo/response/alert_list.go
+15
-0
src/controller/alert_list.go
src/controller/alert_list.go
+62
-0
src/router/alertlistrouter.go.go
src/router/alertlistrouter.go.go
+17
-0
src/router/router.go
src/router/router.go
+2
-0
src/service/alert_list.go
src/service/alert_list.go
+116
-0
No files found.
src/bean/entity/alert_class.go
View file @
ef1ffd7b
...
@@ -3,15 +3,15 @@ package entity
...
@@ -3,15 +3,15 @@ package entity
import
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/jsontime"
import
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/jsontime"
type
AlertClass
struct
{
type
AlertClass
struct
{
ClassId
int
`json:"class_id" xorm:"'class_id' pk autoincr"
`
// 主键id
ClassId
int
`json:"class_id" xorm:"'class_id' pk autoincr"`
// 主键id
ClassName
string
`json:"class_name" xorm:"'class_name'"`
// 分类名称
ClassName
string
`json:"class_name" xorm:"'class_name'"`
// 分类名称
ParentId
int
`json:"parent_id" xorm:"'parent_id'"`
// 父级id
ParentId
int
`json:"parent_id" xorm:"'parent_id'"`
// 父级id
SortOrder
int
`json:"sort_order" xorm:"'sort_order'"`
// 排序
SortOrder
int
`json:"sort_order" xorm:"'sort_order'"`
// 排序
SourceFrom
int
`json:"source_from" xorm:"source_from"`
// 数据来源 1:默认 2:自定义
SourceFrom
int
`json:"source_from" xorm:"source_from"`
// 数据来源 1:默认 2:自定义
CreatedBy
string
`json:"created_by" xorm:"'created_by'"`
// 创建人
CreatedBy
string
`json:"created_by" xorm:"'created_by'"`
// 创建人
CreatedAt
jsontime
.
Time
`json:"created_at" xorm:"'created_at'"`
// 创建时间
CreatedAt
jsontime
.
Time
`json:"created_at" xorm:"'created_at'"`
// 创建时间
UpdatedBy
string
`json:"updated_by" xorm:"'updated_by'"`
// 更新人
UpdatedBy
string
`json:"updated_by" xorm:"'updated_by'"`
// 更新人
UpdatedAt
jsontime
.
Time
`json:"updated_at" xorm:"'updated_at'"`
// 更新时间
UpdatedAt
jsontime
.
Time
`json:"updated_at" xorm:"'updated_at'"`
// 更新时间
}
}
func
(
m
*
AlertClass
)
TableName
()
string
{
func
(
m
*
AlertClass
)
TableName
()
string
{
...
...
src/bean/entity/alert_list.go
0 → 100644
View file @
ef1ffd7b
package
entity
import
(
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/jsontime"
)
type
AlertList
struct
{
Id
int
`json:"id"`
// 预警列表ID,主键,自增长
AlertPoint
string
`json:"alert_point"`
// 预警点
AlertRulesId
string
`json:"alert_rules_id"`
// 告警规则id
RiskLevel
int
`json:"risk_level"`
// 风险等级,1:低风险,2:一般风险,3:较大风险,4:重大风险
AlertTime
jsontime
.
Time
`json:"alert_time"`
// 预警时间
ClassId
int
`json:"class_id" xorm:"'class_id'"`
// 预警对象id(级联:预警分类/预警对象)
MetricConfigId
string
`json:"metric_config_id"`
// 预警指标id // 预警指标
CurrentValue
float64
`json:"current_value"`
// 当前报警值
AlertCondition
string
`json:"alert_condition" xorm:"'alert_condition'"`
// 预警规则(预警阈值) 字典值
NotificationCount
int
`json:"notification_count"`
// 通知人数
PushCount
int
`json:"push_count"`
// 推送次数
LastPushTime
jsontime
.
Time
`json:"last_push_time"`
// 最近推送时间
Status
int
`json:"status"`
// 状态,1:已恢复 2:未恢复 3:已关闭
CreatedBy
string
`json:"created_by" xorm:"'created_by'"`
// 创建人
CreatedAt
jsontime
.
Time
`json:"created_at" xorm:"'created_at'"`
// 创建时间
UpdatedBy
string
`json:"updated_by" xorm:"'updated_by'"`
// 更新人
UpdatedAt
jsontime
.
Time
`json:"updated_at" xorm:"'updated_at'"`
// 更新时间
}
func
(
a
*
AlertList
)
TableName
()
string
{
return
"alert_list"
}
src/bean/entity/alert_rules.go
View file @
ef1ffd7b
...
@@ -38,7 +38,7 @@ type RulesAlertRange struct {
...
@@ -38,7 +38,7 @@ type RulesAlertRange struct {
type
AlertCondition
struct
{
type
AlertCondition
struct
{
ThresholdsMax
int
`json:"thresholds_max" form:"thresholds_max" binding:"required"`
ThresholdsMax
int
`json:"thresholds_max" form:"thresholds_max" binding:"required"`
ThresholdsMin
int
`json:"thresholds_min" form:"thresholds_min" binding:"required"`
ThresholdsMin
int
`json:"thresholds_min" form:"thresholds_min" binding:"required"`
RiskLevel
int
`json:"risk_level" form:"risk_level" binding:"required"`
RiskLevel
int
`json:"risk_level" form:"risk_level" binding:"required
,oneof=1 2 3 4
"`
}
}
type
NotifyRecipients
struct
{
type
NotifyRecipients
struct
{
...
...
src/bean/entity/push_record.go
0 → 100644
View file @
ef1ffd7b
package
entity
import
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/jsontime"
type
PushRecord
struct
{
Id
int
`json:"id" xorm:"'id' pk autoincr"`
// 主键id
AlertRulesId
string
`json:"alert_rules_id" xorm:"'alert_rules_id'"`
// 告警规则id
RiskLevel
int
`json:"risk_level" xorm:"'risk_level'"`
// 风险等级,1:低风险,2:一般风险,3:较大风险,4:重大风险
NotifyMethod
string
`json:"notify_method" xorm:"'notify_method'"`
// 预警通知方式 all dingtalk sms
SystemAccount
string
`json:"system_account" xorm:"system_account"`
// 预警推送用户(NotifyRecipient) // 账号
PushTime
jsontime
.
Time
`json:"push_time" xorm:"'push_time'"`
// 推送时间
PushType
int
`json:"push_type" xorm:"'push_type'"`
// 推送类型,1:自动推送,2:手动推送
Status
int
`json:"status" xorm:"'status'"`
// 推送状态,1:成功,2:失败
CreatedBy
string
`json:"created_by" xorm:"'created_by'"`
// 创建人
CreatedAt
jsontime
.
Time
`json:"created_at" xorm:"'created_at'"`
// 创建时间
UpdatedBy
string
`json:"updated_by" xorm:"'updated_by'"`
// 更新人
UpdatedAt
jsontime
.
Time
`json:"updated_at" xorm:"'updated_at'"`
// 更新时间
}
src/bean/vo/request/alert_list.go
0 → 100644
View file @
ef1ffd7b
package
request
type
DetailAlertList
struct
{
Id
int
`json:"id" form:"id" binding:"required"`
}
type
UpdateAlertList
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
ListAlertList
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:已关闭
Keyword
string
`json:"keyword" form:"keyword"`
// 预警点/分类/指标
StartTime
string
`json:"start_time" form:"start_time" binding:"omitempty,datetime=2006-01-02 15:04:05"`
EndTime
string
`json:"end_time" form:"end_time" binding:"omitempty,datetime=2006-01-02 15:04:05"`
}
src/bean/vo/response/alert_list.go
0 → 100644
View file @
ef1ffd7b
package
response
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"`
}
type
AlertListList
struct
{
TotalCount
int64
`json:"total_count"`
List
[]
AlertListItem
`json:"list"`
}
src/controller/alert_list.go
0 → 100644
View file @
ef1ffd7b
package
controller
import
(
"github.com/gin-gonic/gin"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/client"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/service"
)
func
UpdateAlertList
(
c
*
gin
.
Context
)
{
var
req
request
.
UpdateAlertList
if
err
:=
c
.
ShouldBind
(
&
req
);
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
TranslateError
(
err
),
nil
)
return
}
svc
:=
service
.
AlertListSvc
{
User
:
header
.
GetUser
(
c
)}
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
DbConnectError
.
WithError
(
err
),
nil
)
return
}
err
=
svc
.
Update
(
db
.
NewSession
(),
req
)
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
),
nil
)
return
}
SendJsonResponse
(
c
,
resp
.
OK
,
nil
)
}
func
DetailAlertList
(
c
*
gin
.
Context
)
{
var
req
request
.
DetailAlertList
if
err
:=
c
.
ShouldBind
(
&
req
);
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
TranslateError
(
err
),
nil
)
return
}
svc
:=
service
.
AlertListSvc
{
User
:
header
.
GetUser
(
c
)}
data
,
err
:=
svc
.
GetDataById
(
req
)
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
),
nil
)
return
}
SendJsonResponse
(
c
,
resp
.
OK
,
data
)
}
func
ListAlertList
(
c
*
gin
.
Context
)
{
var
req
request
.
ListAlertList
if
err
:=
c
.
ShouldBind
(
&
req
);
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
TranslateError
(
err
),
nil
)
return
}
svc
:=
service
.
AlertListSvc
{
User
:
header
.
GetUser
(
c
)}
data
,
err
:=
svc
.
List
(
req
)
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
),
nil
)
return
}
SendJsonResponse
(
c
,
resp
.
OK
,
data
)
}
src/router/alertlistrouter.go.go
0 → 100644
View file @
ef1ffd7b
package
router
import
(
"fmt"
"github.com/gin-gonic/gin"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/controller"
)
// InitAlertListRouter 初始化预警列表配置路由
func
InitAlertListRouter
(
e
*
gin
.
Engine
)
{
group
:=
e
.
Group
(
fmt
.
Sprintf
(
"%s/alert_list"
,
conf
.
Options
.
Prefix
))
{
group
.
GET
(
""
,
controller
.
DetailAlertList
)
group
.
GET
(
"list"
,
controller
.
ListAlertList
)
}
}
src/router/router.go
View file @
ef1ffd7b
...
@@ -53,6 +53,8 @@ func Load(r *gin.Engine, middleware ...gin.HandlerFunc) {
...
@@ -53,6 +53,8 @@ func Load(r *gin.Engine, middleware ...gin.HandlerFunc) {
InitMetricConfigRouter
(
r
)
InitMetricConfigRouter
(
r
)
// 初始化预警规则配置路由
// 初始化预警规则配置路由
InitAlertRulesRouter
(
r
)
InitAlertRulesRouter
(
r
)
// 初始化预警列表配置路由
InitAlertListRouter
(
r
)
// 初始化prometheus路由
// 初始化prometheus路由
InitPrometheusRouter
(
r
)
InitPrometheusRouter
(
r
)
// 初始化工单管理路由
// 初始化工单管理路由
...
...
src/service/alert_list.go
0 → 100644
View file @
ef1ffd7b
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/pkg/beagle/jsontime"
"xorm.io/xorm"
)
type
AlertListSvc
struct
{
User
entity
.
SystemUserInfo
}
func
(
a
*
AlertListSvc
)
Update
(
session
*
xorm
.
Session
,
req
request
.
UpdateAlertList
)
error
{
now
:=
jsontime
.
Now
()
data
:=
entity
.
AlertList
{
UpdatedBy
:
a
.
User
.
SystemAccount
,
UpdatedAt
:
now
,
}
_
=
copier
.
Copy
(
&
data
,
&
req
)
_
,
err
:=
session
.
Cols
(
"class_name"
,
"updated_by"
,
"updated_at"
)
.
ID
(
data
.
ClassId
)
.
Update
(
&
data
)
if
err
!=
nil
{
return
err
}
return
nil
}
func
(
a
*
AlertListSvc
)
GetDataById
(
req
request
.
DetailAlertList
)
(
resp
response
.
AlertListItem
,
err
error
)
{
now
:=
jsontime
.
Now
()
data
:=
response
.
AlertListItem
{
AlertList
:
entity
.
AlertList
{
Id
:
123
,
AlertPoint
:
"容器云/kube-apiserver"
,
AlertRulesId
:
"762ed641-6c0e-4c39-bf7c-7463abb0f8a2"
,
RiskLevel
:
4
,
AlertTime
:
now
,
ClassId
:
14
,
MetricConfigId
:
"d773b37b-dbb4-4a7b-be11-ab40f8acc00e"
,
CurrentValue
:
85
,
NotificationCount
:
3
,
PushCount
:
3
,
LastPushTime
:
now
,
Status
:
0
,
CreatedBy
:
"admin"
,
CreatedAt
:
now
,
UpdatedBy
:
"admin"
,
UpdatedAt
:
now
,
},
AlertCondition
:
entity
.
AlertCondition
{
ThresholdsMax
:
100
,
ThresholdsMin
:
80
,
RiskLevel
:
4
,
},
}
resp
=
data
return
}
func
(
a
*
AlertListSvc
)
List
(
req
request
.
ListAlertList
)
(
resp
response
.
AlertListList
,
err
error
)
{
now
:=
jsontime
.
Now
()
data1
:=
response
.
AlertListItem
{
AlertList
:
entity
.
AlertList
{
Id
:
123
,
AlertPoint
:
"容器云/kube-apiserver"
,
AlertRulesId
:
"762ed641-6c0e-4c39-bf7c-7463abb0f8a2"
,
RiskLevel
:
4
,
AlertTime
:
now
,
ClassId
:
14
,
MetricConfigId
:
"d773b37b-dbb4-4a7b-be11-ab40f8acc00e"
,
CurrentValue
:
85
,
NotificationCount
:
3
,
PushCount
:
3
,
LastPushTime
:
now
,
Status
:
2
,
CreatedBy
:
"admin"
,
CreatedAt
:
now
,
UpdatedBy
:
"admin"
,
UpdatedAt
:
now
,
},
AlertCondition
:
entity
.
AlertCondition
{
ThresholdsMax
:
100
,
ThresholdsMin
:
80
,
RiskLevel
:
4
,
},
}
data2
:=
response
.
AlertListItem
{
AlertList
:
entity
.
AlertList
{
Id
:
125
,
AlertPoint
:
"容器云/apaas"
,
AlertRulesId
:
"762ed641-6c0e-4c39-bf7c-7463abb0f8a2"
,
RiskLevel
:
3
,
AlertTime
:
now
,
ClassId
:
14
,
MetricConfigId
:
"d773b37b-dbb4-4a7b-be11-ab40f8acc00e"
,
CurrentValue
:
85
,
NotificationCount
:
1
,
PushCount
:
1
,
LastPushTime
:
now
,
Status
:
1
,
CreatedBy
:
"admin"
,
CreatedAt
:
now
,
UpdatedBy
:
"admin"
,
UpdatedAt
:
now
,
},
AlertCondition
:
entity
.
AlertCondition
{
ThresholdsMax
:
80
,
ThresholdsMin
:
50
,
RiskLevel
:
3
,
},
}
resp
.
List
=
append
(
resp
.
List
,
data1
,
data2
)
resp
.
TotalCount
=
int64
(
len
(
resp
.
List
))
return
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment