Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
Nightingale
提交
87899cbe
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,发现更多精彩内容 >>
未验证
提交
87899cbe
编写于
2月 08, 2023
作者:
Y
Yening Qin
提交者:
GitHub
2月 08, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
compatible with alert rule older data structures (#1373)
* change alert rule
上级
d4257d11
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
76 addition
and
53 deletion
+76
-53
src/models/alert_rule.go
src/models/alert_rule.go
+76
-53
未找到文件。
src/models/alert_rule.go
浏览文件 @
87899cbe
...
...
@@ -14,47 +14,50 @@ import (
)
type
AlertRule
struct
{
Id
int64
`json:"id" gorm:"primaryKey"`
GroupId
int64
`json:"group_id"`
// busi group id
Cate
string
`json:"cate"`
// alert rule cate (prometheus|elasticsearch)
Cluster
string
`json:"cluster"`
// take effect by clusters, seperated by space
Name
string
`json:"name"`
// rule name
Note
string
`json:"note"`
// will sent in notify
Prod
string
`json:"prod"`
// product empty means n9e
Algorithm
string
`json:"algorithm"`
// algorithm (''|holtwinters), empty means threshold
AlgoParams
string
`json:"-" gorm:"algo_params"`
// params algorithm need
AlgoParamsJson
interface
{}
`json:"algo_params" gorm:"-"`
//
Delay
int
`json:"delay"`
// Time (in seconds) to delay evaluation
Severity
int
`json:"severity"`
// 1: Emergency 2: Warning 3: Notice
Disabled
int
`json:"disabled"`
// 0: enabled, 1: disabled
PromForDuration
int
`json:"prom_for_duration"`
// prometheus for, unit:s
PromQl
string
`json:"prom_ql"`
// just one ql
PromEvalInterval
int
`json:"prom_eval_interval"`
// unit:s
EnableStime
string
`json:"-"`
// split by space: "00:00 10:00 12:00"
EnableStimeJSON
[]
string
`json:"enable_stime" gorm:"-"`
// for fe
EnableEtime
string
`json:"-"`
// split by space: "00:00 10:00 12:00"
EnableEtimeJSON
[]
string
`json:"enable_etime" gorm:"-"`
// for fe
EnableDaysOfWeek
string
`json:"-"`
// eg: "0 1 2 3 4 5 6 ; 0 1 2"
EnableDaysOfWeekJSON
[][]
string
`json:"enable_days_of_week" gorm:"-"`
// for fe
EnableInBG
int
`json:"enable_in_bg"`
// 0: global 1: enable one busi-group
NotifyRecovered
int
`json:"notify_recovered"`
// whether notify when recovery
NotifyChannels
string
`json:"-"`
// split by space: sms voice email dingtalk wecom
NotifyChannelsJSON
[]
string
`json:"notify_channels" gorm:"-"`
// for fe
NotifyGroups
string
`json:"-"`
// split by space: 233 43
NotifyGroupsObj
[]
UserGroup
`json:"notify_groups_obj" gorm:"-"`
// for fe
NotifyGroupsJSON
[]
string
`json:"notify_groups" gorm:"-"`
// for fe
NotifyRepeatStep
int
`json:"notify_repeat_step"`
// notify repeat interval, unit: min
NotifyMaxNumber
int
`json:"notify_max_number"`
// notify: max number
RecoverDuration
int64
`json:"recover_duration"`
// unit: s
Callbacks
string
`json:"-"`
// split by space: http://a.com/api/x http://a.com/api/y'
CallbacksJSON
[]
string
`json:"callbacks" gorm:"-"`
// for fe
RunbookUrl
string
`json:"runbook_url"`
// sop url
AppendTags
string
`json:"-"`
// split by space: service=n9e mod=api
AppendTagsJSON
[]
string
`json:"append_tags" gorm:"-"`
// for fe
CreateAt
int64
`json:"create_at"`
CreateBy
string
`json:"create_by"`
UpdateAt
int64
`json:"update_at"`
UpdateBy
string
`json:"update_by"`
Id
int64
`json:"id" gorm:"primaryKey"`
GroupId
int64
`json:"group_id"`
// busi group id
Cate
string
`json:"cate"`
// alert rule cate (prometheus|elasticsearch)
Cluster
string
`json:"cluster"`
// take effect by clusters, seperated by space
Name
string
`json:"name"`
// rule name
Note
string
`json:"note"`
// will sent in notify
Prod
string
`json:"prod"`
// product empty means n9e
Algorithm
string
`json:"algorithm"`
// algorithm (''|holtwinters), empty means threshold
AlgoParams
string
`json:"-" gorm:"algo_params"`
// params algorithm need
AlgoParamsJson
interface
{}
`json:"algo_params" gorm:"-"`
//
Delay
int
`json:"delay"`
// Time (in seconds) to delay evaluation
Severity
int
`json:"severity"`
// 1: Emergency 2: Warning 3: Notice
Disabled
int
`json:"disabled"`
// 0: enabled, 1: disabled
PromForDuration
int
`json:"prom_for_duration"`
// prometheus for, unit:s
PromQl
string
`json:"prom_ql"`
// just one ql
PromEvalInterval
int
`json:"prom_eval_interval"`
// unit:s
EnableStime
string
`json:"-"`
// split by space: "00:00 10:00 12:00"
EnableStimeJSON
string
`json:"enable_stime" gorm:"-"`
// for fe
EnableStimesJSON
[]
string
`json:"enable_stimes" gorm:"-"`
// for fe
EnableEtime
string
`json:"-"`
// split by space: "00:00 10:00 12:00"
EnableEtimeJSON
string
`json:"enable_etime" gorm:"-"`
// for fe
EnableEtimesJSON
[]
string
`json:"enable_etimes" gorm:"-"`
// for fe
EnableDaysOfWeek
string
`json:"-"`
// eg: "0 1 2 3 4 5 6 ; 0 1 2"
EnableDaysOfWeekJSON
[]
string
`json:"enable_days_of_week" gorm:"-"`
// for fe
EnableDaysOfWeeksJSON
[][]
string
`json:"enable_days_of_weeks" gorm:"-"`
// for fe
EnableInBG
int
`json:"enable_in_bg"`
// 0: global 1: enable one busi-group
NotifyRecovered
int
`json:"notify_recovered"`
// whether notify when recovery
NotifyChannels
string
`json:"-"`
// split by space: sms voice email dingtalk wecom
NotifyChannelsJSON
[]
string
`json:"notify_channels" gorm:"-"`
// for fe
NotifyGroups
string
`json:"-"`
// split by space: 233 43
NotifyGroupsObj
[]
UserGroup
`json:"notify_groups_obj" gorm:"-"`
// for fe
NotifyGroupsJSON
[]
string
`json:"notify_groups" gorm:"-"`
// for fe
NotifyRepeatStep
int
`json:"notify_repeat_step"`
// notify repeat interval, unit: min
NotifyMaxNumber
int
`json:"notify_max_number"`
// notify: max number
RecoverDuration
int64
`json:"recover_duration"`
// unit: s
Callbacks
string
`json:"-"`
// split by space: http://a.com/api/x http://a.com/api/y'
CallbacksJSON
[]
string
`json:"callbacks" gorm:"-"`
// for fe
RunbookUrl
string
`json:"runbook_url"`
// sop url
AppendTags
string
`json:"-"`
// split by space: service=n9e mod=api
AppendTagsJSON
[]
string
`json:"append_tags" gorm:"-"`
// for fe
CreateAt
int64
`json:"create_at"`
CreateBy
string
`json:"create_by"`
UpdateAt
int64
`json:"update_at"`
UpdateBy
string
`json:"update_by"`
}
func
(
ar
*
AlertRule
)
TableName
()
string
{
...
...
@@ -226,19 +229,30 @@ func (ar *AlertRule) FillNotifyGroups(cache map[int64]*UserGroup) error {
}
func
(
ar
*
AlertRule
)
FE2DB
()
error
{
ar
.
EnableStime
=
strings
.
Join
(
ar
.
EnableStimeJSON
,
" "
)
ar
.
EnableEtime
=
strings
.
Join
(
ar
.
EnableEtimeJSON
,
" "
)
for
i
:=
0
;
i
<
len
(
ar
.
EnableDaysOfWeekJSON
);
i
++
{
if
len
(
ar
.
EnableDaysOfWeekJSON
)
==
1
{
ar
.
EnableDaysOfWeek
=
strings
.
Join
(
ar
.
EnableDaysOfWeekJSON
[
i
],
" "
)
}
else
{
if
i
==
len
(
ar
.
EnableDaysOfWeekJSON
)
-
1
{
ar
.
EnableDaysOfWeek
+=
strings
.
Join
(
ar
.
EnableDaysOfWeekJSON
[
i
],
" "
)
if
len
(
ar
.
EnableStimesJSON
)
>
0
{
ar
.
EnableStime
=
strings
.
Join
(
ar
.
EnableStimesJSON
,
" "
)
ar
.
EnableEtime
=
strings
.
Join
(
ar
.
EnableEtimesJSON
,
" "
)
}
else
{
ar
.
EnableStime
=
ar
.
EnableStimeJSON
ar
.
EnableEtime
=
ar
.
EnableEtimeJSON
}
if
len
(
ar
.
EnableDaysOfWeeksJSON
)
>
0
{
for
i
:=
0
;
i
<
len
(
ar
.
EnableDaysOfWeeksJSON
);
i
++
{
if
len
(
ar
.
EnableDaysOfWeeksJSON
)
==
1
{
ar
.
EnableDaysOfWeek
=
strings
.
Join
(
ar
.
EnableDaysOfWeeksJSON
[
i
],
" "
)
}
else
{
ar
.
EnableDaysOfWeek
+=
strings
.
Join
(
ar
.
EnableDaysOfWeekJSON
[
i
],
" "
)
+
";"
if
i
==
len
(
ar
.
EnableDaysOfWeeksJSON
)
-
1
{
ar
.
EnableDaysOfWeek
+=
strings
.
Join
(
ar
.
EnableDaysOfWeeksJSON
[
i
],
" "
)
}
else
{
ar
.
EnableDaysOfWeek
+=
strings
.
Join
(
ar
.
EnableDaysOfWeeksJSON
[
i
],
" "
)
+
";"
}
}
}
}
else
{
ar
.
EnableDaysOfWeek
=
strings
.
Join
(
ar
.
EnableDaysOfWeekJSON
,
" "
)
}
ar
.
NotifyChannels
=
strings
.
Join
(
ar
.
NotifyChannelsJSON
,
" "
)
ar
.
NotifyGroups
=
strings
.
Join
(
ar
.
NotifyGroupsJSON
,
" "
)
ar
.
Callbacks
=
strings
.
Join
(
ar
.
CallbacksJSON
,
" "
)
...
...
@@ -253,12 +267,21 @@ func (ar *AlertRule) FE2DB() error {
}
func
(
ar
*
AlertRule
)
DB2FE
()
{
ar
.
EnableStimeJSON
=
strings
.
Fields
(
ar
.
EnableStime
)
ar
.
EnableEtimeJSON
=
strings
.
Fields
(
ar
.
EnableEtime
)
ar
.
EnableStimesJSON
=
strings
.
Fields
(
ar
.
EnableStime
)
ar
.
EnableEtimesJSON
=
strings
.
Fields
(
ar
.
EnableEtime
)
if
len
(
ar
.
EnableEtimesJSON
)
>
0
{
ar
.
EnableStimeJSON
=
ar
.
EnableStimesJSON
[
0
]
ar
.
EnableEtimeJSON
=
ar
.
EnableEtimesJSON
[
0
]
}
cache
:=
strings
.
Split
(
ar
.
EnableDaysOfWeek
,
";"
)
for
i
:=
0
;
i
<
len
(
cache
);
i
++
{
ar
.
EnableDaysOfWeek
JSON
=
append
(
ar
.
EnableDaysOfWeek
JSON
,
strings
.
Fields
(
cache
[
i
]))
ar
.
EnableDaysOfWeek
sJSON
=
append
(
ar
.
EnableDaysOfWeeks
JSON
,
strings
.
Fields
(
cache
[
i
]))
}
if
len
(
ar
.
EnableDaysOfWeeksJSON
)
>
0
{
ar
.
EnableDaysOfWeekJSON
=
ar
.
EnableDaysOfWeeksJSON
[
0
]
}
ar
.
NotifyChannelsJSON
=
strings
.
Fields
(
ar
.
NotifyChannels
)
ar
.
NotifyGroupsJSON
=
strings
.
Fields
(
ar
.
NotifyGroups
)
ar
.
CallbacksJSON
=
strings
.
Fields
(
ar
.
Callbacks
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录