日常使用報表二次開發(fā)

2018-06-15 11:48 更新

日常使用報表調(diào)用關系

日常使用報表 _report 函數(shù)

(1)獲取報表的時間范圍

time_from = int(time.mktime(startTime))+1

time_till = int(time.mktime(endTime))

(2)獲取需要輸出的host 列表【主要是獲取hostid】

host_list = self._hosts_get()

如果沒有--hostid和--hostgroupid參數(shù),此函數(shù)將會返回所有的主機列表

(3)對每個host輸出和想要輸出的item相關的item信息列表【主要是獲取對應hostid的相關itemid】

itemid_all_list = self.item_get(host_info[0],itemName)

 item_get 調(diào)用的是zabbix官方api item.get

(4)依次對要查詢的itemid進行求最大值,最小值以及平均值

report_min,report_max,report_avg = self.__trend_get(itemid,time_from,time_till)

這個函數(shù)的主要參數(shù)就是itemid 和 time_from,time_till

 __trend_get調(diào)用的是zabbix官方api trend.get,同時對返回的數(shù)據(jù)進行了下求值運算(最大值,最小值,平均值)
計算方法為:
最大值:特定時間范圍內(nèi),trend.get 獲取特定itemid的最大值中的最大值
最小值:特定時間范圍內(nèi),trend.get 獲取特定itemid的最小值中的最小值
平均值:特定時間范圍內(nèi),trend.get 獲取特定itemid的平均值重新求平均值
trend.get 為zabbix3.0 加的api,故低于zabbix3.0的版本需要使用history.get 進行計算

(5)對輸出的信息進行處理

 if history_type=="3":    

    report_min=int(report_min)

    report_max=int(report_max)

    report_avg=int(report_avg)

report_min=str(report_min)

report_max=str(report_max)

report_avg=str(report_avg)

類型是3時,結(jié)果為整數(shù)型的

0 - numeric float; 
1 - character; 
2 - log; 
3 - numeric unsigned; 整型
4 - text.

想要對數(shù)據(jù)進行處理時,可以從第5步方面著手處理,good luck


    


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號