示例#1
0
def memt_in_db():
    # get_srv_list = ["219.134.132.194"]
    if not get_srv_list:
        srv_list = zbx_srv.objects.all()
    else:
        for srv in get_srv_list:
            srv_list = zbx_srv.objects.filter(ip=srv)
    print "zabbix get mem total info: ", len(srv_list)
    for i in srv_list:
        print "connect to ... ", i.ip, i.port
        conn_chk = connect_chk(i.ip, int(i.port))
        i.status = conn_chk
        i.save()
        if conn_chk:
            res_srvinfo = zbx_con(i.ip, i.port, "mem_t")
        else:
            print i.name, "connection fail..."
            continue
        for j in res_srvinfo:
            db, sta = hosts.objects.get_or_create(zbx_srv_id=i.id, host_id=j[0])
            mem_2_m = int(j[1]) / 1048576
            db.mem_total = mem_2_m
            db.name = j[2]
            db.save()

        print "get host mem total success : ", i.name
示例#2
0
def update():
    srv_list = zbx_srv.objects.all()
    # srv_list = zbx_srv.objects.filter(ip="219.134.132.194")
    for i in srv_list:
        print "connect to ... ", i.ip, i.port
        conn_chk = connect_chk(i.ip, int(i.port))
        i.status = conn_chk
        i.save()
        if conn_chk:
            f = open("/opt/mozbx_server/mozbx/zbx2db.py", "rb")
            file_data = f.read()
            f.close()
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            try:
                s.settimeout(30)
                s.connect((i.ip, i.port))
                s.send("update")
                time.sleep(1)
                s.send(file_data)
                print 'file sent finished!'
            except socket.error, arg:
                (errno, err_msg) = arg
                print "Connect server failed: %s, errno=%d" % (err_msg, errno)
            time.sleep(5)
            s.send("file_send_done")
            s.close()
        else:
            print i.name, "connection fail..."
            continue
示例#3
0
def update():
    srv_list = zbx_srv.objects.all()
    # srv_list = zbx_srv.objects.filter(ip="219.134.132.194")
    for i in srv_list:
        print "connect to ... ", i.ip, i.port
        conn_chk = connect_chk(i.ip, int(i.port))
        i.status = conn_chk
        i.save()
        if conn_chk:
            f = open("/opt/mozbx_server/mozbx/zbx2db.py", "rb")
            file_data = f.read()
            f.close()
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            try:
                s.settimeout(30)
                s.connect((i.ip, i.port))
                s.send("update")
                time.sleep(1)
                s.send(file_data)
                print 'file sent finished!'
            except socket.error, arg:
                (errno, err_msg) = arg
                print "Connect server failed: %s, errno=%d" % (err_msg, errno)
            time.sleep(5)
            s.send("file_send_done")
            s.close()
        else:
            print i.name, "connection fail..."
            continue
示例#4
0
def memt_in_db():
    # get_srv_list = ["219.134.132.194"]
    if not get_srv_list:
        srv_list = zbx_srv.objects.all()
    else:
        for srv in get_srv_list:
            srv_list = zbx_srv.objects.filter(ip=srv)
    print "zabbix get mem total info: ", len(srv_list)
    for i in srv_list:
        print "connect to ... ", i.ip, i.port
        conn_chk = connect_chk(i.ip, int(i.port))
        i.status = conn_chk
        i.save()
        if conn_chk:
            res_srvinfo = zbx_con(i.ip, i.port, "mem_t")
        else:
            print i.name, "connection fail..."
            continue
        for j in res_srvinfo:
            db, sta = hosts.objects.get_or_create(zbx_srv_id=i.id,
                                                  host_id=j[0])
            mem_2_m = int(j[1]) / 1048576
            db.mem_total = mem_2_m
            db.name = j[2]
            db.save()

        print "get host mem total success : ", i.name
