-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix WeChat issue #1229
Fix WeChat issue #1229
Conversation
552bce8
to
0054ed5
Compare
notify/impl.go
Outdated
|
||
var accessToken string | ||
// Refresh AccessToken over 2 hours | ||
if n.accessToken != "" && time.Now().Sub(n.accessTokenAt) < 110*time.Minute { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can change 110*time.Minute
to 2*time.Hour
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be changed to
if n.accessToken == "" || time.Now().Sub(n.accessTokenAt) > 2*time.Hour {
// refresh token
// Set n.accessToken and n.AccessTokenAt
}
// Down below, use n.accessToken directly
notify/impl.go
Outdated
|
||
u.RawQuery = parameters.Encode() | ||
|
||
level.Debug(n.logger).Log("msg", "Sending Wechat message", "incident", key, "url", u.String()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Sending/sending/
There is an extra space between Wechat
and message
that can be removed.
notify/impl.go
Outdated
|
||
level.Debug(n.logger).Log("msg", "Sending Wechat message", "incident", key, "url", u.String()) | ||
|
||
resp, err := ctxhttp.Get(ctx, http.DefaultClient, u.String()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you replace this with
res, err := http.NewRequest("GET", u.String(), nil)
if err != nil {
return true, err
}
resp, err := http.DefaulClient.Do(req.WithContext(ctx))
I want to start removing the ctxhttp
library :)
notify/impl_test.go
Outdated
"io/ioutil" | ||
"net/url" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both "io/ioutil"
and "net/url"
should be in the first block of imports in this list, with the other stdlib imports.
Thanks for the contribution! Few easy changes and then this should be good to be merged |
demo to show: @stuartnelson3 review again please. |
5e20d85
to
0da153d
Compare
config/notifiers.go
Outdated
ToUser: `{{ template "wechat.default.to_user" . }}`, | ||
ToParty: `{{ template "wechat.default.to_party" . }}`, | ||
ToTag: `{{ template "wechat.default.to_tag" . }}`, | ||
AgentID: `{{ template "wechat.default.agent_id" . }}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why were all these fields removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these fields should be a determined value.
config/notifiers.go
Outdated
AgentID: `{{ template "wechat.default.agent_id" . }}`, | ||
// TODO: Add a details field with all the alerts. | ||
Message: `{{ template "wechat.default.message" . }}`, | ||
APIURL: DefaultGlobalConfig.WeChatAPIURL, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to leave this as a templated value for users. There is the check in https://github.com/prometheus/alertmanager/pull/1229/files#diff-3baf47c64847a8fb8aaa8cc2e088513bR250 that will set the api url to the global default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I will check it again.
fixed |
…theus#1229) Adds a new label called "type" systemd_unit_state which contains the Type field from the unit file. This applies only to the .service and .mount unit types. The other unit types do not include the optional type field. Fixes prometheus#1210 Signed-off-by: Paul Gier <[email protected]>
For issue #1218
Changes:
weChatCreateMessage
andweChatCloseMessage
toweChatMessage
accessTokenAt
Test config:
Work with this config.