heartbeatAgent.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:djangoStatusPanel 作者: okar1 项目源码 文件源码
def _snmpFormatValue(v):
    _type=type(v)
    if _type is NoSuchObject:
        res="?????? ???????? OID"
    elif sum([issubclass(_type,baseType) for baseType in [TimeTicks,Integer,Integer32,Gauge32,Counter32,Counter64,Unsigned32]]):
        res=int(v)
    elif sum([issubclass(_type,baseType) for baseType in [ObjectIdentity,ObjectIdentifier,IpAddress]]):
        res=str(v.prettyPrint())
    elif sum([issubclass(_type,baseType) for baseType in [OctetString]]):
        pp=v.prettyPrint()
        s=str(v)
        # sometimes prettyPrint returns hex values instead of string because of trailing 00 byte
        # if we got not a string - try to remove trailing 00
        # if we got a string after it - use this value
        if pp!=s:
            if len(v)>0:
                if v[len(v)-1]==0:
                    v2=v[:len(v)-1]
                    pp2=v2.prettyPrint()
                    s2=str(v2)
                    if pp2==s2:
                        v=v2
        res=v.prettyPrint()
    else:
        res="??????????? ??? ?????? "+str(_type)

    # if issubclass(_type,OctetString):
    #     print("v=",v)
    #     # print("res=",res)
    #     print("pp=",v.prettyPrint())
    #     print("bytes=",v.asOctets())
    #     print("bytes-decode=",v.asOctets().decode('iso-8859-1'))
    #     print("str=",str(v))
    #     print("hex=",binascii.hexlify(v.asOctets()).decode("utf8"))
    return res
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号