Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DiDi
nightingale
提交
22ee99f2
N
nightingale
项目概览
DiDi
/
nightingale
9 个月 前同步成功
通知
45
Star
7053
Fork
1161
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
nightingale
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
22ee99f2
编写于
3月 19, 2021
作者:
U
UlricQin
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of
https://github.com/didi/nightingale
上级
f4675f0a
111c6fc1
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
38 addition
and
0 deletion
+38
-0
etc/rdb.yml
etc/rdb.yml
+4
-0
src/modules/rdb/config/yaml.go
src/modules/rdb/config/yaml.go
+6
-0
src/modules/rdb/http/router_node.go
src/modules/rdb/http/router_node.go
+28
-0
未找到文件。
etc/rdb.yml
浏览文件 @
22ee99f2
...
...
@@ -104,3 +104,7 @@ wechat:
corp_id
:
"
xxxxxxxxxxxxx"
agent_id
:
1000000
secret
:
"
xxxxxxxxxxxxxxxxx"
#webhook:
# - addr: http://localhost:2008/api/event
# token: "1234"
src/modules/rdb/config/yaml.go
浏览文件 @
22ee99f2
...
...
@@ -21,6 +21,12 @@ type ConfigT struct {
WeChat
wechatSection
`yaml:"wechat"`
I18n
i18n
.
I18nSection
`yaml:"i18n"`
Auth
authSection
`yaml:"auth"`
Webhook
[]
webhook
`yaml:"webhook"`
}
type
webhook
struct
{
Addr
string
`yaml:"addr"`
Token
string
`yaml:"token"`
}
type
authSection
struct
{
...
...
src/modules/rdb/http/router_node.go
浏览文件 @
22ee99f2
...
...
@@ -2,11 +2,15 @@ package http
import
(
"fmt"
"time"
"github.com/gin-gonic/gin"
"github.com/toolkits/pkg/logger"
"github.com/toolkits/pkg/net/httplib"
"github.com/toolkits/pkg/str"
"github.com/didi/nightingale/src/models"
"github.com/didi/nightingale/src/modules/rdb/config"
)
func
nodeGet
(
c
*
gin
.
Context
)
{
...
...
@@ -154,6 +158,7 @@ func nodePost(c *gin.Context) {
dangerous
(
models
.
NodeNew
(
node
,
f
.
AdminIds
))
go
models
.
OperationLogNew
(
me
.
Username
,
"node"
,
node
.
Id
,
fmt
.
Sprintf
(
"NodeCreate path: %s, name: %s"
,
node
.
Path
,
node
.
Name
))
go
nodeEvent
(
"create"
,
node
)
// 把节点详情返回,便于前端易用性处理
renderData
(
c
,
node
,
nil
)
...
...
@@ -175,6 +180,7 @@ func nodePost(c *gin.Context) {
child
,
err
:=
parent
.
CreateChild
(
f
.
Ident
,
f
.
Name
,
f
.
Note
,
f
.
Cate
,
me
.
Username
,
f
.
Leaf
,
f
.
Proxy
,
f
.
AdminIds
)
if
err
==
nil
{
go
models
.
OperationLogNew
(
me
.
Username
,
"node"
,
child
.
Id
,
fmt
.
Sprintf
(
"NodeCreate path: %s, name: %s"
,
child
.
Path
,
child
.
Name
))
go
nodeEvent
(
"create"
,
child
)
}
renderData
(
c
,
child
,
err
)
}
...
...
@@ -206,6 +212,7 @@ func nodePut(c *gin.Context) {
err
:=
node
.
Modify
(
f
.
Name
,
f
.
Cate
,
f
.
Note
,
f
.
AdminIds
)
go
models
.
OperationLogNew
(
me
.
Username
,
"node"
,
node
.
Id
,
fmt
.
Sprintf
(
"NodeModify path: %s, name: %s clientIP: %s"
,
node
.
Path
,
node
.
Name
,
c
.
ClientIP
()))
go
nodeEvent
(
"update"
,
node
)
renderData
(
c
,
node
,
err
)
}
...
...
@@ -217,5 +224,26 @@ func nodeDel(c *gin.Context) {
dangerous
(
node
.
Del
())
go
models
.
OperationLogNew
(
me
.
Username
,
"node"
,
node
.
Id
,
fmt
.
Sprintf
(
"NodeDelete path: %s, name: %s clientIP: %s"
,
node
.
Path
,
node
.
Name
,
c
.
ClientIP
()))
go
nodeEvent
(
"delete"
,
node
)
renderMessage
(
c
,
nil
)
}
type
eventEntity
struct
{
Action
string
`json:"action"`
Kind
string
`json:"kind"`
Data
interface
{}
`json:"data"`
}
func
nodeEvent
(
action
string
,
node
*
models
.
Node
)
{
for
_
,
backend
:=
range
config
.
Config
.
Webhook
{
header
:=
map
[
string
]
string
{}
if
backend
.
Token
!=
""
{
header
[
"Authorization"
]
=
"Bearer "
+
backend
.
Token
}
event
:=
&
eventEntity
{
Action
:
action
,
Kind
:
"node"
,
Data
:
node
}
res
,
code
,
err
:=
httplib
.
PostJSON
(
backend
.
Addr
,
3
*
time
.
Second
,
event
,
header
)
logger
.
Infof
(
"Webhook, api:%s, event:%+v, error:%v, response:%s, statuscode:%d"
,
backend
.
Addr
,
event
,
err
,
string
(
res
),
code
)
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录