[zenoss-users] 'Event' object has no attribute. dotted decimal IPv6
-> hex
gentux31
tijmen.vandenbrink at gmail.com
Fri May 30 06:08:58 EDT 2008
Dear all,
I want to transform a bgpBackwardTransition with a dotted decimal IPv6 address to the normal hex addres. I wrote a python script that I call from the event transform. This is my event transform:
Code:
from socket import gethostbyaddr
from decToHex import *
for attr in dir(evt):
if attr.startswith('1.3.6.1.2.1.15.3.1.14.'):
evt.bgpPeerIp = attr.replace('1.3.6.1.2.1.15.3.1.14.', '')
if len(evt.bgpPeerIp) > 15:
evt.bgpPeerIp = printIPv6(evt.bgpPeerIp)
try:
evt.bgpPeerName = gethostbyaddr(evt.bgpPeerIp)[0]
except:
pass
evt.summary = "bgpBackwardTransNotification from " + evt.bgpPeerIp + " (" + evt.bgpPeerName + ")"
In zentrap.log I can see the following:
ERROR zen.Events: Error transforming EventClassInst bgpBackwardTransition ('Event' object has no attribute 'bgpPeerName')
But I don't know why it complains about the event object not having the attribute bgpPeerName. I just created it saying:
evt.bgpPeerName = gethostbyaddr(evt.bgpPeerIp)[0]
Just to share here is the decToHex code:
Code:
import string
import sys
from IPy import IP
def printIPv6(ip):
"""Print the IPv6 address"""
array_ip = ip.split('.')
i = 0
ipv6_address = ""
while i < 14:
ipv6_address = ipv6_address + decToHex(array_ip[i], array_ip[i+1]) + ":"
i = i+2
ipv6_address = ipv6_address + decToHex(array_ip[14], array_ip[15])
return ipv6_address
def toHex(i):
"""Convert an int into a hex string (without the leading 0x)"""
return hex(i)[2:]
def decToHex(a, b):
"""Convert a decimal dotted IPv6 addresses to a regular/hexadecimal IPv6 address"""
if int(a) == 0:
if int(b) == 0:
return toHex(int(a))
else:
return toHex(int(b))
elif (int(b)) < 10:
return toHex(int(a)) + "0" + toHex(int(b))
else:
return toHex(int(a)) + toHex(int(b))
Any thought on how to fix this? Because the event transform is not working. Thanks all!
-------------------- m2f --------------------
Read this topic online here:
http://community.zenoss.com/forums/viewtopic.php?p=20652#20652
-------------------- m2f --------------------
More information about the zenoss-users
mailing list