forked from claranet/go-zabbix-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.sh
28 lines (23 loc) · 1.13 KB
/
tests.sh
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
#!/bin/bash
set -ueo pipefail
echo "Run zabbix checks"
# Check zabbix version
ZABBIX_VERSION=$(curl -s -X POST -H 'Content-Type: application/json-rpc' -d '{"jsonrpc":"2.0","method":"apiinfo.version","id":1,"auth":null,"params":{}}' "$TEST_ZABBIX_URL" | jq -c -r .result)
if ! [[ "$ZABBIX_VERSION" == "$TEST_ZABBIX_VERSION"* ]]; then
echo "Zabbix server version wrong version"
exit 1
fi
# Check login
ZABBIX_TOKEN=$(curl -s -X POST -H 'Content-Type: application/json-rpc' -d "{\"jsonrpc\":\"2.0\",\"method\":\"user.login\",\"id\":1,\"params\":{\"username\":\"$TEST_ZABBIX_USER\",\"password\":\"$TEST_ZABBIX_PASSWORD\"}}" "$TEST_ZABBIX_URL" | jq -c -r .result)
if [[ "$ZABBIX_VERSION" == "null" ]]; then
echo "Zabbix login failed"
exit 2
fi
# Check request
ZABBIX_USERID=$(curl -s -X POST -H 'Content-Type: application/json-rpc' -d "{\"jsonrpc\":\"2.0\",\"method\":\"user.get\",\"id\":1,\"auth\":\"${ZABBIX_TOKEN}\",\"params\":{}}" "$TEST_ZABBIX_URL" | jq -r -c '.result[] | select(.name=="Zabbix") | .userid')
if [[ $ZABBIX_USERID -ne 1 ]]; then
echo "Zabbix default user does not match id 1"
exit 3
fi
echo "Success"
exit 0