Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
f21c976b
Unverified
Commit
f21c976b
authored
Mar 06, 2019
by
Marcus Efraimsson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix discord notifier so it doesn't crash when there are no image generated
parent
8ba4eb47
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
29 deletions
+34
-29
pkg/services/alerting/notifiers/discord.go
+34
-29
No files found.
pkg/services/alerting/notifiers/discord.go
View file @
f21c976b
...
...
@@ -111,31 +111,52 @@ func (this *DiscordNotifier) Notify(evalContext *alerting.EvalContext) error {
json
,
_
:=
bodyJSON
.
MarshalJSON
()
c
ontent_type
:=
"application/json"
var
body
[]
byte
if
embeddedImage
{
c
md
:=
&
m
.
SendWebhookSync
{
Url
:
this
.
WebhookURL
,
HttpMethod
:
"POST"
,
ContentType
:
"application/json"
,
}
var
b
bytes
.
Buffer
if
!
embeddedImage
{
cmd
.
Body
=
string
(
json
)
}
else
{
err
:=
this
.
embedImage
(
cmd
,
evalContext
.
ImageOnDiskPath
,
json
)
if
err
!=
nil
{
this
.
log
.
Error
(
"failed to embed image"
,
"error"
,
err
)
return
err
}
}
w
:=
multipart
.
NewWriter
(
&
b
)
if
err
:=
bus
.
DispatchCtx
(
evalContext
.
Ctx
,
cmd
);
err
!=
nil
{
this
.
log
.
Error
(
"Failed to send notification to Discord"
,
"error"
,
err
)
return
err
}
f
,
err
:=
os
.
Open
(
evalContext
.
ImageOnDiskPath
)
return
nil
}
func
(
this
*
DiscordNotifier
)
embedImage
(
cmd
*
m
.
SendWebhookSync
,
imagePath
string
,
existingJSONBody
[]
byte
)
error
{
f
,
err
:=
os
.
Open
(
imagePath
)
defer
f
.
Close
()
if
err
!=
nil
{
this
.
log
.
Error
(
"Can't open graph file"
,
err
)
if
os
.
IsNotExist
(
err
)
{
cmd
.
Body
=
string
(
existingJSONBody
)
return
nil
}
if
!
os
.
IsNotExist
(
err
)
{
return
err
}
}
defer
f
.
Close
()
var
b
bytes
.
Buffer
w
:=
multipart
.
NewWriter
(
&
b
)
fw
,
err
:=
w
.
CreateFormField
(
"payload_json"
)
if
err
!=
nil
{
return
err
}
if
_
,
err
=
fw
.
Write
([]
byte
(
string
(
json
)));
err
!=
nil
{
if
_
,
err
=
fw
.
Write
([]
byte
(
string
(
existingJSONBody
)));
err
!=
nil
{
return
err
}
...
...
@@ -150,24 +171,8 @@ func (this *DiscordNotifier) Notify(evalContext *alerting.EvalContext) error {
w
.
Close
()
body
=
b
.
Bytes
()
content_type
=
w
.
FormDataContentType
()
}
else
{
body
=
json
}
cmd
:=
&
m
.
SendWebhookSync
{
Url
:
this
.
WebhookURL
,
Body
:
string
(
body
),
HttpMethod
:
"POST"
,
ContentType
:
content_type
,
}
if
err
:=
bus
.
DispatchCtx
(
evalContext
.
Ctx
,
cmd
);
err
!=
nil
{
this
.
log
.
Error
(
"Failed to send notification to Discord"
,
"error"
,
err
)
return
err
}
cmd
.
Body
=
string
(
b
.
Bytes
())
cmd
.
ContentType
=
w
.
FormDataContentType
()
return
nil
}
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