Hi everybody,
We monitor a couple of core routers that have interface description starting
with CU for customers and EX for external peerings.
What I'm trying to accomplish is the following:
When the interface description starts with CU or EX take the ip address of that
interface and pass it to IPy (nice module to process ip addresses). I then
check wether it's a /29 or /30 prefix.
If it's a /29 we now the customers ip address is (for example) the 3rd hosts
address in the network.
If it's a /30 we now the customers ip address is (for example) the 2nd hosts
address in the network.
However something seems to be wrong in my code.
Sometimes there is no ip address and I need to filter out the None. I'm fairly
new at python and I'm just a bit stuck here.
Maybe you can help me out. Here's my code:
Code:
#!/usr/bin/python
#!/usr/bin/python
import os
import sys
from IPy import IP
a = ['CU','EX']
for dev in dmd.Devices.SURFnet.SURFnet6.getSubDevices():
for interface in dev.os.interfaces():
for x in a:
if interface.description.startswith(x):
ip = str(interface.getIpAddress())
if ip.find("None"):
print "No IP configured"
else:
network = IP(ip, make_net=True)
array_ip = []
if ip.endswith("/30\n"):
for x in network:
array_ip.append(x)
print array_ip[2]
if ip.endswith("/29\n"):
for x in network:
array_ip.append(x)
print array_ip[2]
This is the error I get:
Code:
Welcome to zenoss dmd command shell!
use zhelp() to list commands
>>> ... >>> >>> >>> >>> >>> ... ... ... ... ... ... ... ... ... ... ... ... ...
>>> ... ... ... ... ... Traceback (most recent call last):
File "<stdin>", line 9, in ?
File "/usr/lib/python2.4/site-packages/IPy.py", line 192, in __init__
(self.ip, parsedVersion) = parseAddress(ip)
File "/usr/lib/python2.4/site-packages/IPy.py", line 1084, in parseAddress
ret = long(ipstr, 10)
ValueError: invalid literal for long(): None
>>>
I looks like IPy gets the string None where it expects a long. However it
shouldn't even get there or am I just totally wasted?
Thanks everybody!
-------------------- m2f --------------------
Read this topic online here:
http://community.zenoss.com/forums/viewtopic.php?p=19502#19502
-------------------- m2f --------------------
_______________________________________________
zenoss-users mailing list
[email protected]
http://lists.zenoss.org/mailman/listinfo/zenoss-users