#############################################################################
# Copyright (c) 2015 Balabit
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 as published
# by the Free Software Foundation, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#
# As an additional exemption you are allowed to compile & link against the
# OpenSSL libraries as published by the OpenSSL project. See the file
# COPYING for details.
#
#############################################################################

@requires json-plugin

block destination elasticsearch2(
  index()
  type()
  template("$(format-json --scope rfc5424 --exclude DATE --key ISODATE @timestamp=${ISODATE})")
  port("")
  server("localhost")
  flush_limit("5000")
  flush_timeout("0")
  client_mode("node")
  cluster("")
  custom_id("")
  resource("")
  client_lib_dir("")
  concurrent_requests("1")
  skip_cluster_health_check("")
  cluster_url("")
  java_keystore_filepath("")
  java_keystore_password("")
  java_truststore_filepath("")
  java_truststore_password("")
  java_ssl_insecure("false")
  http_auth_type("none")
  http_auth_type_basic_username("")
  http_auth_type_basic_password("")
  time_zone("UTC")
  ...
)
{

@requires mod-java "The elasticsearch2() driver depends on the syslog-ng java module, please install the syslog-ng-mod-java (Debian & derivatives) or the syslog-ng-java (RHEL & co) package"


  java(
    class_path("`java-module-dir`/*.jar:`java-module-dir`/elastic-jest-client/*.jar:`client_lib_dir`/*.jar")
    class_name("org.syslog_ng.elasticsearch_v2.ElasticSearchDestination")
    option("index", `index`)
    option("type", `type`)
    option("server", `server`)
    option("port", "`port`")
    option("message-template", `template`)
    option("cluster", "`cluster`")
    option("flush_limit", `flush_limit`)
    option("flush_timeout", `flush_timeout`)
    option("client_mode", `client_mode`)
    option("resource", "`resource`")
    option("custom_id", "`custom_id`")
    option("concurrent_requests", `concurrent_requests`)
    option("skip_cluster_health_check", "`skip_cluster_health_check`")
    option("cluster_url", "`cluster_url`")
    option("java_keystore_filepath", "`java_keystore_filepath`")
    option("java_keystore_password", "`java_keystore_password`")
    option("java_truststore_filepath", "`java_truststore_filepath`")
    option("java_truststore_password", "`java_truststore_password`")
    option("java_ssl_insecure", `java_ssl_insecure`)
    option("http_auth_type", `http_auth_type`)
    option("http_auth_type_basic_username", "`http_auth_type_basic_username`")
    option("http_auth_type_basic_password", "`http_auth_type_basic_password`")
    time_zone(`time_zone`)
    `__VARARGS__`
  );
};
