Add sourceInfo to NotificationEvent (#3937)

This change adds information like host, port and user-agent of the
client whose request triggered an event notification.

E.g, if someone uploads an object to a bucket using mc. If notifications
were configured on that bucket, the host, port and user-agent of mc
would be sent as part of event notification data.

Sample output:
```
"source": {
          "host": "127.0.0.1",
          "port": "55808",
          "userAgent": "Minio (linux; amd64) minio-go/2.0.4 mc ..."
}
```
This commit is contained in:
Krishnan Parthasarathi
2017-03-23 07:14:35 +05:30
committed by Harshavardhana
parent 7f5a5b5e9d
commit 607c8a9611
4 changed files with 79 additions and 1 deletions
+13 -1
View File
@@ -29,6 +29,10 @@ import (
"github.com/Sirupsen/logrus"
)
const (
minioEventSource = "minio:s3"
)
type externalNotifier struct {
// Per-bucket notification config. This is updated via
// PutBucketNotification API.
@@ -82,6 +86,9 @@ type eventData struct {
Bucket string
ObjInfo ObjectInfo
ReqParams map[string]string
Host string
Port string
UserAgent string
}
// New notification event constructs a new notification event message from
@@ -114,7 +121,7 @@ func newNotificationEvent(event eventData) NotificationEvent {
// http://docs.aws.amazon.com/AmazonS3/latest/dev/notification-content-structure.html
nEvent := NotificationEvent{
EventVersion: eventVersion,
EventSource: eventSource,
EventSource: minioEventSource,
AwsRegion: region,
EventTime: eventTime.Format(timeFormatAMZ),
EventName: event.Type.String(),
@@ -135,6 +142,11 @@ func newNotificationEvent(event eventData) NotificationEvent {
ARN: bucketARNPrefix + event.Bucket,
},
},
Source: sourceInfo{
Host: event.Host,
Port: event.Port,
UserAgent: event.UserAgent,
},
}
// Escape the object name. For example "red flower.jpg" becomes "red+flower.jpg".