-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Add input for receiving papertrail webhooks #2038
Conversation
4a0c9cd
to
9641507
Compare
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.
Looks good!
You may also update the root README.me and plugins/inputs/webhooks/README.md
to add a link to plugins/inputs/webhooks/papertrail/README.md
.
|
||
## Events | ||
|
||
See [here](http://help.papertrailapp.com/kb/how-it-works/web-hooks/#callback) for full documentation. |
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 prefer links without name here
. You could make the full sentence clickable, such as [See the full documentation](http://help.papertrailapp.com/kb/how-it-works/web-hooks/#callback)
.
Events from Papertrail come in two forms: | ||
|
||
* The event-based callback (shown in the example | ||
[here](http://help.papertrailapp.com/kb/how-it-works/web-hooks/#callback)): |
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.
Same here: shown in the example
clickable
@danielnelson can you take a look at this |
When an event is received, any point will look similar to: | ||
|
||
``` | ||
papertrail,host=myserver.example.com,event=saved_search_name count=3 1453248892 |
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.
Count should be an integer and the timestamp in nanoseconds
|
||
var payload Payload | ||
// JSON payload is x-www-form-urlencoded, remove this string when unmarshaling | ||
remove := "payload=" |
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.
Should do real unencoding in case the JSON has special escaped characters.
type Count struct { | ||
SourceName string `json:"source_name"` | ||
SourceID int64 `json:"source_id"` | ||
TimeSeries *map[int]int `json:"timeseries"` |
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.
int64?
payload := url.QueryEscape(sampleEventPayload) | ||
resp := postWebhooks(pt, payload) | ||
if resp.Code != http.StatusOK { | ||
t.Errorf("POST new_item returned HTTP status code %v.\nExpected %v", resp.Code, http.StatusOK) |
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.
Remove newlines in error
payload := url.QueryEscape(sampleCountPayload) | ||
resp := postWebhooks(pt, payload) | ||
if resp.Code != http.StatusOK { | ||
t.Errorf("POST new_item returned HTTP status code %v.\nExpected %v", resp.Code, http.StatusOK) |
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.
Remove newlines in error
9641507
to
2351e48
Compare
@francois2metz Would you like to take a second look at the updated code? |
} | ||
|
||
func (pt *PapertrailWebhook) eventHandler(w http.ResponseWriter, r *http.Request) { | ||
if r.Method != "POST" { |
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 don't know if this check is really needed. This handle is already restricted to the POST
method in the Register
function.
Looks good 👍 , don't forget to update all the readme involved when adding a new webhook: the root README.me and plugins/inputs/webhooks/README.md. |
2351e48
to
c5956b1
Compare
ac89667
to
d8f24ff
Compare
Required for all PRs: