Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
Nightingale
提交
754ad160
N
Nightingale
项目概览
jobily
/
Nightingale
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
Nightingale
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
754ad160
编写于
8月 23, 2021
作者:
I
Istil
提交者:
GitHub
8月 23, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: support to deal with alert_event (#777)
上级
12e3b3a4
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
85 addition
and
17 deletion
+85
-17
http/router.go
http/router.go
+1
-0
http/router_alert_event.go
http/router_alert_event.go
+18
-0
models/alert_event.go
models/alert_event.go
+33
-0
models/history_alert_event.go
models/history_alert_event.go
+11
-0
sql/n9e.sql
sql/n9e.sql
+22
-17
未找到文件。
http/router.go
浏览文件 @
754ad160
...
...
@@ -159,6 +159,7 @@ func configRoutes(r *gin.Engine) {
pages
.
DELETE
(
"/alert-events"
,
login
(),
alertEventsDel
)
pages
.
GET
(
"/alert-event/:id"
,
login
(),
alertEventGet
)
pages
.
DELETE
(
"/alert-event/:id"
,
login
(),
alertEventDel
)
pages
.
PUT
(
"/alert-event/:id"
,
login
(),
alertEventNotePut
)
pages
.
GET
(
"/history-alert-events"
,
login
(),
historyAlertEventGets
)
pages
.
GET
(
"/history-alert-event/:id"
,
login
(),
historyAlertEventGet
)
...
...
http/router_alert_event.go
浏览文件 @
754ad160
package
http
import
(
"net/http"
"time"
"github.com/gin-gonic/gin"
...
...
@@ -54,6 +55,23 @@ func alertEventGet(c *gin.Context) {
renderData
(
c
,
ae
,
nil
)
}
type
alertEventNoteForm
struct
{
EventNote
string
`json:"event_note"`
}
func
alertEventNotePut
(
c
*
gin
.
Context
)
{
var
f
alertEventNoteForm
bind
(
c
,
&
f
)
me
:=
loginUser
(
c
)
.
MustPerm
(
"alert_event_modify"
)
ae
:=
AlertEvent
(
urlParamInt64
(
c
,
"id"
))
if
len
(
f
.
EventNote
)
==
0
{
bomb
(
http
.
StatusBadRequest
,
"event note is empty"
)
}
renderMessage
(
c
,
models
.
AlertEventUpdateEventNote
(
ae
.
Id
,
ae
.
HashId
,
f
.
EventNote
,
me
.
Id
))
}
func
alertEventDel
(
c
*
gin
.
Context
)
{
loginUser
(
c
)
.
MustPerm
(
"alert_event_delete"
)
renderMessage
(
c
,
AlertEvent
(
urlParamInt64
(
c
,
"id"
))
.
Del
())
...
...
models/alert_event.go
浏览文件 @
754ad160
...
...
@@ -17,6 +17,9 @@ type AlertEvent struct {
RuleId
int64
`json:"rule_id"`
RuleName
string
`json:"rule_name"`
RuleNote
string
`json:"rule_note"`
ProcessorUid
int64
`json:"processor_uid"`
ProcessorObjs
User
`json:"processor_user_objs" xorm:"-"`
EventNote
string
`json:"event_note"`
HashId
string
`json:"hash_id"`
// 唯一标识
IsPromePull
int
`json:"is_prome_pull"`
// 代表是否是prometheus pull告警,为1时前端使用 ReadableExpression 拉取最近1小时数据
LastSend
bool
`json:"last_sent" xorm:"-"`
// true 代表上次发了,false代表还没发:给prometheus做for判断的
...
...
@@ -114,6 +117,14 @@ func (ae *AlertEvent) FillObjs() error {
ae
.
NotifyUserObjs
=
users
}
if
ae
.
ProcessorUid
!=
0
{
processor
,
err
:=
UserGetById
(
ae
.
ProcessorUid
)
if
err
!=
nil
{
return
err
}
ae
.
ProcessorObjs
=
*
processor
}
return
nil
}
...
...
@@ -245,6 +256,7 @@ func AlertEventGets(stime, etime int64, query string, status, priority int, limi
func
AlertEventGet
(
where
string
,
args
...
interface
{})
(
*
AlertEvent
,
error
)
{
var
obj
AlertEvent
has
,
err
:=
DB
.
Where
(
where
,
args
...
)
.
Get
(
&
obj
)
if
err
!=
nil
{
logger
.
Errorf
(
"mysql.error: query alert_event(%s)%+v fail: %s"
,
where
,
args
,
err
)
return
nil
,
internalServerError
...
...
@@ -256,3 +268,24 @@ func AlertEventGet(where string, args ...interface{}) (*AlertEvent, error) {
return
&
obj
,
nil
}
func
AlertEventUpdateEventNote
(
id
int64
,
hashId
string
,
note
string
,
uid
int64
)
error
{
session
:=
DB
.
NewSession
()
defer
session
.
Close
()
if
err
:=
session
.
Begin
();
err
!=
nil
{
return
err
}
if
_
,
err
:=
session
.
Exec
(
"UPDATE alert_event SET event_note = ?, processor_uid = ? WHERE id = ?"
,
note
,
uid
,
id
);
err
!=
nil
{
logger
.
Errorf
(
"mysql.error: update alert_event event_note fail: %v"
,
err
)
return
err
}
if
_
,
err
:=
session
.
Exec
(
"UPDATE history_alert_event SET event_note = ?, processor_uid = ? WHERE hash_id = ?"
,
note
,
uid
,
hashId
);
err
!=
nil
{
logger
.
Errorf
(
"mysql.error: update history_alert_event event_note fail: %v"
,
err
)
return
err
}
return
session
.
Commit
()
}
models/history_alert_event.go
浏览文件 @
754ad160
...
...
@@ -15,6 +15,9 @@ type HistoryAlertEvent struct {
RuleId
int64
`json:"rule_id"`
RuleName
string
`json:"rule_name"`
RuleNote
string
`json:"rule_note"`
ProcessorUid
int64
`json:"processor_uid"`
ProcessorObjs
User
`json:"processor_user_objs" xorm:"-"`
EventNote
string
`json:"event_note"`
HashId
string
`json:"hash_id"`
// 唯一标识
IsPromePull
int
`json:"is_prome_pull"`
// 代表是否是prometheus pull告警,为1时前端使用 ReadableExpression 拉取最近1小时数据
ResClasspaths
string
`json:"res_classpaths"`
...
...
@@ -79,6 +82,14 @@ func (hae *HistoryAlertEvent) FillObjs() error {
hae
.
NotifyUserObjs
=
users
}
if
hae
.
ProcessorUid
!=
0
{
processor
,
err
:=
UserGetById
(
hae
.
ProcessorUid
)
if
err
!=
nil
{
return
err
}
hae
.
ProcessorObjs
=
*
processor
}
return
nil
}
...
...
sql/n9e.sql
浏览文件 @
754ad160
...
...
@@ -99,6 +99,7 @@ insert into `role_operation`(role_name, operation) values('Standard', 'alert_rul
insert
into
`role_operation`
(
role_name
,
operation
)
values
(
'Standard'
,
'alert_rule_modify'
);
insert
into
`role_operation`
(
role_name
,
operation
)
values
(
'Standard'
,
'alert_rule_delete'
);
insert
into
`role_operation`
(
role_name
,
operation
)
values
(
'Standard'
,
'alert_event_delete'
);
insert
into
`role_operation`
(
role_name
,
operation
)
values
(
'Standard'
,
'alert_event_modify'
);
insert
into
`role_operation`
(
role_name
,
operation
)
values
(
'Standard'
,
'collect_rule_create'
);
insert
into
`role_operation`
(
role_name
,
operation
)
values
(
'Standard'
,
'collect_rule_modify'
);
insert
into
`role_operation`
(
role_name
,
operation
)
values
(
'Standard'
,
'collect_rule_delete'
);
...
...
@@ -295,6 +296,8 @@ CREATE TABLE `alert_event` (
`rule_id`
bigint
unsigned
not
null
,
`rule_name`
varchar
(
255
)
not
null
,
`rule_note`
varchar
(
512
)
not
null
default
'alert rule note'
,
`processor_uid`
bigint
NOT
NULL
default
0
,
`event_note`
varchar
(
512
)
not
null
default
'alert event note'
,
`res_classpaths`
varchar
(
1024
)
not
null
default
''
comment
'belong classpaths'
,
`priority`
tinyint
(
1
)
not
null
,
`status`
tinyint
(
1
)
not
null
,
...
...
@@ -314,24 +317,26 @@ CREATE TABLE `alert_event` (
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
;
CREATE
TABLE
`history_alert_event`
(
`id`
bigint
unsigned
NOT
NULL
AUTO_INCREMENT
,
`hash_id`
varchar
(
255
)
NOT
NULL
COMMENT
'rule_id + point_pk'
,
`rule_id`
bigint
unsigned
NOT
NULL
,
`rule_name`
varchar
(
255
)
NOT
NULL
,
`rule_note`
varchar
(
512
)
NOT
NULL
DEFAULT
'alert rule note'
,
`res_classpaths`
varchar
(
1024
)
NOT
NULL
DEFAULT
''
COMMENT
'belong classpaths'
,
`priority`
tinyint
(
1
)
NOT
NULL
,
`status`
tinyint
(
1
)
NOT
NULL
,
`is_prome_pull`
tinyint
(
1
)
NOT
NULL
,
`is_recovery`
tinyint
(
1
)
NOT
NULL
,
`id`
bigint
unsigned
not
null
AUTO_INCREMENT
,
`hash_id`
varchar
(
255
)
not
null
COMMENT
'rule_id + point_pk'
,
`rule_id`
bigint
unsigned
not
null
,
`rule_name`
varchar
(
255
)
not
null
,
`rule_note`
varchar
(
512
)
not
null
default
'alert rule note'
,
`processor_uid`
bigint
not
null
default
0
,
`event_note`
varchar
(
512
)
not
null
default
'alert event note'
,
`res_classpaths`
varchar
(
1024
)
not
null
default
''
COMMENT
'belong classpaths'
,
`priority`
tinyint
(
1
)
not
null
,
`status`
tinyint
(
1
)
not
null
,
`is_prome_pull`
tinyint
(
1
)
not
null
,
`is_recovery`
tinyint
(
1
)
not
null
,
`history_points`
text
COMMENT
'metric, history points'
,
`trigger_time`
bigint
NOT
NULL
,
`notify_channels`
varchar
(
255
)
NOT
NULL
DEFAULT
''
,
`notify_groups`
varchar
(
255
)
NOT
NULL
DEFAULT
''
,
`notify_users`
varchar
(
255
)
NOT
NULL
DEFAULT
''
,
`runbook_url`
varchar
(
255
)
DEFAULT
NULL
,
`readable_expression`
varchar
(
1024
)
NOT
NULL
COMMENT
'e.g. mem.bytes.used.percent(all,60s) > 0'
,
`tags`
varchar
(
1024
)
NOT
NULL
DEFAULT
'merge data_tags rule_tags and res_tags'
,
`trigger_time`
bigint
not
null
,
`notify_channels`
varchar
(
255
)
not
null
default
''
,
`notify_groups`
varchar
(
255
)
not
null
default
''
,
`notify_users`
varchar
(
255
)
not
null
default
''
,
`runbook_url`
varchar
(
255
)
default
NULL
,
`readable_expression`
varchar
(
1024
)
not
null
COMMENT
'e.g. mem.bytes.used.percent(all,60s) > 0'
,
`tags`
varchar
(
1024
)
not
null
default
'merge data_tags rule_tags and res_tags'
,
PRIMARY
KEY
(
`id`
),
KEY
`hash_id`
(
`hash_id`
),
KEY
`rule_id`
(
`rule_id`
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录