Skip to content

Commit af63d40

Browse files
author
alexander popov
committed
test: add test mamonsu zabbix, add configure zabbix servers
1 parent bb2cd50 commit af63d40

File tree

7 files changed

+288
-4
lines changed

7 files changed

+288
-4
lines changed

Makefile.tests

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,20 @@ run_builds:
77
run_functional_tests:
88
docker run -v "$(WORKDIR)":/var/tmp centos:7 /bin/bash -ex "/var/tmp/tests/check.sh"
99

10-
local_test:run_local_test_pg9.5 run_local_test_pg9.6 run_local_test_pg10 run_local_test_pg11 run_local_test_pg12 run_local_test_pg13
10+
local_test:local_test_prepare run_local_test_pg9.5 run_local_test_pg9.6 run_local_test_pg10 run_local_test_pg11 run_local_test_pg12 run_local_test_pg13
11+
12+
clean_local_tests: clean_zabbix clean_local_test_pg9.5 clean_local_test_pg9.6 clean_local_test_pg10 clean_local_test_pg11 clean_local_test_pg12 clean_local_test_pg13
13+
14+
local_test_prepare: clean_zabbix
15+
docker network create --driver=bridge --subnet=172.18.0.0/16 network-local-tests
16+
$(WORKDIR)/tests/local_start_zabbix.sh
1117

12-
clean_local_tests: clean_local_test_pg9.5 clean_local_test_pg9.6 clean_local_test_pg10 clean_local_test_pg11 clean_local_test_pg12 clean_local_test_pg13
1318

1419
run_local_test_pg9.5:
1520
docker run -it -d \
1621
--name pg9.5 \
22+
--net="network-local-tests" \
23+
--ip="172.18.0.95" \
1724
-e POSTGRES_PASSWORD="111111" \
1825
-e POSTGRES_HOST_AUTH_METHOD=trust \
1926
-v "$(WORKDIR)":/var/tmp/mamonsu \
@@ -26,6 +33,8 @@ run_local_test_pg9.5:
2633
run_local_test_pg9.6:
2734
docker run -it -d \
2835
--name pg9.6 \
36+
--net="network-local-tests" \
37+
--ip="172.18.0.96" \
2938
-e POSTGRES_PASSWORD="111111" \
3039
-e POSTGRES_HOST_AUTH_METHOD=trust \
3140
-v "$(WORKDIR)":/var/tmp/mamonsu \
@@ -38,6 +47,8 @@ run_local_test_pg9.6:
3847
run_local_test_pg10:
3948
docker run -it -d \
4049
--name pg10 \
50+
--net="network-local-tests" \
51+
--ip="172.18.0.10" \
4152
-e POSTGRES_PASSWORD="111111" \
4253
-e POSTGRES_HOST_AUTH_METHOD=trust \
4354
-v "$(WORKDIR)":/var/tmp/mamonsu \
@@ -50,6 +61,8 @@ run_local_test_pg10:
5061
run_local_test_pg11:
5162
docker run -it -d \
5263
--name pg11 \
64+
--net="network-local-tests" \
65+
--ip="172.18.0.11" \
5366
-e POSTGRES_PASSWORD="111111" \
5467
-e POSTGRES_HOST_AUTH_METHOD=trust \
5568
-v "$(WORKDIR)":/var/tmp/mamonsu \
@@ -62,6 +75,8 @@ run_local_test_pg11:
6275
run_local_test_pg12:
6376
docker run -it -d \
6477
--name pg12 \
78+
--net="network-local-tests" \
79+
--ip="172.18.0.12" \
6580
-e POSTGRES_PASSWORD="111111" \
6681
-e POSTGRES_HOST_AUTH_METHOD=trust \
6782
-v "$(WORKDIR)":/var/tmp/mamonsu \
@@ -71,9 +86,11 @@ run_local_test_pg12:
7186
docker stop pg12
7287
docker rm pg12
7388

74-
run_local_test_pg13:
89+
run_local_test_pg13: clean_local_test_pg13
7590
docker run -it -d \
7691
--name pg13 \
92+
--net="network-local-tests" \
93+
--ip="172.18.0.13" \
7794
-e POSTGRES_PASSWORD="111111" \
7895
-e POSTGRES_HOST_AUTH_METHOD=trust \
7996
-v "$(WORKDIR)":/var/tmp/mamonsu \
@@ -83,6 +100,9 @@ run_local_test_pg13:
83100
docker stop pg13
84101
docker rm pg13
85102

103+
run_zabbix: clean_zabbix
104+
$(WORKDIR)/tests/local_start_zabbix.sh
105+
86106
clean_local_test_pg9.5:
87107
docker stop pg9.5 | true
88108
docker rm pg9.5 | true
@@ -105,4 +125,13 @@ clean_local_test_pg12:
105125

