2016-07-24 01:51:12 -04:00
|
|
|
/*
|
|
|
|
* Minio Cloud Storage, (C) 2016 Minio, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2016-08-18 19:23:42 -04:00
|
|
|
package cmd
|
2016-07-24 01:51:12 -04:00
|
|
|
|
|
|
|
import (
|
Add `access` format support for Elasticsearch notification target (#4006)
This change adds `access` format support for notifications to a
Elasticsearch server, and it refactors `namespace` format support.
In the case of `access` format, for each event in Minio, a JSON
document is inserted into Elasticsearch with its timestamp set to the
event's timestamp, and with the ID generated automatically by
elasticsearch. No events are modified or deleted in this mode.
In the case of `namespace` format, for each event in Minio, a JSON
document is keyed together by the bucket and object name is updated in
Elasticsearch. In the case of an object being created or over-written
in Minio, a new document or an existing document is inserted into the
Elasticsearch index. If an object is deleted in Minio, the
corresponding document is deleted from the Elasticsearch index.
Additionally, this change upgrades Elasticsearch support to the 5.x
series. This is a breaking change, and users of previous elasticsearch
versions should upgrade.
Also updates documentation on Elasticsearch notification target usage
and has a link to an elasticsearch upgrade guide.
This is the last patch that finally resolves #3928.
2017-03-31 17:11:27 -04:00
|
|
|
"context"
|
2017-03-27 14:27:25 -04:00
|
|
|
"fmt"
|
2016-08-05 01:01:58 -04:00
|
|
|
"io/ioutil"
|
Add `access` format support for Elasticsearch notification target (#4006)
This change adds `access` format support for notifications to a
Elasticsearch server, and it refactors `namespace` format support.
In the case of `access` format, for each event in Minio, a JSON
document is inserted into Elasticsearch with its timestamp set to the
event's timestamp, and with the ID generated automatically by
elasticsearch. No events are modified or deleted in this mode.
In the case of `namespace` format, for each event in Minio, a JSON
document is keyed together by the bucket and object name is updated in
Elasticsearch. In the case of an object being created or over-written
in Minio, a new document or an existing document is inserted into the
Elasticsearch index. If an object is deleted in Minio, the
corresponding document is deleted from the Elasticsearch index.
Additionally, this change upgrades Elasticsearch support to the 5.x
series. This is a breaking change, and users of previous elasticsearch
versions should upgrade.
Also updates documentation on Elasticsearch notification target usage
and has a link to an elasticsearch upgrade guide.
This is the last patch that finally resolves #3928.
2017-03-31 17:11:27 -04:00
|
|
|
"time"
|
2016-07-24 01:51:12 -04:00
|
|
|
|
|
|
|
"github.com/Sirupsen/logrus"
|
Add `access` format support for Elasticsearch notification target (#4006)
This change adds `access` format support for notifications to a
Elasticsearch server, and it refactors `namespace` format support.
In the case of `access` format, for each event in Minio, a JSON
document is inserted into Elasticsearch with its timestamp set to the
event's timestamp, and with the ID generated automatically by
elasticsearch. No events are modified or deleted in this mode.
In the case of `namespace` format, for each event in Minio, a JSON
document is keyed together by the bucket and object name is updated in
Elasticsearch. In the case of an object being created or over-written
in Minio, a new document or an existing document is inserted into the
Elasticsearch index. If an object is deleted in Minio, the
corresponding document is deleted from the Elasticsearch index.
Additionally, this change upgrades Elasticsearch support to the 5.x
series. This is a breaking change, and users of previous elasticsearch
versions should upgrade.
Also updates documentation on Elasticsearch notification target usage
and has a link to an elasticsearch upgrade guide.
This is the last patch that finally resolves #3928.
2017-03-31 17:11:27 -04:00
|
|
|
"gopkg.in/olivere/elastic.v5"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
esErrFunc = newNotificationErrorFactory("Elasticsearch")
|
|
|
|
|
|
|
|
errESFormat = esErrFunc(`"format" value is invalid - it must be one of "%s" or "%s".`, formatNamespace, formatAccess)
|
|
|
|
errESIndex = esErrFunc("Index name was not specified in the configuration.")
|
2016-07-24 01:51:12 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// elasticQueue is a elasticsearch event notification queue.
|
2016-08-05 01:01:58 -04:00
|
|
|
type elasticSearchNotify struct {
|
2016-07-24 01:51:12 -04:00
|
|
|
Enable bool `json:"enable"`
|
2017-03-27 14:27:25 -04:00
|
|
|
Format string `json:"format"`
|
2016-07-24 01:51:12 -04:00
|
|
|
URL string `json:"url"`
|
|
|
|
Index string `json:"index"`
|
|
|
|
}
|
|
|
|
|
2017-03-15 19:30:34 -04:00
|
|
|
func (e *elasticSearchNotify) Validate() error {
|
|
|
|
if !e.Enable {
|
|
|
|
return nil
|
|
|
|
}
|
Add `access` format support for Elasticsearch notification target (#4006)
This change adds `access` format support for notifications to a
Elasticsearch server, and it refactors `namespace` format support.
In the case of `access` format, for each event in Minio, a JSON
document is inserted into Elasticsearch with its timestamp set to the
event's timestamp, and with the ID generated automatically by
elasticsearch. No events are modified or deleted in this mode.
In the case of `namespace` format, for each event in Minio, a JSON
document is keyed together by the bucket and object name is updated in
Elasticsearch. In the case of an object being created or over-written
in Minio, a new document or an existing document is inserted into the
Elasticsearch index. If an object is deleted in Minio, the
corresponding document is deleted from the Elasticsearch index.
Additionally, this change upgrades Elasticsearch support to the 5.x
series. This is a breaking change, and users of previous elasticsearch
versions should upgrade.
Also updates documentation on Elasticsearch notification target usage
and has a link to an elasticsearch upgrade guide.
This is the last patch that finally resolves #3928.
2017-03-31 17:11:27 -04:00
|
|
|
if e.Format != formatNamespace && e.Format != formatAccess {
|
|
|
|
return errESFormat
|
2017-03-27 14:27:25 -04:00
|
|
|
}
|
2017-03-16 14:44:01 -04:00
|
|
|
if _, err := checkURL(e.URL); err != nil {
|
2017-03-15 19:30:34 -04:00
|
|
|
return err
|
|
|
|
}
|
Add `access` format support for Elasticsearch notification target (#4006)
This change adds `access` format support for notifications to a
Elasticsearch server, and it refactors `namespace` format support.
In the case of `access` format, for each event in Minio, a JSON
document is inserted into Elasticsearch with its timestamp set to the
event's timestamp, and with the ID generated automatically by
elasticsearch. No events are modified or deleted in this mode.
In the case of `namespace` format, for each event in Minio, a JSON
document is keyed together by the bucket and object name is updated in
Elasticsearch. In the case of an object being created or over-written
in Minio, a new document or an existing document is inserted into the
Elasticsearch index. If an object is deleted in Minio, the
corresponding document is deleted from the Elasticsearch index.
Additionally, this change upgrades Elasticsearch support to the 5.x
series. This is a breaking change, and users of previous elasticsearch
versions should upgrade.
Also updates documentation on Elasticsearch notification target usage
and has a link to an elasticsearch upgrade guide.
This is the last patch that finally resolves #3928.
2017-03-31 17:11:27 -04:00
|
|
|
if e.Index == "" {
|
|
|
|
return errESIndex
|
|
|
|
}
|
2017-03-15 19:30:34 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-07-24 01:51:12 -04:00
|
|
|
type elasticClient struct {
|
|
|
|
*elastic.Client
|
2016-08-05 01:01:58 -04:00
|
|
|
params elasticSearchNotify
|
2016-07-24 01:51:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Connects to elastic search instance at URL.
|
2016-08-05 01:01:58 -04:00
|
|
|
func dialElastic(esNotify elasticSearchNotify) (*elastic.Client, error) {
|
|
|
|
if !esNotify.Enable {
|
|
|
|
return nil, errNotifyNotEnabled
|
2016-07-25 20:53:55 -04:00
|
|
|
}
|
Add `access` format support for Elasticsearch notification target (#4006)
This change adds `access` format support for notifications to a
Elasticsearch server, and it refactors `namespace` format support.
In the case of `access` format, for each event in Minio, a JSON
document is inserted into Elasticsearch with its timestamp set to the
event's timestamp, and with the ID generated automatically by
elasticsearch. No events are modified or deleted in this mode.
In the case of `namespace` format, for each event in Minio, a JSON
document is keyed together by the bucket and object name is updated in
Elasticsearch. In the case of an object being created or over-written
in Minio, a new document or an existing document is inserted into the
Elasticsearch index. If an object is deleted in Minio, the
corresponding document is deleted from the Elasticsearch index.
Additionally, this change upgrades Elasticsearch support to the 5.x
series. This is a breaking change, and users of previous elasticsearch
versions should upgrade.
Also updates documentation on Elasticsearch notification target usage
and has a link to an elasticsearch upgrade guide.
This is the last patch that finally resolves #3928.
2017-03-31 17:11:27 -04:00
|
|
|
return elastic.NewClient(
|
2016-09-20 19:36:18 -04:00
|
|
|
elastic.SetURL(esNotify.URL),
|
|
|
|
elastic.SetSniff(false),
|
|
|
|
elastic.SetMaxRetries(10),
|
|
|
|
)
|
2016-07-24 01:51:12 -04:00
|
|
|
}
|
|
|
|
|
2016-08-05 01:01:58 -04:00
|
|
|
func newElasticNotify(accountID string) (*logrus.Logger, error) {
|
2017-02-09 18:20:54 -05:00
|
|
|
esNotify := serverConfig.Notify.GetElasticSearchByID(accountID)
|
2016-07-25 20:53:55 -04:00
|
|
|
|
|
|
|
// Dial to elastic search.
|
2016-08-05 01:01:58 -04:00
|
|
|
client, err := dialElastic(esNotify)
|
2016-07-24 01:51:12 -04:00
|
|
|
if err != nil {
|
Add `access` format support for Elasticsearch notification target (#4006)
This change adds `access` format support for notifications to a
Elasticsearch server, and it refactors `namespace` format support.
In the case of `access` format, for each event in Minio, a JSON
document is inserted into Elasticsearch with its timestamp set to the
event's timestamp, and with the ID generated automatically by
elasticsearch. No events are modified or deleted in this mode.
In the case of `namespace` format, for each event in Minio, a JSON
document is keyed together by the bucket and object name is updated in
Elasticsearch. In the case of an object being created or over-written
in Minio, a new document or an existing document is inserted into the
Elasticsearch index. If an object is deleted in Minio, the
corresponding document is deleted from the Elasticsearch index.
Additionally, this change upgrades Elasticsearch support to the 5.x
series. This is a breaking change, and users of previous elasticsearch
versions should upgrade.
Also updates documentation on Elasticsearch notification target usage
and has a link to an elasticsearch upgrade guide.
This is the last patch that finally resolves #3928.
2017-03-31 17:11:27 -04:00
|
|
|
return nil, esErrFunc("Error dialing the server: %v", err)
|
2016-07-24 01:51:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Use the IndexExists service to check if a specified index exists.
|
Add `access` format support for Elasticsearch notification target (#4006)
This change adds `access` format support for notifications to a
Elasticsearch server, and it refactors `namespace` format support.
In the case of `access` format, for each event in Minio, a JSON
document is inserted into Elasticsearch with its timestamp set to the
event's timestamp, and with the ID generated automatically by
elasticsearch. No events are modified or deleted in this mode.
In the case of `namespace` format, for each event in Minio, a JSON
document is keyed together by the bucket and object name is updated in
Elasticsearch. In the case of an object being created or over-written
in Minio, a new document or an existing document is inserted into the
Elasticsearch index. If an object is deleted in Minio, the
corresponding document is deleted from the Elasticsearch index.
Additionally, this change upgrades Elasticsearch support to the 5.x
series. This is a breaking change, and users of previous elasticsearch
versions should upgrade.
Also updates documentation on Elasticsearch notification target usage
and has a link to an elasticsearch upgrade guide.
This is the last patch that finally resolves #3928.
2017-03-31 17:11:27 -04:00
|
|
|
exists, err := client.IndexExists(esNotify.Index).
|
|
|
|
Do(context.Background())
|
2016-07-24 01:51:12 -04:00
|
|
|
if err != nil {
|
Add `access` format support for Elasticsearch notification target (#4006)
This change adds `access` format support for notifications to a
Elasticsearch server, and it refactors `namespace` format support.
In the case of `access` format, for each event in Minio, a JSON
document is inserted into Elasticsearch with its timestamp set to the
event's timestamp, and with the ID generated automatically by
elasticsearch. No events are modified or deleted in this mode.
In the case of `namespace` format, for each event in Minio, a JSON
document is keyed together by the bucket and object name is updated in
Elasticsearch. In the case of an object being created or over-written
in Minio, a new document or an existing document is inserted into the
Elasticsearch index. If an object is deleted in Minio, the
corresponding document is deleted from the Elasticsearch index.
Additionally, this change upgrades Elasticsearch support to the 5.x
series. This is a breaking change, and users of previous elasticsearch
versions should upgrade.
Also updates documentation on Elasticsearch notification target usage
and has a link to an elasticsearch upgrade guide.
This is the last patch that finally resolves #3928.
2017-03-31 17:11:27 -04:00
|
|
|
return nil, esErrFunc("Error checking if index exists: %v", err)
|
2016-07-24 01:51:12 -04:00
|
|
|
}
|
|
|
|
// Index does not exist, attempt to create it.
|
|
|
|
if !exists {
|
|
|
|
var createIndex *elastic.IndicesCreateResult
|
Add `access` format support for Elasticsearch notification target (#4006)
This change adds `access` format support for notifications to a
Elasticsearch server, and it refactors `namespace` format support.
In the case of `access` format, for each event in Minio, a JSON
document is inserted into Elasticsearch with its timestamp set to the
event's timestamp, and with the ID generated automatically by
elasticsearch. No events are modified or deleted in this mode.
In the case of `namespace` format, for each event in Minio, a JSON
document is keyed together by the bucket and object name is updated in
Elasticsearch. In the case of an object being created or over-written
in Minio, a new document or an existing document is inserted into the
Elasticsearch index. If an object is deleted in Minio, the
corresponding document is deleted from the Elasticsearch index.
Additionally, this change upgrades Elasticsearch support to the 5.x
series. This is a breaking change, and users of previous elasticsearch
versions should upgrade.
Also updates documentation on Elasticsearch notification target usage
and has a link to an elasticsearch upgrade guide.
This is the last patch that finally resolves #3928.
2017-03-31 17:11:27 -04:00
|
|
|
createIndex, err = client.CreateIndex(esNotify.Index).
|
|
|
|
Do(context.Background())
|
2016-07-24 01:51:12 -04:00
|
|
|
if err != nil {
|
Add `access` format support for Elasticsearch notification target (#4006)
This change adds `access` format support for notifications to a
Elasticsearch server, and it refactors `namespace` format support.
In the case of `access` format, for each event in Minio, a JSON
document is inserted into Elasticsearch with its timestamp set to the
event's timestamp, and with the ID generated automatically by
elasticsearch. No events are modified or deleted in this mode.
In the case of `namespace` format, for each event in Minio, a JSON
document is keyed together by the bucket and object name is updated in
Elasticsearch. In the case of an object being created or over-written
in Minio, a new document or an existing document is inserted into the
Elasticsearch index. If an object is deleted in Minio, the
corresponding document is deleted from the Elasticsearch index.
Additionally, this change upgrades Elasticsearch support to the 5.x
series. This is a breaking change, and users of previous elasticsearch
versions should upgrade.
Also updates documentation on Elasticsearch notification target usage
and has a link to an elasticsearch upgrade guide.
This is the last patch that finally resolves #3928.
2017-03-31 17:11:27 -04:00
|
|
|
return nil, esErrFunc("Error creating index `%s`: %v",
|
|
|
|
esNotify.Index, err)
|
2016-07-24 01:51:12 -04:00
|
|
|
}
|
|
|
|
if !createIndex.Acknowledged {
|
Add `access` format support for Elasticsearch notification target (#4006)
This change adds `access` format support for notifications to a
Elasticsearch server, and it refactors `namespace` format support.
In the case of `access` format, for each event in Minio, a JSON
document is inserted into Elasticsearch with its timestamp set to the
event's timestamp, and with the ID generated automatically by
elasticsearch. No events are modified or deleted in this mode.
In the case of `namespace` format, for each event in Minio, a JSON
document is keyed together by the bucket and object name is updated in
Elasticsearch. In the case of an object being created or over-written
in Minio, a new document or an existing document is inserted into the
Elasticsearch index. If an object is deleted in Minio, the
corresponding document is deleted from the Elasticsearch index.
Additionally, this change upgrades Elasticsearch support to the 5.x
series. This is a breaking change, and users of previous elasticsearch
versions should upgrade.
Also updates documentation on Elasticsearch notification target usage
and has a link to an elasticsearch upgrade guide.
This is the last patch that finally resolves #3928.
2017-03-31 17:11:27 -04:00
|
|
|
return nil, esErrFunc("Index not created")
|
2016-07-24 01:51:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
elasticCl := elasticClient{
|
|
|
|
Client: client,
|
2016-08-05 01:01:58 -04:00
|
|
|
params: esNotify,
|
2016-07-24 01:51:12 -04:00
|
|
|
}
|
|
|
|
|
2016-08-05 01:01:58 -04:00
|
|
|
elasticSearchLog := logrus.New()
|
2016-07-24 01:51:12 -04:00
|
|
|
|
2016-08-05 01:01:58 -04:00
|
|
|
// Disable writing to console.
|
|
|
|
elasticSearchLog.Out = ioutil.Discard
|
2016-07-24 01:51:12 -04:00
|
|
|
|
2016-08-05 01:01:58 -04:00
|
|
|
// Add a elasticSearch hook.
|
|
|
|
elasticSearchLog.Hooks.Add(elasticCl)
|
2016-07-24 01:51:12 -04:00
|
|
|
|
2016-08-05 01:01:58 -04:00
|
|
|
// Set default JSON formatter.
|
|
|
|
elasticSearchLog.Formatter = new(logrus.JSONFormatter)
|
2016-07-24 01:51:12 -04:00
|
|
|
|
2016-08-05 01:01:58 -04:00
|
|
|
// Success, elastic search successfully initialized.
|
|
|
|
return elasticSearchLog, nil
|
2016-07-24 01:51:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fire is required to implement logrus hook
|
Add `access` format support for Elasticsearch notification target (#4006)
This change adds `access` format support for notifications to a
Elasticsearch server, and it refactors `namespace` format support.
In the case of `access` format, for each event in Minio, a JSON
document is inserted into Elasticsearch with its timestamp set to the
event's timestamp, and with the ID generated automatically by
elasticsearch. No events are modified or deleted in this mode.
In the case of `namespace` format, for each event in Minio, a JSON
document is keyed together by the bucket and object name is updated in
Elasticsearch. In the case of an object being created or over-written
in Minio, a new document or an existing document is inserted into the
Elasticsearch index. If an object is deleted in Minio, the
corresponding document is deleted from the Elasticsearch index.
Additionally, this change upgrades Elasticsearch support to the 5.x
series. This is a breaking change, and users of previous elasticsearch
versions should upgrade.
Also updates documentation on Elasticsearch notification target usage
and has a link to an elasticsearch upgrade guide.
This is the last patch that finally resolves #3928.
2017-03-31 17:11:27 -04:00
|
|
|
func (q elasticClient) Fire(entry *logrus.Entry) (err error) {
|
2016-09-20 05:11:17 -04:00
|
|
|
// Reflect on eventType and Key on their native type.
|
|
|
|
entryStr, ok := entry.Data["EventType"].(string)
|
|
|
|
if !ok {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
keyStr, ok := entry.Data["Key"].(string)
|
|
|
|
if !ok {
|
|
|
|
return nil
|
|
|
|
}
|
2016-07-24 01:51:12 -04:00
|
|
|
|
Add `access` format support for Elasticsearch notification target (#4006)
This change adds `access` format support for notifications to a
Elasticsearch server, and it refactors `namespace` format support.
In the case of `access` format, for each event in Minio, a JSON
document is inserted into Elasticsearch with its timestamp set to the
event's timestamp, and with the ID generated automatically by
elasticsearch. No events are modified or deleted in this mode.
In the case of `namespace` format, for each event in Minio, a JSON
document is keyed together by the bucket and object name is updated in
Elasticsearch. In the case of an object being created or over-written
in Minio, a new document or an existing document is inserted into the
Elasticsearch index. If an object is deleted in Minio, the
corresponding document is deleted from the Elasticsearch index.
Additionally, this change upgrades Elasticsearch support to the 5.x
series. This is a breaking change, and users of previous elasticsearch
versions should upgrade.
Also updates documentation on Elasticsearch notification target usage
and has a link to an elasticsearch upgrade guide.
This is the last patch that finally resolves #3928.
2017-03-31 17:11:27 -04:00
|
|
|
switch q.params.Format {
|
|
|
|
case formatNamespace:
|
|
|
|
// If event matches as delete, we purge the previous index.
|
|
|
|
if eventMatch(entryStr, []string{"s3:ObjectRemoved:*"}) {
|
|
|
|
_, err = q.Client.Delete().Index(q.params.Index).
|
|
|
|
Type("event").Id(keyStr).Do(context.Background())
|
|
|
|
break
|
|
|
|
} // else we update elastic index or create a new one.
|
|
|
|
_, err = q.Client.Index().Index(q.params.Index).
|
|
|
|
Type("event").
|
|
|
|
BodyJson(map[string]interface{}{
|
|
|
|
"Records": entry.Data["Records"],
|
|
|
|
}).Id(keyStr).Do(context.Background())
|
|
|
|
case formatAccess:
|
|
|
|
// eventTime is taken from the first entry in the
|
|
|
|
// records.
|
|
|
|
events, ok := entry.Data["Records"].([]NotificationEvent)
|
|
|
|
if !ok {
|
|
|
|
return esErrFunc("Unable to extract event time due to conversion error of entry.Data[\"Records\"]=%v", entry.Data["Records"])
|
|
|
|
}
|
|
|
|
var eventTime time.Time
|
|
|
|
eventTime, err = time.Parse(timeFormatAMZ, events[0].EventTime)
|
2016-09-20 05:11:17 -04:00
|
|
|
if err != nil {
|
Add `access` format support for Elasticsearch notification target (#4006)
This change adds `access` format support for notifications to a
Elasticsearch server, and it refactors `namespace` format support.
In the case of `access` format, for each event in Minio, a JSON
document is inserted into Elasticsearch with its timestamp set to the
event's timestamp, and with the ID generated automatically by
elasticsearch. No events are modified or deleted in this mode.
In the case of `namespace` format, for each event in Minio, a JSON
document is keyed together by the bucket and object name is updated in
Elasticsearch. In the case of an object being created or over-written
in Minio, a new document or an existing document is inserted into the
Elasticsearch index. If an object is deleted in Minio, the
corresponding document is deleted from the Elasticsearch index.
Additionally, this change upgrades Elasticsearch support to the 5.x
series. This is a breaking change, and users of previous elasticsearch
versions should upgrade.
Also updates documentation on Elasticsearch notification target usage
and has a link to an elasticsearch upgrade guide.
This is the last patch that finally resolves #3928.
2017-03-31 17:11:27 -04:00
|
|
|
return esErrFunc("Unable to parse event time \"%s\": %v",
|
|
|
|
events[0].EventTime, err)
|
2016-09-20 05:11:17 -04:00
|
|
|
}
|
Add `access` format support for Elasticsearch notification target (#4006)
This change adds `access` format support for notifications to a
Elasticsearch server, and it refactors `namespace` format support.
In the case of `access` format, for each event in Minio, a JSON
document is inserted into Elasticsearch with its timestamp set to the
event's timestamp, and with the ID generated automatically by
elasticsearch. No events are modified or deleted in this mode.
In the case of `namespace` format, for each event in Minio, a JSON
document is keyed together by the bucket and object name is updated in
Elasticsearch. In the case of an object being created or over-written
in Minio, a new document or an existing document is inserted into the
Elasticsearch index. If an object is deleted in Minio, the
corresponding document is deleted from the Elasticsearch index.
Additionally, this change upgrades Elasticsearch support to the 5.x
series. This is a breaking change, and users of previous elasticsearch
versions should upgrade.
Also updates documentation on Elasticsearch notification target usage
and has a link to an elasticsearch upgrade guide.
This is the last patch that finally resolves #3928.
2017-03-31 17:11:27 -04:00
|
|
|
// Extract event time in milliseconds for Elasticsearch.
|
|
|
|
eventTimeStr := fmt.Sprintf("%d", eventTime.UnixNano()/1000000)
|
|
|
|
_, err = q.Client.Index().Index(q.params.Index).Type("event").
|
|
|
|
Timestamp(eventTimeStr).
|
|
|
|
BodyJson(map[string]interface{}{
|
|
|
|
"Records": entry.Data["Records"],
|
|
|
|
}).Do(context.Background())
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return esErrFunc("Error inserting/deleting entry: %v", err)
|
|
|
|
}
|
|
|
|
return nil
|
2016-07-24 01:51:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Required for logrus hook implementation
|
|
|
|
func (q elasticClient) Levels() []logrus.Level {
|
|
|
|
return []logrus.Level{
|
|
|
|
logrus.InfoLevel,
|
|
|
|
}
|
|
|
|
}
|