Reputation: 95
we are running 3 components of zabbix. Zabbix-webui, zabbix server and mysql database as docker containers using docker-compose file. have created another springboot application which is dockerized & trying to connect to zabbix api. All 4 images are running within the same compose file.
How can we connect to zabbix api and fetch the api results in our application?
Upvotes: 0
Views: 1298
Reputation: 2113
Let's assume this docker-compose.yml
file:
version: '2'
services:
zabbix-frontend:
restart: always
image: zabbix/zabbix-web-nginx-mysql
environment:
- DB_SERVER_HOST=someserver
[...]
some-application:
restart: always
image: yourapplication:latest
Your some-application
container should connect to http://zabbix-frontend
to consume the APIs.
To test http reachability from within the application container (a5d95c2cc9a2
in the example):
# docker exec -it a5d95c2cc9a2 sh
sh-4.2# curl -i -X POST -H 'Content-type:application/json' \
-d '{"jsonrpc":"2.0","method":"user.login", \
"params":{ "user":"youruser","password":"somepassword"},"auth":null,"id":0}' \
http://zabbix-frontend/api_jsonrpc.php
HTTP/1.1 200 OK
Server: nginx
Date: Mon, 21 Jan 2019 19:17:55 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
Keep-Alive: timeout=20
X-Powered-By: PHP/7.1.17
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Methods: POST
Access-Control-Max-Age: 1000
{"jsonrpc":"2.0","result":"xxxxxxxxxxxxxxxxx","id":0}
Upvotes: 1