深度剖析Zabbix Web scenarios數(shù)據(jù)表結(jié)構(gòu)
前言
因開(kāi)發(fā)需求,需要解析Zabbix web監(jiān)控?cái)?shù)據(jù)表結(jié)構(gòu);因?yàn)榫W(wǎng)上關(guān)于Zabbix數(shù)據(jù)表結(jié)構(gòu)解析的比較少,所以心血來(lái)潮寫了一篇作為記錄。
突破口
對(duì)Zabbix數(shù)據(jù)庫(kù)表結(jié)構(gòu)做解析的時(shí)候,我有個(gè)習(xí)慣,直接針對(duì)某個(gè)itemid懟。
這次當(dāng)然不例外,隨便找了個(gè)Zabbix web itemid。
直接查數(shù)據(jù)庫(kù)里有哪些表
show tables like "%http%";
+—————————+
| Tables_in_zabbix (%http%) |
+—————————+
| httpstep |
| httpstep_field |
| httpstepitem |
| httptest |
| httptest_field |
| httptestitem |
+—————————+
用屁股猜已經(jīng)猜出大概存儲(chǔ)的是什么內(nèi)容:
httpstep 存儲(chǔ)的為場(chǎng)景信息 httpstepitem 存儲(chǔ)的為場(chǎng)景ID httptest 存儲(chǔ)的為步驟信息 httptestitem 存儲(chǔ)的為步驟ID
剖析
以itemid為突破口
獲取到這個(gè)場(chǎng)景的itemID
查詢這個(gè)item所在的testID與testitemID
select * from httptestitem where itemid="56263" ;
+—————-+————+——–+——+
| httptestitemid | httptestid | itemid | type |
+—————-+————+——–+——+
| 1194 | 398 | 56263 | 4 |
+—————-+————+——–+——+
根據(jù)這個(gè)itemid我們找到他對(duì)應(yīng)的場(chǎng)景id。
獲取這個(gè)場(chǎng)景的幾個(gè)監(jiān)控item值
Last error message of scenario Download speed for scenario Failed step of scenario
select * from httptestitem where httptestid="398";
+—————-+————+——–+——+
| httptestitemid | httptestid | itemid | type |
+—————-+————+——–+——+
| 1192 | 398 | 56261 | 2 |
| 1193 | 398 | 56262 | 3 |
| 1194 | 398 | 56263 | 4 |
+—————-+————+——–+——+
解析一波,具體自己參照Latest data
#############
# 各Type剖析
#
# type類型為2代表【Download speed for scenario】
# 場(chǎng)景總下載速度,歷史數(shù)據(jù)存儲(chǔ)在history表.
#
# type類型為3代表【Failed step of scenario】
# 場(chǎng)景返回狀態(tài)碼, 0表示場(chǎng)景正常, 每個(gè)步驟異常為1.歷史數(shù)據(jù)存儲(chǔ)在history_uint表.
#
# type類型為4代表【Last error message of scenario】
# 上一次場(chǎng)景返回錯(cuò)誤信息,歷史數(shù)據(jù)存儲(chǔ)在history_str表.
#
#############
接下來(lái)根據(jù)場(chǎng)景ID找出步驟
查詢http場(chǎng)景下的步驟
Download speed for step Response time for step Response code for step
select * from httpstepitem where httpstepid="398";
+—————-+————+——–+——+
| httpstepitemid | httpstepid | itemid | type |
+—————-+————+——–+——+
| 1192 | 398 | 56180 | 2 |
| 1193 | 398 | 56181 | 1 |
| 1194 | 398 | 56182 | 0 |
+—————-+————+——–+——+
解析一波,具體自己參照Latest data
#############
# 各Type剖析
#
# type類型為2代表【Download speed for step】
# 步驟的下載速度,歷史數(shù)據(jù)存儲(chǔ)在history表.
#
# type類型為1代表【Response time for step】
# 步驟返回時(shí)間,歷史數(shù)據(jù)存儲(chǔ)在history表.
#
# type類型為0代表【Response code for step】
# 步驟的返回狀態(tài)碼, 其中0為無(wú)法連接,無(wú)狀態(tài)碼.歷史數(shù)據(jù)存儲(chǔ)在history_uint表.
#
#############
接下來(lái)剖析詳細(xì)場(chǎng)景與步驟
根據(jù)ID查詢場(chǎng)景信息
自行對(duì)應(yīng)ZabbixWEB界面
select * from httptest where httptestid="398" G;
*************************** 1. row ***************************
httptestid: 398
name: 業(yè)務(wù)接口A
applicationid: 800
nextcheck: 1542984224
delay: 1m
status: 0
agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36
authentication: 0
http_user:
http_password:
hostid: 10084
templateid: 397
http_proxy:
retries: 1
ssl_cert_file:
ssl_key_file:
ssl_key_password:
verify_peer: 0
verify_host: 0
順便簡(jiǎn)單介紹下場(chǎng)景下的字段表,也就是一些自定宏
select * from httptest_field limit 1;
+——————+————+——+———-+——————-+
| httptest_fieldid | httptestid | type | name | value |
+——————+————+——+———-+——————-+
| 1 | 535 | 1 | {IP} | 10.1.1.1 |
+——————+————+——+———-+——————-+
# type為1表示 Variables.
# type為0表示 Headers.
接下來(lái)查看場(chǎng)景里面的步驟 自行參照Steps頁(yè)面
查詢指定ID的步驟
select * from httpstep where httptestid="398"G;
*************************** 1. row ***************************
httpstepid: 412
httptestid: 398
name: 業(yè)務(wù)接口A
no: 1
url: https://baidu.com
timeout: 15s
posts:
required:
status_codes:
follow_redirects: 0
retrieve_mode: 0
post_type: 0
# no代表場(chǎng)景的步驟
# required表示步驟正常返回字符串,填寫內(nèi)容為正則表達(dá)式.
步驟也有map字段表
select * from httpstep_field limit 1;
+——————+————+——+———-+———————+
| httpstep_fieldid | httpstepid | type | name | value |
+——————+————+——+———-+———————+
| 1 | 129 | 1 | {rentid} | regex:([0-9]{4,10}) |
+——————+————+——+———-+———————+
# type為0表示 Headers.
# type為1表示 Variables.
# type為2表示 Post fields.
后記
文章一些數(shù)據(jù)表字段不明白都可以參照Z(yǔ)abbixWEB配置頁(yè)面。
另外建議大家Zabbix二次開(kāi)發(fā)的時(shí)候可以懟庫(kù)就懟庫(kù),遇到邏輯復(fù)雜沒(méi)有把握才使用API。