1#!/bin/bash
2# This file is part of the rsyslog project, released under ASL 2.0
3. ${srcdir:=.}/diag.sh init
4export ES_DOWNLOAD=elasticsearch-6.0.0.tar.gz
5ensure_elasticsearch_ready
6
7init_elasticsearch
8curl -H 'Content-Type: application/json' -XPUT localhost:19200/rsyslog_testbench/ -d '{
9  "mappings": {
10    "test-type": {
11      "properties": {
12        "msgnum": {
13          "type": "integer"
14        }
15      }
16    }
17  }
18}'
19generate_conf
20add_conf '
21# Note: we must mess up with the template, because we can not
22# instruct ES to put further constraints on the data type and
23# values. So we require integer and make sure it is none.
24template(name="tpl" type="string"
25	 string="{\"msgnum\":\"x%msg:F,58:2%\"}")
26
27module(load="../plugins/omelasticsearch/.libs/omelasticsearch")
28:msg, contains, "msgnum:" action(type="omelasticsearch"
29				 template="tpl"
30				 searchIndex="rsyslog_testbench"
31				 searchType="test-type"
32				 serverport="19200"
33				 bulkmode="on"
34				 errorFile="./'${RSYSLOG_DYNNAME}'.errorfile")
35'
36startup
37injectmsg  0 1000
38shutdown_when_empty
39wait_shutdown
40if [ ! -f ${RSYSLOG_DYNNAME}.errorfile ]
41then
42    echo "error: error file does not exist!"
43    exit 1
44fi
45exit_test
46