106126
clean_local_test_pg13:
107127
docker stop pg13 | true
108-
docker rm pg13 | true
128+
docker rm pg13 | true
129+
130+
clean_zabbix:
131+
docker stop `docker ps -a -q --filter="name=zabbix-server-pgsql" ` | true
132+
docker rm `docker ps -a -q --filter="name=zabbix-server-pgsql" ` | true
133+
docker stop `docker ps -a -q --filter="name=zabbix-web-apache-pgsql" ` | true
134+
docker rm `docker ps -a -q --filter="name=zabbix-web-apache-pgsql" ` | true
135+
docker stop pg_for_zabbix | true
136+
docker rm pg_for_zabbix | true
137+
docker network rm network-local-tests | true

tests/local_start_zabbix.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash -ex
2+
3+
if [ ! -v ZABBIX_DOCKER_VERSIONS ];
4+
then
5+
export ZABBIX_DOCKER_VERSIONS="5.2 5.0 4.4 4.2"
6+
fi
7+
# !!!! zabbix 4.4 имеет порт 80, остальные 8080
8+
#ZABBIX_DOCKER_VERSIONS="4.4"
9+
10+
docker run -it -d \
11+
--name pg_for_zabbix \
12+
--ip 172.18.0.7 \
13+
--net network-local-tests \
14+
--hostname pg_for_zabbix \
15+
-e POSTGRES_PASSWORD="111111" \
16+
-e POSTGRES_HOST_AUTH_METHOD=trust \
17+
postgres:13 /bin/bash /docker-entrypoint.sh -c max_connections=200
18+
sleep 3
19+
20+
docker exec -d -i pg_for_zabbix psql -U postgres -c 'create user zabbix superuser'
21+
docker exec -d -i pg_for_zabbix psql -U postgres -c 'create database zabbix owner zabbix'
22+
for VER in $ZABBIX_DOCKER_VERSIONS
23+
do
24+
VER2="${VER/./_}"
25+
IFS='.' read -ra VER_ARRAY <<<$VER
26+
VER_MAJOR=${VER_ARRAY[0]}
27+
VER_MINOR=${VER_ARRAY[1]}
28+
docker exec -d -i pg_for_zabbix psql -U postgres -c "create database zabbix_$VER2 owner zabbix"
29+
sleep 1
30+
docker run \
31+
--name="zabbix-server-pgsql_$VER2" \
32+
--ip="172.18.0.1$VER_MAJOR$VER_MINOR" \
33+
--net network-local-tests \
34+
--hostname="zabbix-server-pgsql_$VER2" \
35+
-e DB_SERVER_HOST="pg_for_zabbix" \
36+
-e DB_SERVER_DBNAME="server_$VER2" \
37+
-e POSTGRES_USER="zabbix" \
38+
-e POSTGRES_DB="zabbix_$VER2" \
39+
-e PHP_TZ="Europe/Moscow" \
40+
-d zabbix/zabbix-server-pgsql:alpine-$VER-latest
41+
42+
sleep 1
43+
docker run \
44+
--name="zabbix-web-apache-pgsql_$VER2" \
45+
--net="network-local-tests" \
46+
--ip="172.18.0.2$VER_MAJOR$VER_MINOR" \
47+
-e DB_SERVER_HOST="pg_for_zabbix" \
48+
-e ZBX_SERVER_HOST="zabbix-server-pgsql_$VER2" \
49+
-e DB_SERVER_DBNAME="zabbix_$VER2" \
50+
-e POSTGRES_DB="zabbix_$VER2" \
51+
-e POSTGRES_USER="zabbix" \
52+
--restart unless-stopped \
53+
-e PHP_TZ="Europe/Moscow" \
54+
-d zabbix/zabbix-web-apache-pgsql:alpine-$VER-latest
55+
done
56+
exit 0
57+
58+
59+
# docker exec -it -i pg_for_zabbix psql -U postgres -c '\l'
60+
# docker exec -it -i pg_for_zabbix psql -U postgres -c '\du'
61+
# docker exec -it zabbix-web-apache-pgsql_5.0 bash

tests/local_tests.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,31 @@
22

33
/var/tmp/mamonsu/tests/local_install_mamonsu.sh
44
/var/tmp/mamonsu/tests/bootstrap.sh
5+
6+
###### test mamonsu zabbix *
7+
mkdir /etc/mamonsu/
8+
cp /var/tmp/mamonsu/packaging/conf/example.conf /etc/mamonsu/agent.conf
9+
ZABBIX_DOCKER_VERSIONS="5.2 5.0 4.4 4.2"
10+
for VER in $ZABBIX_DOCKER_VERSIONS
11+
do
12+
IFS='.' read -ra VER_ARRAY <<<$VER
13+
VER_MAJOR=${VER_ARRAY[0]}
14+
VER_MINOR=${VER_ARRAY[1]}
15+
16+
Z_PORT=":8080"
17+
if [[ "$VER" == "4.2" ]]
18+
then
19+
Z_PORT=":80"
20+
fi
21+
export Z_URL="http://172.18.0.2$VER_MAJOR$VER_MINOR$Z_PORT"
22+
export Z_USER=Admin
23+
export Z_PASSWORD=zabbix
24+
export Z_VERSION=$VER
25+
echo " Z_URL=$Z_URL,
26+
Z_USER=$Z_USER
27+
Z_PASSWORD=$Z_PASSWORD
28+
Z_VERSION=$Z_VERSION"
29+
/var/tmp/mamonsu/tests/zabbix.sh
30+
done
31+
532
exit 0

