示例#1
0
def zbxsend(connectnum):
    zbx_host = getiniConfig.getConfig('/tools/config/nsconfig',
                                      'monitorlinenumber.ini', 'zabbixConfig',
                                      'zbx_host')
    zbx_port = int(
        getiniConfig.getConfig('/tools/config/nsconfig',
                               'monitorlinenumber.ini', 'zabbixConfig',
                               'zbx_port'))
    zbx_host = eval(zbx_host)
    innerIP = str(get_ip_address('eth1'))
    innerIPPart = '.'.join(innerIP.split('.')[0:-1])
    zbx_ip = ''
    for host in zbx_host:
        for inIP in host['innerIP']:
            inIP = '.'.join(inIP.split('.')[0:-1])
            if innerIPPart == inIP:
                zbx_ip = host['zbx_ip']
                continue
    if not zbx_ip:
        zbx_ip = "127.0.0.1"
    zbxdata = []
    zbxdata.append({
        "host": str(get_ip_address('eth1')),
        "key": "monitor_linenumber.status",
        "value": int(connectnum)
    })
    zbxsender = zabbix_sender(zbx_ip, zbx_port)
    zbxsender.send(zbxdata, datarecv_print)

    getiniConfig.write_config('/home/config', 'monitorNewlinenumber.ini',
                              'lastNumConfig', 'lastLineNum', str(connectnum))
示例#2
0
def send_zabbix(type, value):
    global zbx_host
    if not zbx_host:
        zbx_host = getConfig('zbx_host', 'zabbixConfig').strip('"').strip("'")
        zbx_host = eval(zbx_host)
    innerIP = str(get_ip_address('eth1'))
    innerIPPart = '.'.join(innerIP.split('.')[0:-1])
    zbx_ip = ''
    for host in zbx_host:
        for inIP in host['innerIP']:
            inIP = '.'.join(inIP.split('.')[0:-1])
            if innerIPPart == inIP:
                zbx_ip = host['zbx_ip']
                continue
    if not zbx_ip:
        zbx_ip = "127.0.0.1"
    if type == 'databak_zabbix':
        print 'databak_zabbix is %s' % str(value)
        zbxdata = []
        zbxdata.append({
            "host": str(get_ip_address('eth1')),
            "key": "databak_zabbix.status",
            "value": value
        })
        zbxsender = zabbix_sender(zbx_ip, zbx_port)
        zbxsender.send(zbxdata, datarecv_print)
    elif type == 'newdisk_zabbix':
        print 'newdisk_zabbix is %s' % str(value)
        zbxdata = []
        zbxdata.append({
            "host": str(get_ip_address('eth1')),
            "key": "newdisk_zabbix.status",
            "value": value
        })
        zbxsender = zabbix_sender(zbx_ip, zbx_port)
        zbxsender.send(zbxdata, datarecv_print)