示例#5
0
def war_in_db():
    # srv_list = zbx_srv.objects.filter(ip="219.134.132.194")
    if not get_srv_list:
        srv_list = zbx_srv.objects.all()
    else:
        for srv in get_srv_list:
            srv_list = zbx_srv.objects.filter(name=srv)
    print "zabbix get info hosts: ", len(srv_list)
    for i in srv_list:
        print "connect to ... ", i.ip, i.port
        conn_chk = connect_chk(i.ip, int(i.port))
        i.status = conn_chk
        i.save()
        if conn_chk:
            res_host = zbx_con(i.ip, i.port, "war")
        else:
            print i.name, "connection fail..."
            continue
        t_now = time.time()
        ch_nt = datetime.datetime.utcfromtimestamp(t_now)
        ch_at = timezone.make_aware(ch_nt, TZ)
        Issues.objects.filter(locate=i.name).filter(resolve=0).update(resolve=1, resolvetime=ch_at)
        if not res_host:
            db, sta = Issues.objects.get_or_create(
                locate=i.name,
                hostname="---all  hosts---",
                desciptions="No warnning messages!",
                level=1
                )
            db.resolve=1
            db.resolvetime=ch_at
            db.problemtime=ch_at
            db.save()
            print timezone.now(), i.name, "All good!"
            continue
        for j in res_host:
            d_if = re.findall("Free disk space is less than \d{,2}% on volume /data", j[2])
            if "dn" in j[0] and d_if:
                continue
            # ch_t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(j[1]))
            ch_nt = datetime.datetime.utcfromtimestamp(int(j[1]))
            ch_at = timezone.make_aware(ch_nt, TZ)
            des = j[2].replace("{HOST.NAME}", j[0])
            db, sta = Issues.objects.get_or_create(locate=i.name,
                                                   hostname=j[0],
                                                   desciptions=des,
                                                   problemtime=ch_at,
                                                   level=int(j[3])
                                                   )
            db.resolve=0
            db.resolvetime=ch_at
            db.save()
            if "hjdl" in j[0]:
                hj_mail_send(des)
        print timezone.now(), i.name, "get warnning!"
示例#6
0
def ora_in_db():
    if not get_srv_list:
        srv_list = zbx_srv.objects.all()
    else:
        for srv in get_srv_list:
            srv_list = zbx_srv.objects.filter(name=srv)
    print "zabbix get ora db info: ", len(srv_list)
    for i in srv_list:
        mail_sta = 0
        print "connect to ... ", i.ip, i.port
        conn_chk = connect_chk(i.ip, int(i.port))
        i.status = conn_chk
        i.save()
        if conn_chk:
            res_srvinfo = zbx_con(i.ip, i.port, "oradb")
            print "get db info..."
            print res_srvinfo
        else:
            print i.name, "connection fail..."
            continue
        if not res_srvinfo:
            continue
        else:
            for j in res_srvinfo:
                timestr = time.strftime("%Y-%m-%d %H:%M:%S",
                                        time.localtime(int(j[4])))
                db, sta = ora_db.objects.get_or_create(
                    zbx_srv_name=i.name,
                    host_id=j[0],
                    keyname=j[3]
                )
                db.host_name = j[1]
                db.desciptions = j[2]
                db.checktime = timestr
                db.status = int(j[5])
                if int(time.time()) - int(j[4]) >  1200:
                    db.recv_state = 0
                    if mail_sta == 0 :
                        messages = "Host: %s %s No data revice at %s, please check. " % (j[1],
                                                              j[2],
                                                              time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(time.time()))),
                                                              )
                        mail_send(messages)
                        mail_sta = 1
                else:
                    db.recv_state = 1
                db.save()
                if int(j[5]) == 0:
                    messages = "Host: %s %s %s at %s " % (j[1],
                                                          j[2],
                                                          j[5],
                                                          timestr
                                                          )
                    mail_send(messages)
    print "insert databases info   done!"