tests/template.xml

Lines changed: 30 additions & 0 deletions
Large diffs are not rendered by default.

tests/template_new.xml

Lines changed: 30 additions & 0 deletions
Large diffs are not rendered by default.

tests/template_old.xml

Lines changed: 30 additions & 0 deletions
Large diffs are not rendered by default.

tests/zabbix.sh

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash -ex
2+
3+
# тест команд /mamonsu zabbix *
4+
# Требования:
5+
# наличие запущенного zabbix сервера и прописанные переменные окружения: Z_URL Z_USER Z_PASSWORD, Z_MAJOR_VERSION
6+
# todo change and remove
7+
#Z_URL=http://192.168.234.53/zabbix
8+
#Z_USER=user
9+
#Z_PASSWORD=111111
10+
11+
if [ ! -v Z_URL ];
12+
then
13+
export Z_URL=localhost
14+
fi
15+
if [ ! -v Z_USER ];
16+
then
17+
export Z_USER=Admon
18+
fi
19+
if [ ! -v Z_PASSWORD ];
20+
then
21+
export Z_PASSWORD=zabbix
22+
fi
23+
if [ ! -v Z_VERSION ];
24+
then
25+
export Z_VERSION=5.0
26+
fi
27+
28+
echo "Z_URL=$Z_URL, Z_USER=$Z_USER, Z_PASSWORD=$Z_PASSWORD"
29+
OPTIONS=" --url=$Z_URL --user=$Z_USER --password=$Z_PASSWORD"
30+
31+
# test 1 mamonsu zabbix template with
32+
#mamonsu zabbix template list
33+
#mamonsu zabbix template show <template name>
34+
#mamonsu zabbix template id <template name>
35+
#mamonsu zabbix template delete <template id>
36+
#mamonsu zabbix template export <file>
37+
38+
echo "Test with connect options: $OPTIONS "
39+
## prepare
40+
IFS='.' read -ra Z_VERSION_ARRAY <<<$Z_VERSION
41+
Z_VERSION_MAJOR=${Z_VERSION_ARRAY[0]}
42+
Z_VERSION_MINOR=${Z_VERSION_ARRAY[1]}
43+
echo Z_VERSION_MAJOR
44+
45+
OLD_ZABBIX=" "
46+
if ((Z_VERSION_MAJOR <= 4))
47+
then
48+
if ((Z_VERSION_MINOR <= 2))
49+
then
50+
OLD_ZABBIX=" --old-zabbix "
51+
fi
52+
fi
53+
54+
mamonsu export template $OLD_ZABBIX template.xml | grep "Template for mamonsu has been saved as template.xml" || exit 11
55+
mamonsu zabbix template export template.xml $OPTIONS
56+
mamonsu zabbix template list $OPTIONS | grep PostgresPro-Linux || exit 11
57+
mamonsu zabbix template show PostgresPro-Linux $OPTIONS | grep PostgresPro-Linux || exit 11
58+
mamonsu zabbix template id PostgresPro-Linux $OPTIONS | grep -x -E "[[:digit:]]+" || exit 11
59+
TEMPLATE_ID=`mamonsu zabbix template id PostgresPro-Linux $OPTIONS`
60+
mamonsu zabbix template delete $TEMPLATE_ID $OPTIONS | grep "templateids.*$TEMPLATE_ID" || exit 11
61+
62+
# test 2 mamonsu zabbix - Environment variables
63+
64+
export ZABBIX_URL=$Z_URL
65+
export ZABBIX_USER=$Z_USER
66+
export ZABBIX_PASSWD=$Z_PASSWORD
67+
68+
echo "Test with Environment variables: ZABBIX_URL=$ZABBIX_URL, ZABBIX_USER=$ZABBIX_USER, ZABBIX_PASSWD=$ZABBIX_PASSWD"
69+
mamonsu export template $OLD_ZABBIX template.xml | grep "Template for mamonsu has been saved as template.xml" || exit 11
70+
mamonsu zabbix template export template.xml
71+
mamonsu zabbix template list | grep PostgresPro-Linux || exit 11
72+
mamonsu zabbix template show PostgresPro-Linux | grep PostgresPro-Linux || exit 11
73+
mamonsu zabbix template id PostgresPro-Linux | grep -x -E "[[:digit:]]+" || exit 11
74+
TEMPLATE_ID=`mamonsu zabbix template id PostgresPro-Linux`
75+
mamonsu zabbix template delete $TEMPLATE_ID | grep "templateids.*$TEMPLATE_ID" || exit 11
76+
77+
exit 0

0 commit comments

Comments
 (0)