-
Notifications
You must be signed in to change notification settings - Fork 134
sec_dev
日常使用报表 _report 函数
time_from = int(time.mktime(startTime))+1
time_till = int(time.mktime(endTime))
host_list = self._hosts_get()
如果没有 --hostid 和 --hostgroupid 参数,此函数将会返回所有的主机列表
itemid_all_list = self.item_get(host_info[0],itemName)
item_get 调用的是 zabbix 官方 api item.get
此部分不同的导出报表使用的不同的参数进行获取 item 列表,具体如下
- report-------- 此处调用
item_get
函数根据 item_name 模糊搜索获取某个 host 的 item 列表 - report_app---- 此处调用
__appitem_get
函数根据特定的 applicationid 获取某个 host 的 item 列表 - report_key---- 此处调用
__item_get2
函数根据特定的 item key 获取某个 host 的 item 列表,此处为特定搜索,__item_get2 只处理单个 item key 所以返回的列表中只有单个 item
report_min,report_max,report_avg = self.__trend_get(itemid,time_from,time_till)
这个函数的主要参数就是 itemid 和 time_from,time_till __trend_get 调用的是 zabbix 官方 api trend.get, 同时对返回的数据进行了下求值运算(最大值,最小值,平均值) 计算方法为: 最大值:特定时间范围内,trend.get 获取特定 itemid 的最大值中的最大值 最小值:特定时间范围内,trend.get 获取特定 itemid 的最小值中的最小值 平均值:特定时间范围内,trend.get 获取特定 itemid 的平均值重新求平均值 trend.get 为 zabbix3.0 加的 api,故低于 zabbix3.0 的版本需要使用 history.get 进行计算
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 时,结果为整数型的 0 - numeric float; 1 - character; 2 - log; 3 - numeric unsigned; 整型 4 - text.
输出显示包括终端表格
和excel
表格输出,主要部分是个列表,即report_output
report_output.append([host_info[0],host_info[2],item_name,report_min,report_max,report_avg])
如:某位大哥想输出到 excel 表格中的值自动更换单位,如获取到的 1024B 显示为 1KB 【此需求已实现】
想要对数据进行处理时,可以从第 5 步方面着手处理
目前 report_key 只能输出单 host 单 key 显示,如想要达到以上需求
- 修改上面步骤第 3 步,修改__item_get2 程序使 __item_get2 可以处理多个 key 返回多个 item 的列表
- 修改上面步骤第 6 步,修改为对同一个 host 得到的 item 追加后放到 report_output 列表,如 report_output.append([host_info[0],host_info[2],item_name1,report_min1,report_max1,report_avg1,item_name2,report_min2,report_max2,report_avg2])
- 在第 6 步骤 report_output的列表参数中增加
host_info[3]
,host_info[3]即为host IP
如
report_output.append([host_info[0],host_info[2],host_info[3],item_name,report_min,report_max,report_avg])
行到水穷处 坐看云起时 good luck
遇到问题可以加入 Zabbix 开源社区群进行讨论 加入微信群方法如下
- (1) 微信添加 zabbix_china(Zabbix_Z小秘)备注说明:(王斌 zabbix_manager)
- (2) 然后让
Zabbix_Z小秘
拉入Zabbix 开源社区群
即可