示例#7
0
def war_in_db():
    # srv_list = zbx_srv.objects.filter(ip="219.134.132.194")
    if not get_srv_list:
        srv_list = zbx_srv.objects.all()
    else:
        for srv in get_srv_list:
            srv_list = zbx_srv.objects.filter(name=srv)
    print "zabbix get info hosts: ", len(srv_list)
    for i in srv_list:
        print "connect to ... ", i.ip, i.port
        conn_chk = connect_chk(i.ip, int(i.port))
        i.status = conn_chk
        i.save()
        if conn_chk:
            res_host = zbx_con(i.ip, i.port, "war")
        else:
            print i.name, "connection fail..."
            continue
        t_now = time.time()
        ch_nt = datetime.datetime.utcfromtimestamp(t_now)
        ch_at = timezone.make_aware(ch_nt, TZ)
        Issues.objects.filter(locate=i.name).filter(resolve=0).update(
            resolve=1, resolvetime=ch_at)
        if not res_host:
            db, sta = Issues.objects.get_or_create(
                locate=i.name,
                hostname="---all  hosts---",
                desciptions="No warnning messages!",
                level=1)
            db.resolve = 1
            db.resolvetime = ch_at
            db.problemtime = ch_at
            db.save()
            print timezone.now(), i.name, "All good!"
            continue
        for j in res_host:
            d_if = re.findall(
                "Free disk space is less than \d{,2}% on volume /data", j[2])
            if "dn" in j[0] and d_if:
                continue
            # ch_t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(j[1]))
            ch_nt = datetime.datetime.utcfromtimestamp(int(j[1]))
            ch_at = timezone.make_aware(ch_nt, TZ)
            des = j[2].replace("{HOST.NAME}", j[0])
            db, sta = Issues.objects.get_or_create(locate=i.name,
                                                   hostname=j[0],
                                                   desciptions=des,
                                                   problemtime=ch_at,
                                                   level=int(j[3]))
            db.resolve = 0
            db.resolvetime = ch_at
            db.save()
            if "hjdl" in j[0]:
                hj_mail_send(des)
        print timezone.now(), i.name, "get warnning!"
示例#8
0
def net_chk():
    if not get_srv_list:
        srv_list = zbx_srv.objects.all()
    else:
        for srv in get_srv_list:
            srv_list = zbx_srv.objects.filter(name=srv)
    print "zabbix get info hosts: ", len(srv_list)
    for i in srv_list:
        print "connect to ... ", i.ip, i.port
        conn_chk = connect_chk(i.ip, int(i.port))
        i.status = conn_chk
        i.save()
示例#9
0
def net_chk():
    if not get_srv_list:
        srv_list = zbx_srv.objects.all()
    else:
        for srv in get_srv_list:
            srv_list = zbx_srv.objects.filter(name=srv)
    print "zabbix get info hosts: ", len(srv_list)
    for i in srv_list:
        print "connect to ... ", i.ip, i.port
        conn_chk = connect_chk(i.ip, int(i.port))
        i.status = conn_chk
        i.save()
示例#10
0
def ora_in_db():
    if not get_srv_list:
        srv_list = zbx_srv.objects.all()
    else:
        for srv in get_srv_list:
            srv_list = zbx_srv.objects.filter(name=srv)
    print "zabbix get ora db info: ", len(srv_list)
    for i in srv_list:
        mail_sta = 0
        print "connect to ... ", i.ip, i.port
        conn_chk = connect_chk(i.ip, int(i.port))
        i.status = conn_chk
        i.save()
        if conn_chk:
            res_srvinfo = zbx_con(i.ip, i.port, "oradb")
            print "get db info..."
            print res_srvinfo
        else:
            print i.name, "connection fail..."
            continue
        if not res_srvinfo:
            continue
        else:
            for j in res_srvinfo:
                timestr = time.strftime("%Y-%m-%d %H:%M:%S",
                                        time.localtime(int(j[4])))
                db, sta = ora_db.objects.get_or_create(zbx_srv_name=i.name,
                                                       host_id=j[0],
                                                       keyname=j[3])
                db.host_name = j[1]
                db.desciptions = j[2]
                db.checktime = timestr
                db.status = int(j[5])
                if int(time.time()) - int(j[4]) > 1200:
                    db.recv_state = 0
                    if mail_sta == 0:
                        messages = "Host: %s %s No data revice at %s, please check. " % (
                            j[1],
                            j[2],
                            time.strftime('%Y-%m-%d %H:%M:%S',
                                          time.localtime(int(time.time()))),
                        )
                        mail_send(messages)
                        mail_sta = 1
                else:
                    db.recv_state = 1
                db.save()
                if int(j[5]) == 0:
                    messages = "Host: %s %s %s at %s " % (j[1], j[2], j[5],
                                                          timestr)
                    mail_send(messages)
    print "insert databases info   done!"
