我们正在运行zabbix的3个组件。使用docker-compose文件将Zabbix-webui,zabbix服务器和mysql数据库作为docker容器。
已经创建了另一个已被dockerized并尝试连接到zabbix api的springboot应用程序。所有4个图像都在同一个撰写文件中运行。

我们如何连接到zabbix api并在应用程序中获取api结果?

最佳答案

让我们假设这个docker-compose.yml文件:

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


您的some-application容器应连接到http://zabbix-frontend以使用API​​。

要从应用程序容器(示例中为a5d95c2cc9a2)测试http可访问性:

# 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}

关于java - 如何从容器内部连接zabbix api?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54230614/

10-11 06:31