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
b6fcf2b6
Commit
b6fcf2b6
authored
Nov 22, 2017
by
Robin Burchell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
telegram: Switch to using multipart form rather than JSON as a body
This is a pre-requisite for uploading inline images.
parent
a1a9f339
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
11 deletions
+18
-11
pkg/services/alerting/notifiers/telegram.go
+18
-11
No files found.
pkg/services/alerting/notifiers/telegram.go
View file @
b6fcf2b6
package
notifiers
package
notifiers
import
(
import
(
"bytes"
"fmt"
"fmt"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/log"
m
"github.com/grafana/grafana/pkg/models"
m
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/alerting"
"mime/multipart"
)
)
var
(
var
(
...
@@ -84,11 +84,6 @@ func (this *TelegramNotifier) Notify(evalContext *alerting.EvalContext) error {
...
@@ -84,11 +84,6 @@ func (this *TelegramNotifier) Notify(evalContext *alerting.EvalContext) error {
this
.
log
.
Info
(
"Sending alert notification to"
,
"bot_token"
,
this
.
BotToken
)
this
.
log
.
Info
(
"Sending alert notification to"
,
"bot_token"
,
this
.
BotToken
)
this
.
log
.
Info
(
"Sending alert notification to"
,
"chat_id"
,
this
.
ChatID
)
this
.
log
.
Info
(
"Sending alert notification to"
,
"chat_id"
,
this
.
ChatID
)
bodyJSON
:=
simplejson
.
New
()
bodyJSON
.
Set
(
"chat_id"
,
this
.
ChatID
)
bodyJSON
.
Set
(
"parse_mode"
,
"html"
)
message
:=
fmt
.
Sprintf
(
"<b>%s</b>
\n
State: %s
\n
Message: %s
\n
"
,
evalContext
.
GetNotificationTitle
(),
evalContext
.
Rule
.
Name
,
evalContext
.
Rule
.
Message
)
message
:=
fmt
.
Sprintf
(
"<b>%s</b>
\n
State: %s
\n
Message: %s
\n
"
,
evalContext
.
GetNotificationTitle
(),
evalContext
.
Rule
.
Name
,
evalContext
.
Rule
.
Message
)
ruleUrl
,
err
:=
evalContext
.
GetRuleUrl
()
ruleUrl
,
err
:=
evalContext
.
GetRuleUrl
()
...
@@ -111,15 +106,27 @@ func (this *TelegramNotifier) Notify(evalContext *alerting.EvalContext) error {
...
@@ -111,15 +106,27 @@ func (this *TelegramNotifier) Notify(evalContext *alerting.EvalContext) error {
message
=
message
+
fmt
.
Sprintf
(
"
\n
<i>Metrics:</i>%s"
,
metrics
)
message
=
message
+
fmt
.
Sprintf
(
"
\n
<i>Metrics:</i>%s"
,
metrics
)
}
}
bodyJSON
.
Set
(
"text"
,
message
)
var
body
bytes
.
Buffer
w
:=
multipart
.
NewWriter
(
&
body
)
fw
,
_
:=
w
.
CreateFormField
(
"chat_id"
)
fw
.
Write
([]
byte
(
this
.
ChatID
))
url
:=
fmt
.
Sprintf
(
telegramApiUrl
,
this
.
BotToken
,
"sendMessag
e"
)
fw
,
_
=
w
.
CreateFormField
(
"parse_mod
e"
)
body
,
_
:=
bodyJSON
.
MarshalJSON
(
)
fw
.
Write
([]
byte
(
"html"
)
)
fw
,
_
=
w
.
CreateFormField
(
"text"
)
fw
.
Write
([]
byte
(
message
))
w
.
Close
()
url
:=
fmt
.
Sprintf
(
telegramApiUrl
,
this
.
BotToken
,
"sendMessage"
)
cmd
:=
&
m
.
SendWebhookSync
{
cmd
:=
&
m
.
SendWebhookSync
{
Url
:
url
,
Url
:
url
,
Body
:
string
(
body
),
Body
:
body
.
String
(
),
HttpMethod
:
"POST"
,
HttpMethod
:
"POST"
,
HttpHeader
:
map
[
string
]
string
{
"Content-Type"
:
w
.
FormDataContentType
(),
},
}
}
if
err
:=
bus
.
DispatchCtx
(
evalContext
.
Ctx
,
cmd
);
err
!=
nil
{
if
err
:=
bus
.
DispatchCtx
(
evalContext
.
Ctx
,
cmd
);
err
!=
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