在机器上已经安装好了Grafana容器,zabbix-web-Nginx-MySQL容器,镜像都是从官网下载官方制作的镜像,grafana配置zabbix数据源也是很简单的(grafana官网写的也很清楚)。下面就到了?这个配置数据源画面:
修改API地址,输入zabbix用户的密码,接着我点下确定。这时我陷入了一个深坑,报错了!!!
浏览器查看报错信息如下:
2angular.js:12759 OPTIONS http://10.211.55.8:8081/zabbix/api_jsonrpc.php 404 (Not Found)
(anonymous) @ angular.js:12759
(anonymous) @ angular.js:12492
(anonymous) @ angular.js:12244
(anonymous) @ angular.js:17051
(anonymous) @ angular.js:17095
$digest @ angular.js:18232
(anonymous) @ angular.js:18462
h @ angular.js:6362
(anonymous) @ angular.js:6642
setTimeout (async)
i.defer @ angular.js:6640
$evalAsync @ angular.js:18460
(anonymous) @ angular.js:16923
c @ angular.js:17095
e @ angular.js:17122
d @ angular.js:17106
resolve @ angular.js:17001
(anonymous) @ GrafanaCtrl.ts:9
Promise.then (async)
t.loadDatasource @ AngularLoader.ts:36
t.get @ AngularLoader.ts:24
t.testDatasource @ plugin_component.ts:47
(anonymous) @ plugin_component.ts:94
(anonymous) @ angular.js:17051
(anonymous) @ angular.js:17095
$digest @ angular.js:18232
$apply @ angular.js:18531
(anonymous) @ angular.js:18832
h @ angular.js:6362
(anonymous) @ angular.js:6642
setTimeout (async)
i.defer @ angular.js:6640
$applyAsync @ angular.js:18831
(anonymous) @ angular.js:12544
w @ angular.js:12785
y.onload @ angular.js:12702
load (async)
(anonymous) @ angular.js:12685
(anonymous) @ angular.js:12492
(anonymous) @ angular.js:12244
(anonymous) @ angular.js:17051
(anonymous) @ angular.js:17095
$digest @ angular.js:18232
$apply @ angular.js:18531
(anonymous) @ angular.js:18832
h @ angular.js:6362
(anonymous) @ angular.js:6642
setTimeout (async)
i.defer @ angular.js:6640
$applyAsync @ angular.js:18831
(anonymous) @ angular.js:12544
w @ angular.js:12785
y.onload @ angular.js:12702
load (async)
(anonymous) @ angular.js:12685
(anonymous) @ angular.js:12492
(anonymous) @ angular.js:12244
(anonymous) @ angular.js:17051
(anonymous) @ angular.js:17095
$digest @ angular.js:18232
$apply @ angular.js:18531
(anonymous) @ angular.js:27346
dispatch @ jquery.js:5183
g.handle @ jquery.js:4991
1:1 Access to XMLHttpRequest at 'http://10.211.55.8:8081/zabbix/api_jsonrpc.php' from origin 'http://10.211.55.8:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
datasource.js:355 {err: {…}, cancelled: true}
我惊异了跨域请求问题???原来用实体机装没有出现过这个问题啊!!!
一开始看到跨域请求问题在想是不是因为Nginx没有设置跨域问题,百度一整在配置文件增加了跨域的配置,还是不行!!!
索性直接再起一个httpd的zabbix web 容器试试,我擦还是不行!!!
再次,再次又研究了一下请求和响应如下:
Request URL: http://10.211.55.8:8081/zabbix/api_jsonrpc.php
Request Method: OPTIONS
Status Code: 404 Not Found
Remote Address: 10.211.55.8:8081
Referrer Policy: no-referrer-when-downgrade
Connection: keep-alive
Content-Encoding: gzip
Content-Type: text/html
Date: Mon, 25 Feb 2019 19:45:40 GMT
Keep-Alive: timeout=20
Server: nginx
Transfer-Encoding: chunked
X-Powered-By: PHP/5.4.16
Provisional headers are shown
Access-Control-Request-Headers: content-type
Access-Control-Request-Method: POST
Origin: http://10.211.55.8:3000
Referer: http://10.211.55.8:3000/datasources/edit/1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36
response
File not found.
我擦文件没找到,咋回事!!!
服务器上有api_jsonrpc.php文件啊!!!
就在我在绝望时,名侦探柯南说他用curl调用成功了啊!!!
柯南代码?
curl -s -X POST -H 'Content-Type:application/json' -d '{"jsonrpc": "2.0","method": "user.login","params": {"user": "Admin","password": "zabbix"},"id": 1}' http://localhost:80/api_jsonrpc.php
我心想这就更诡异了,我咋用curl调不成功呢!!!
我的代码?
curl -i -X POST -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","method":"user.login","params":{"user":"Admin","password":"zabbix"},"auth":null,"id":0}' http://zabbix-web-nginx-mysql-8/zabbix/api_jsonrpc.php;
我擦难道是“-i"和”-s“参数不一样导致柯南可以跑通???百度了一下这两个参数没啥用!!!
擦擦擦!!!正在百思不得其解的时候,发现两个URL不一样!!!
由于zabbix-web容器PHP文件存放的层级变了,导致API的URL也变了,少了zabbix这个层级。
其实在初始页面也可以看出这一点:
平时我们登录地址是http://ip/zabbix/
容器版的web服务直接http://ip/就可以打开登录页面。
终于活着出坑啊!!!