Code

b2e6ed82a644074cb3745b58b3d45e388a471313
[sysdb.git] / t / integration / query.sh
1 #! /bin/bash
2 #
3 # SysDB -- t/integration/basic_query.sh
4 # Copyright (C) 2012 Sebastian 'tokkee' Harl <sh@tokkee.org>
5 # All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 # 1. Redistributions of source code must retain the above copyright
11 #    notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 #    notice, this list of conditions and the following disclaimer in the
14 #    documentation and/or other materials provided with the distribution.
15 #
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
20 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #
29 # Integration tests using basic queries.
30 #
32 set -ex
34 source "$( dirname "$0" )/test_lib.sh"
36 cat <<EOF > "$SYSDBD_CONF"
37 Listen "$SOCKET_FILE"
38 PluginDir "$PLUGIN_DIR"
39 Interval 2
41 LoadBackend mock_plugin
42 <Backend "mock_plugin">
43 </Backend>
44 EOF
46 run_sysdbd -D -C "$SYSDBD_CONF"
48 wait_for_sysdbd
49 sleep 3
51 # Invalid user.
52 output="$( run_sysdb_nouser -H "$SOCKET_FILE" \
53   -U $SYSDB_USER-invalid -c 'LIST hosts' 2>&1 )" && exit 1
54 echo "$output" | grep -F 'Access denied'
56 # On parse errors, expect a non-zero exit code.
57 output="$( run_sysdb -H "$SOCKET_FILE" -c INVALID 2>&1 )" && exit 1
58 echo "$output" | grep "Failed to parse query 'INVALID'"
59 echo "$output" | grep "parse error: syntax error"
61 # Simple, successful commands.
62 output="$( run_sysdb -H "$SOCKET_FILE" -c 'LIST hosts' )"
63 echo "$output" \
64         | grep -F '"host1.example.com"' \
65         | grep -F '"host2.example.com"' \
66         | grep -F '"localhost"' \
67         | grep -F '"other.host.name"' \
68         | grep -F '"some.host.name"'
70 output="$( echo 'LIST hosts;' | run_sysdb -H "$SOCKET_FILE" )" || echo $?
71 echo "$output" \
72         | grep -F '"host1.example.com"' \
73         | grep -F '"host2.example.com"' \
74         | grep -F '"localhost"' \
75         | grep -F '"other.host.name"' \
76         | grep -F '"some.host.name"'
78 output="$( run_sysdb -H "$SOCKET_FILE" -c 'LIST services' )"
79 echo "$output" \
80         | grep -F '"host1.example.com"' \
81         | grep -F '"host2.example.com"' \
82         | grep -F '"localhost"' \
83         | grep -F '"some.host.name"' \
84         | grep -F '"mock service"' \
85         | grep -F '"other service"' \
86         | grep -F '"database"' \
87         | grep -F '"example service one"' \
88         | grep -F '"example service two"' \
89         | grep -F '"example service three"'
91 output="$( run_sysdb -H "$SOCKET_FILE" -c "FETCH host 'host1.example.com'" )"
92 echo "$output" \
93         | grep -F '"host1.example.com"' \
94         | grep -F '"mock service"' \
95         | grep -E '"other attribute".*"special value"'
96 echo "$output" | grep -F 'host2.example.com' && exit 1
97 echo "$output" | grep -F 'localhost' && exit 1
98 echo "$output" | grep -F 'other.host.name' && exit 1
99 echo "$output" | grep -F 'some.host.name' && exit 1
101 output="$( run_sysdb -H "$SOCKET_FILE" \
102   -c "FETCH host 'host1.example.com' FILTER last_update < 0" 2>&1 )" \
103   && exit 1
104 echo "$output" | grep -F 'not found'
106 (echo 'LIST hosts;'; sleep 1; echo "FETCH host 'host1.example.com'") \
107         | run_sysdb -H "$SOCKET_FILE"
109 # When requesting information for unknown hosts, expect a non-zero exit code.
110 output="$( run_sysdb -H "$SOCKET_FILE" \
111         -c "FETCH host 'does.not.exist'" 2>&1 )" && exit 1
112 echo "$output" | grep -F 'not found'
114 run_sysdb -H "$SOCKET_FILE" \
115                 -c "TIMESERIES 'invalid.host'.'invalid-metric'" && exit 1
117 # Does not work yet since there is no fetcher plugin.
118 output="$( run_sysdb -H "$SOCKET_FILE" \
119         -c "TIMESERIES 'some.host.name'.'foo/bar/qux'" )"
120 echo "$output" \
121         | grep -F '"value": "1.000000"' \
122         | grep -F '"value": "2.000000"' \
123         | grep -F '"value": "3.000000"' \
124         | grep -F '"value": "4.000000"' \
125         | grep -F '"value": "5.000000"' \
126         | grep -F '"value": "6.000000"' \
127         | grep -F '"value": "7.000000"' \
128         | grep -F '"value": "8.000000"' \
129         | grep -F '"value": "9.000000"' \
130         | grep -F '"value": "10.000000"'
132 stop_sysdbd
134 # vim: set tw=78 sw=4 ts=4 noexpandtab :