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
122e2b5c
Commit
122e2b5c
authored
Oct 02, 2017
by
Matthew McGinn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
break out slack upload into separate function
parent
89ca4b24
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
15 deletions
+21
-15
pkg/services/alerting/notifiers/slack.go
+21
-15
No files found.
pkg/services/alerting/notifiers/slack.go
View file @
122e2b5c
...
...
@@ -163,29 +163,35 @@ func (this *SlackNotifier) Notify(evalContext *alerting.EvalContext) error {
return
err
}
if
this
.
Token
!=
""
{
slackUploadUrl
:=
"https://slack.com/api/files.upload"
if
evalContext
.
ImageOnDiskPath
==
""
{
evalContext
.
ImageOnDiskPath
=
"public/img/mixed_styles.png"
}
this
.
log
.
Info
(
"Uploading to slack via file.upload API"
)
headers
,
uploadBody
,
err
:=
GenerateSlackUpload
(
evalContext
.
ImageOnDiskPath
,
this
.
Token
,
this
.
Recipient
)
if
err
!=
nil
{
return
err
}
cmd
:=
&
m
.
SendWebhookSync
{
Url
:
slackUploadUrl
,
Body
:
uploadBody
.
String
(),
HttpHeader
:
headers
,
HttpMethod
:
"POST"
}
if
err
:=
bus
.
DispatchCtx
(
evalContext
.
Ctx
,
cmd
);
err
!=
nil
{
this
.
log
.
Error
(
"Failed to upload slack image"
,
"error"
,
err
,
"webhook"
,
"file.upload"
)
return
err
}
err
=
SlackFileUpload
(
evalContext
,
this
.
log
,
"https://slack.com/api/files.upload"
,
this
.
Recipient
,
this
.
Token
)
if
err
!=
nil
{
return
err
}
}
return
nil
}
func
SlackFileUpload
(
evalContext
*
alerting
.
EvalContext
,
log
log
.
Logger
,
url
string
,
recipient
string
,
token
string
)
error
{
if
evalContext
.
ImageOnDiskPath
==
""
{
evalContext
.
ImageOnDiskPath
=
"public/img/mixed_styles.png"
}
log
.
Info
(
"Uploading to slack via file.upload API"
)
headers
,
uploadBody
,
err
:=
GenerateSlackBody
(
evalContext
.
ImageOnDiskPath
,
token
,
recipient
)
if
err
!=
nil
{
return
err
}
cmd
:=
&
m
.
SendWebhookSync
{
Url
:
url
,
Body
:
uploadBody
.
String
(),
HttpHeader
:
headers
,
HttpMethod
:
"POST"
}
if
err
:=
bus
.
DispatchCtx
(
evalContext
.
Ctx
,
cmd
);
err
!=
nil
{
log
.
Error
(
"Failed to upload slack image"
,
"error"
,
err
,
"webhook"
,
"file.upload"
)
return
err
}
if
err
!=
nil
{
return
err
}
return
nil
}
func
GenerateSlack
Upload
(
file
string
,
token
string
,
recipient
string
)
(
map
[
string
]
string
,
bytes
.
Buffer
,
error
)
{
func
GenerateSlack
Body
(
file
string
,
token
string
,
recipient
string
)
(
map
[
string
]
string
,
bytes
.
Buffer
,
error
)
{
// Slack requires all POSTs to files.upload to present
// an "application/x-www-form-urlencoded" encoded querystring
// See https://api.slack.com/methods/files.upload
...
...
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