Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
L
logtransfer
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
谢宇轩
logtransfer
Commits
e3fe574e
Commit
e3fe574e
authored
Jan 29, 2023
by
李世星
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(修改模板文件): 202301291102
parent
a82297ee
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
12 deletions
+11
-12
message.go
ding/message.go
+10
-11
ding.go
plugin/ding.go
+1
-1
No files found.
ding/message.go
View file @
e3fe574e
...
@@ -11,9 +11,9 @@ import (
...
@@ -11,9 +11,9 @@ import (
const
(
const
(
MARKTYPE
=
"markdown"
MARKTYPE
=
"markdown"
TEXTTYPE
=
"text"
TEXTTYPE
=
"text"
OPEN_TEMPLE
=
"# 服务通知 已开启
\r\n
> 运行环境:
%s
\r\n
###### %s"
OPEN_TEMPLE
=
"# 服务通知 已开启
\r\n
> 运行环境:
\r\n
###### %s"
CLOSE_TEMPLE
=
"# 服务通知 已关闭
\r\n
> 运行环境:
%s
\r\n
###### %s"
CLOSE_TEMPLE
=
"# 服务通知 已关闭
\r\n
> 运行环境:
\r\n
###### %s"
STATUS_TEMPLE
=
"# 服务通知
\r\n
> 环境:
%s
\r\n
###### %s"
STATUS_TEMPLE
=
"# 服务通知
\r\n
> 环境:
\r\n
###### %s"
MESSAGE_TYPE_OPEN
=
"open"
MESSAGE_TYPE_OPEN
=
"open"
MESSAGE_TYPE_CLOSE
=
"close"
MESSAGE_TYPE_CLOSE
=
"close"
MESSAGE_TYPE_PLUGIN_NOTICE
=
"plugin"
MESSAGE_TYPE_PLUGIN_NOTICE
=
"plugin"
...
@@ -45,19 +45,19 @@ type DDMessage struct {
...
@@ -45,19 +45,19 @@ type DDMessage struct {
*
*
* @return string
* @return string
*/
*/
func
CreateDingMessage
(
dev
string
,
messageType
string
,
msg
interface
{},
mobiles
[]
string
)
DDMessage
{
func
CreateDingMessage
(
messageType
string
,
msg
interface
{},
mobiles
[]
string
)
DDMessage
{
var
message
DDMessage
var
message
DDMessage
message
.
MsgType
=
MARKTYPE
message
.
MsgType
=
MARKTYPE
message
.
Markdown
.
Title
=
"服务通知"
message
.
Markdown
.
Title
=
"服务通知"
switch
messageType
{
switch
messageType
{
case
MESSAGE_TYPE_OPEN
:
case
MESSAGE_TYPE_OPEN
:
message
.
Markdown
.
Text
=
fmt
.
Sprintf
(
OPEN_TEMPLE
,
dev
,
time
.
Now
()
.
Format
(
"2006/01/02 15:04:05"
))
message
.
Markdown
.
Text
=
fmt
.
Sprintf
(
OPEN_TEMPLE
,
time
.
Now
()
.
Format
(
"2006/01/02 15:04:05"
))
case
MESSAGE_TYPE_CLOSE
:
case
MESSAGE_TYPE_CLOSE
:
message
.
Markdown
.
Text
=
fmt
.
Sprintf
(
CLOSE_TEMPLE
,
dev
,
time
.
Now
()
.
Format
(
"2006/01/02 15:04:05"
))
message
.
Markdown
.
Text
=
fmt
.
Sprintf
(
CLOSE_TEMPLE
,
time
.
Now
()
.
Format
(
"2006/01/02 15:04:05"
))
case
MESSAGE_TYPE_PLUGIN_NOTICE
:
case
MESSAGE_TYPE_PLUGIN_NOTICE
:
message
.
Markdown
.
Text
=
pluginNotice
(
dev
,
msg
)
message
.
Markdown
.
Text
=
pluginNotice
(
msg
)
default
:
default
:
message
.
Markdown
.
Text
=
fmt
.
Sprintf
(
STATUS_TEMPLE
,
dev
,
time
.
Now
()
.
Format
(
"2006/01/02 15:04:05"
))
message
.
Markdown
.
Text
=
fmt
.
Sprintf
(
STATUS_TEMPLE
,
time
.
Now
()
.
Format
(
"2006/01/02 15:04:05"
))
}
}
if
len
(
mobiles
)
>
0
{
if
len
(
mobiles
)
>
0
{
...
@@ -71,11 +71,10 @@ func CreateDingMessage(dev string, messageType string, msg interface{}, mobiles
...
@@ -71,11 +71,10 @@ func CreateDingMessage(dev string, messageType string, msg interface{}, mobiles
return
message
return
message
}
}
func
pluginNotice
(
dev
string
,
msg
interface
{})
string
{
func
pluginNotice
(
msg
interface
{})
string
{
mateData
:=
msg
.
(
*
entity
.
Matedata
)
mateData
:=
msg
.
(
*
entity
.
Matedata
)
templateBuff
:=
bytes
.
NewBuffer
([]
byte
{})
templateBuff
:=
bytes
.
NewBuffer
([]
byte
{})
templateBuff
.
WriteString
(
fmt
.
Sprintf
(
"# 服务通知
\r\n
> 环境:%s"
,
dev
))
templateBuff
.
WriteString
(
fmt
.
Sprintf
(
"# 服务通知
\r\n
> [节点]:%s"
,
mateData
.
SourceAgent
))
templateBuff
.
WriteString
(
fmt
.
Sprintf
(
"
\r\n
> [节点]:%s"
,
mateData
.
SourceAgent
))
for
key
,
value
:=
range
mateData
.
Data
{
for
key
,
value
:=
range
mateData
.
Data
{
templateBuff
.
WriteString
(
fmt
.
Sprintf
(
"
\r\n
> [%s]:%s"
,
key
,
value
))
templateBuff
.
WriteString
(
fmt
.
Sprintf
(
"
\r\n
> [%s]:%s"
,
key
,
value
))
}
}
...
...
plugin/ding.go
View file @
e3fe574e
...
@@ -25,7 +25,7 @@ func (d *Ding) HandleFunc(m *entity.Matedata) error {
...
@@ -25,7 +25,7 @@ func (d *Ding) HandleFunc(m *entity.Matedata) error {
for
k
,
v
:=
range
(
*
m
)
.
Data
{
for
k
,
v
:=
range
(
*
m
)
.
Data
{
if
dingWebHook
!=
""
&&
k
==
searchKey
&&
(
searchValue
==
""
||
searchValue
==
v
)
{
if
dingWebHook
!=
""
&&
k
==
searchKey
&&
(
searchValue
==
""
||
searchValue
==
v
)
{
err
:=
ding
.
DingDingNotice
(
dingWebHook
,
context
.
Background
(),
ding
.
CreateDingMessage
(
"dev"
,
ding
.
MESSAGE_TYPE_PLUGIN_NOTICE
,
m
,
dingMobileData
))
err
:=
ding
.
DingDingNotice
(
dingWebHook
,
context
.
Background
(),
ding
.
CreateDingMessage
(
ding
.
MESSAGE_TYPE_PLUGIN_NOTICE
,
m
,
dingMobileData
))
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Println
(
err
)
log
.
Println
(
err
)
}
}
...
...
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