如何采用Python zabbix(3)

#/usr/bin/env python
#-*-coding:UTF-8
"""
    wget
"""
 
import os,sys,time
 
users=u'admin'
pawd = 'zabbix'
 
exc_py = '/data/zabbix/fetch_items_to_csv.py'
os.system('easy_install zabbix_api')
os.system('mkdir -p /data/zabbix/cvs/')
 
if not os.path.exists(exc_py):
    os.system("mkdir -p /data")
    os.system("wget -O /data/zabbix/fetch_items_to_csv.py")
 
def show_items(moniter, dip):
    items = dict()
    items['io_read_win'] = "perf_counter[\\2\\16]"
    items['io_write_win'] = "perf_counter[\\2\\18]"
 
    items['io_read_lin'] = "iostat[,rkB/s]"
    items['io_write_lin'] = "iostat[,wkB/s]"
    items['io_read_lin_sda'] = "iostat[sda,rkB/s]"
    items['io_write_lin_sda'] = "iostat[sda,wkB/s]"
 
    items['io_read_lin_sdb'] = "iostat[sdb,rkB/s]"
    items['io_write_lin_sdb'] = "iostat[sdb,wkB/s]"
 
    # Add items, iostate vdb,vdb
    items['io_read_lin_vda'] = "iostat[vda,rkB/s]"
    items['io_write_lin_vda'] = "iostat[vda,wkB/s]"
 
    items['io_read_lin_vdb'] = "iostat[vdb,rkB/s]"
    items['io_write_lin_vdb'] = "iostat[vdb,wkB/s]"
   
    items['cpu_util'] = "system.cpu.util"
 
    items['net_in_linu_vm_web'] = "net.if.in[eth0]"
    items['net_out_lin_vm_web'] = "net.if.out[eth0]"
 
    items['net_in_linu_vm_db'] = "net.if.in[eth1]"
    items['net_out_lin_vm_db'] = "net.if.out[eth1]"
 
    items['net_in_win_vm'] = "net.if.in[Red Hat VirtIO Ethernet Adapter]"
    items['net_in_win_vm_2'] = "net.if.in[Red Hat VirtIO Ethernet Adapter #2]"
    items['net_in_win_vm_3'] = "net.if.in[Red Hat VirtIO Ethernet Adapter #3]"
 
    items['net_out_win_vm'] = "net.if.out[Red Hat VirtIO Ethernet Adapter]"
    items['net_out_win_vm_2'] = "net.if.out[Red Hat VirtIO Ethernet Adapter #2]"
    items['net_out_win_vm_3'] = "net.if.out[Red Hat VirtIO Ethernet Adapter #3]"
 
    items['net_in_phy_web_lin'] = "net.if.in[bond0]"
    items['net_out_phy_web_lin'] = "net.if.out[bond0]"
 
    items['net_in_phy_db_lin'] = "net.if.in[bond1]"
    items['net_out_phy_db_lin'] = "net.if.out[bond1]"
 
    items['net_in_phy_web_win'] = "net.if.in[TEAM : WEB-TEAM]"
    items['net_out_phy_web_win'] = "net.if.in[TEAM : WEB-TEAM]"
 
    items['net_in_phy_db_win'] = "net.if.in[TEAM : DB Team]"
    items['net_out_phy_db_win'] = "net.if.out[TEAM : DB Team]"
 
    items['net_in_phy_web_win_1'] = "net.if.in[TEAM : web]"
    items['net_out_phy_web_win_1'] = "net.if.out[TEAM : web]"
 
    items['net_in_phy_db_win_1'] = "net.if.in[TEAM : DB]"
    items['net_out_phy_db_win_1'] = "net.if.out[TEAM : DB]"
 
    items['net_in_win_pro'] = "net.if.in[Intel(R) PRO/1000 MT Network Connection]"
    items['net_out_win_pro'] = "net.if.out[Intel(R) PRO/1000 MT Network Connection]"
 
    items['net_in_phy_web_hp'] = "net.if.in[HP Network Team #1]"
    items['net_out_phy_web_hp'] = "net.if.out[HP Network Team #1]"
 
    items['iis_conntion'] = "perf_counter[\\Web Service(_Total)\\Current Connections]"
    items['tcp_conntion'] = "k.tcp.conn[ESTABLISHED]"
 
    for x,y in items.items():
        os.system('mkdir -p /data/zabbix/cvs/%s' % dip)
        cmds = """
        python /data/zabbix/fetch_items_to_csv.py -s '%s' -n '%s' -k '%s' -u 'admin' -p '%s' -t1 '2015-06-23 00:00:01' -t2 '2015-06-30 00:00:01' -o /data/zabbix/cvs/%s/%s_%s.cvs""" %(moniter,dip,y,pawd,dip,dip,x)
 
        os.system(cmds)
 
        print "*"  * 100
        print cmds
        print "*" * 100
 
 
def work():
    moniter='192.168.1.1'
   
    ip_list = ['192.168.1.15','192.168.1.13','192.168.1.66','192.168.1.5','192.168.1.7','192.168.1.16','192.168.1.38','192.168.1.2','192.168.1.13','192.168.1.10']
 
    for ip in ip_list:
        show_items(moniter,ip )
 
 
if __name__ == "__main__":
    sc = work()

三:数据采集完毕,进行格式化输出

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/ffe942d2ed4265818c07ce4dce4f88b7.html