From 975ac47f8e2cda610abd9f43ea6649d8a9d2fb11 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Thu, 8 Feb 2018 18:00:00 +0100 Subject: [PATCH 1/4] Fix Elastic 6 support fixes #5905 --- lib/perfdata/elasticsearchwriter.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/perfdata/elasticsearchwriter.cpp b/lib/perfdata/elasticsearchwriter.cpp index 87f299712..cf78264bb 100644 --- a/lib/perfdata/elasticsearchwriter.cpp +++ b/lib/perfdata/elasticsearchwriter.cpp @@ -357,7 +357,9 @@ void ElasticsearchWriter::Enqueue(const String& type, const Dictionary::Ptr& fie * We do it this way to avoid problems with a near full queue. */ - String indexBody = R"({ "index" : { "_type" : ")" + eventType + "\" } }\n"; + /* ES 6 removes multiple _type mappings: https://www.elastic.co/guide/en/elasticsearch/reference/6.x/removal-of-types.html + * We still need to send an index header. Best practice is to statically define 'doc'. */ + String indexBody = "{ \"index\" : { \"_type\": \"doc\" } }\n"; String fieldsBody = JsonEncode(fields); Log(LogDebug, "ElasticsearchWriter") From fd5d4c5974d60f4c45f20035108eaed537377ea3 Mon Sep 17 00:00:00 2001 From: Jean Flach Date: Fri, 6 Apr 2018 15:24:43 +0200 Subject: [PATCH 2/4] Move _type into url --- lib/perfdata/elasticsearchwriter.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/perfdata/elasticsearchwriter.cpp b/lib/perfdata/elasticsearchwriter.cpp index cf78264bb..531224e08 100644 --- a/lib/perfdata/elasticsearchwriter.cpp +++ b/lib/perfdata/elasticsearchwriter.cpp @@ -353,13 +353,10 @@ void ElasticsearchWriter::Enqueue(const String& type, const Dictionary::Ptr& fie String eventType = m_EventPrefix + type; fields->Set("type", eventType); - /* Every payload needs a line describing the index above. + /* Every payload needs a line describing the index. * We do it this way to avoid problems with a near full queue. */ - - /* ES 6 removes multiple _type mappings: https://www.elastic.co/guide/en/elasticsearch/reference/6.x/removal-of-types.html - * We still need to send an index header. Best practice is to statically define 'doc'. */ - String indexBody = "{ \"index\" : { \"_type\": \"doc\" } }\n"; + String indexBody = "{\"index\": {} }\n"; String fieldsBody = JsonEncode(fields); Log(LogDebug, "ElasticsearchWriter") @@ -421,6 +418,11 @@ void ElasticsearchWriter::SendRequest(const String& body) */ path.emplace_back(GetIndex() + "-" + Utility::FormatDateTime("%Y.%m.%d", Utility::GetTime())); + /* ES 6 removes multiple _type mappings: https://www.elastic.co/guide/en/elasticsearch/reference/6.x/removal-of-types.html + * Best practice is to statically define 'doc'. + */ + path.emplace_back("_doc"); + /* Use the bulk message format. */ path.emplace_back("_bulk"); From 1e0f67d7789ba6bce3485c10373a94bf134f5b58 Mon Sep 17 00:00:00 2001 From: Jean Flach Date: Wed, 11 Apr 2018 14:04:39 +0200 Subject: [PATCH 3/4] Fix ES 5 support --- lib/perfdata/elasticsearchwriter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/perfdata/elasticsearchwriter.cpp b/lib/perfdata/elasticsearchwriter.cpp index 531224e08..2e8ffa515 100644 --- a/lib/perfdata/elasticsearchwriter.cpp +++ b/lib/perfdata/elasticsearchwriter.cpp @@ -419,9 +419,9 @@ void ElasticsearchWriter::SendRequest(const String& body) path.emplace_back(GetIndex() + "-" + Utility::FormatDateTime("%Y.%m.%d", Utility::GetTime())); /* ES 6 removes multiple _type mappings: https://www.elastic.co/guide/en/elasticsearch/reference/6.x/removal-of-types.html - * Best practice is to statically define 'doc'. + * Best practice is to statically define 'doc', as ES 5.X does not allow types starting with '_'. */ - path.emplace_back("_doc"); + path.emplace_back("doc"); /* Use the bulk message format. */ path.emplace_back("_bulk"); From a7d563a2e9d7dce3baf4ec319ac81a943e65c093 Mon Sep 17 00:00:00 2001 From: Jean Flach Date: Wed, 11 Apr 2018 14:32:06 +0200 Subject: [PATCH 4/4] Update docs for ES 6 --- doc/14-features.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/14-features.md b/doc/14-features.md index 2ee09a06a..5e65cff00 100644 --- a/doc/14-features.md +++ b/doc/14-features.md @@ -403,7 +403,7 @@ The check results include parsed performance data metrics if enabled. > **Note** > -> Elasticsearch 5.x is required. This feature has been successfully tested with Elasticsearch 5.6.4. +> Elasticsearch 5.x or 6.x are required. This feature has been successfully tested with Elasticsearch 5.6.7 and 6.2.3. Enable the feature and restart Icinga 2. @@ -433,12 +433,12 @@ Metric values are stored like this: The following characters are escaped in perfdata labels: - Character | Escaped character - --------------|-------------------------- - whitespace | _ - \ | _ - / | _ - :: | . + Character | Escaped character + ------------|-------------------------- + whitespace | _ + \ | _ + / | _ + :: | . Note that perfdata labels may contain dots (`.`) allowing to add more subsequent levels inside the tree.