summaryrefslogtreecommitdiffstats
path: root/tests/es-writeoperation.sh
blob: 846f2f728fd5d7c8d9219f806cca2626c0291efb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/bash
# This file is part of the rsyslog project, released under ASL 2.0
. ${srcdir:=.}/diag.sh init
ensure_elasticsearch_ready
generate_conf
add_conf '
template(name="tpl" type="string"
	 string="{\"msgnum\":\"%msg:F,58:2%\"}")

module(load="../plugins/omelasticsearch/.libs/omelasticsearch")

if $msg contains "msgnum:" then
	action(type="omelasticsearch"
	       server="127.0.0.1"
	       serverport="19200"
	       template="tpl"
	       writeoperation="create"
	       searchIndex="rsyslog_testbench")

action(type="omfile" file=`echo $RSYSLOG_OUT_LOG`)
'

startup
injectmsg  0 1
shutdown_when_empty
wait_shutdown
if grep -q "omelasticsearch: writeoperation '1' requires bulkid"  $RSYSLOG_OUT_LOG ; then
	echo found correct error message
else
	echo Error: did not complain about incorrect writeoperation
	cat $RSYSLOG_OUT_LOG
	error_exit 1
fi

generate_conf
add_conf '
template(name="tpl" type="string"
	 string="{\"msgnum\":\"%msg:F,58:2%\"}")

module(load="../plugins/omelasticsearch/.libs/omelasticsearch")

if $msg contains "msgnum:" then
	action(type="omelasticsearch"
	       server="127.0.0.1"
	       serverport="19200"
	       template="tpl"
	       writeoperation="unknown"
	       searchIndex="rsyslog_testbench")

action(type="omfile" file=`echo $RSYSLOG_OUT_LOG`)
'

startup
injectmsg  0 1
shutdown_when_empty
wait_shutdown
if grep -q "omelasticsearch: invalid value 'unknown' for writeoperation"  $RSYSLOG_OUT_LOG ; then
	echo found correct error message
else
	echo Error: did not complain about incorrect writeoperation
	cat $RSYSLOG_OUT_LOG
	error_exit 1
fi

generate_conf
add_conf '
template(name="tpl" type="string"
	 string="{\"msgnum\":\"%msg:F,58:2%\"}")

module(load="../plugins/omelasticsearch/.libs/omelasticsearch")

template(name="id-template" type="list") { constant(value="123456789") }

if $msg contains "msgnum:" then
	action(type="omelasticsearch"
	       server="127.0.0.1"
	       serverport="19200"
	       template="tpl"
	       writeoperation="create"
	       bulkid="id-template"
	       dynbulkid="on"
	       bulkmode="on"
	       searchIndex="rsyslog_testbench")

action(type="omfile" file=`echo $RSYSLOG_OUT_LOG`)
'

init_elasticsearch

export QUEUE_EMPTY_CHECK_FUNC=es_shutdown_empty_check
export NUMMESSAGES=1
startup
injectmsg
shutdown_when_empty
wait_shutdown
es_getdata 1 $ES_PORT

$PYTHON <$RSYSLOG_DYNNAME.work -c '
import sys,json
hsh = json.load(sys.stdin)
try:
	if hsh["hits"]["hits"][0]["_id"] == "123456789":
		print("good - found expected value")
		sys.exit(0)
	print("Error: _id not expected value 123456789:", hsh["hits"]["hits"][0]["_id"])
	sys.exit(1)
except ValueError:
	print("Error: output is not valid:", json.dumps(hsh,indent=2))
	sys.exit(1)
'

if [ $? -eq 0 ] ; then
	echo found correct response
else
	cat $RSYSLOG_OUT_LOG
	error_exit 1
fi
exit_test