示例#11
0
def cre_free_temp():
    # get_srv_list = ["219.134.132.194"]
    if not get_srv_list:
        srv_list = zbx_srv.objects.all()
    else:
        for srv in get_srv_list:
            srv_list = zbx_srv.objects.filter(ip=srv)
    print "zabbix create  free temp table: ", len(srv_list)
    for i in srv_list:
        print "connect to ... ", i.ip, i.port
        conn_chk = connect_chk(i.ip, int(i.port))
        i.status = conn_chk
        i.save()
        if conn_chk:
            res_srvinfo = zbx_con(i.ip, i.port, "cre_free_tmp")
        else:
            print i.name, "connection fail..."
            continue
        if not res_srvinfo:
            print "create free  table succese: ", i.ip
示例#12
0
def cre_free_temp():
    # get_srv_list = ["219.134.132.194"]
    if not get_srv_list:
        srv_list = zbx_srv.objects.all()
    else:
        for srv in get_srv_list:
            srv_list = zbx_srv.objects.filter(ip=srv)
    print "zabbix create  free temp table: ", len(srv_list)
    for i in srv_list:
        print "connect to ... ", i.ip, i.port
        conn_chk = connect_chk(i.ip, int(i.port))
        i.status = conn_chk
        i.save()
        if conn_chk:
            res_srvinfo = zbx_con(i.ip, i.port, "cre_free_tmp")
        else:
            print i.name, "connection fail..."
            continue
        if not res_srvinfo:
            print "create free  table succese: ", i.ip
示例#13
0
def srv_in_db():
    if not get_srv_list:
        srv_list = zbx_srv.objects.all()
    else:
        for srv in get_srv_list:
            srv_list = zbx_srv.objects.filter(name=srv)
    print "zabbix get server info: ", len(srv_list)
    for i in srv_list:
        print "connect to ... ", i.ip, i.port
        conn_chk = connect_chk(i.ip, int(i.port))
        i.status = conn_chk
        i.save()
        if conn_chk:
            res_srvinfo = zbx_con(i.ip, i.port, "status")
        else:
            print i.name, "connection fail..."
            continue
        i.templates = res_srvinfo["templates"]
        i.hosts_total = res_srvinfo["host"]
        i.dis_hosts = res_srvinfo["disable"]
        i.proxy = res_srvinfo["proxy"]
        i.save()
        print "get server info success : ", i.name
示例#14
0
def srv_in_db():
    if not get_srv_list:
        srv_list = zbx_srv.objects.all()
    else:
        for srv in get_srv_list:
            srv_list = zbx_srv.objects.filter(name=srv)
    print "zabbix get server info: ", len(srv_list)
    for i in srv_list:
        print "connect to ... ", i.ip, i.port
        conn_chk = connect_chk(i.ip, int(i.port))
        i.status = conn_chk
        i.save()
        if conn_chk:
            res_srvinfo = zbx_con(i.ip, i.port, "status")
        else:
            print i.name, "connection fail..."
            continue
        i.templates = res_srvinfo["templates"]
        i.hosts_total = res_srvinfo["host"]
        i.dis_hosts = res_srvinfo["disable"]
        i.proxy = res_srvinfo["proxy"]
        i.save()
        print "get server info success : ", i.name