#!/usr/bin/env python
import Globals
from Products.ZenUtils.ZenScriptBase import ZenScriptBase
from transaction import commit
dmd = ZenScriptBase(connect=True).dmd
find = dmd.Devices.findDevice
adslmac = '00:0E:50:88:34:E6'
found = False
for device in dmd.Devices.deviceSearch():
dev=find(device.id)
for devif in dev.os.interfaces():
devmac = devif.macaddress
print dev, devif, devmac
if devmac == adslmac:
name = dev.id
ip = dev.manageIp
found = True
print "Bingo ",name, ip
break
if found:
break
I take out the testing bits and put the following in a class definition file:
def getIpRemoteAddress(self):
dmd = ZenScriptBase(connect=True).dmd
found = False
IpRemote="Device not in Zenoss"
find = dmd.Devices.findDevice
for device in dmd.Devices.deviceSearch():
dev=find(device.id)
for devif in dev.os.interfaces():
devmac = devif.macaddress
if devmac == str(self.RemoteAddress):
IpRemote = dev.manageIp
found = True
break
if found:
break
return IpRemote
This barfs, not when I model the device, but when I go and look at the new tab which uses my getIpRemoteAddress function, with:
* Module TAL.TALInterpreter, line 406, in no_tag
* Module TAL.TALInterpreter, line 250, in interpret
* Module TAL.TALInterpreter, line 501, in do_insertText_tal
* Module Products.PageTemplates.TALES, line 227, in evaluateText
* Module Products.PageTemplates.TALES, line 221, in evaluate
URL: file:/usr/local/zenoss/zenoss/local/BridgeMib2/ZenPacks.skills1st.bridge/ZenPacks/skills1st/bridge/skins/ZenPacks.skills1st.bridge/BridgeDeviceDetail.pt
Line 49, Column 6
Expression: standard:'Bridge/getIpRemoteAddress'
Names:
{'container': <ZentinelPortal at /zport>,
'context': <BridgeDevice at /zport/dmd/Devices/Network/Switch/BridgeMIB/devices/switch.skills-1st.co.uk>,
'default': <Products.PageTemplates.TALES.Default instance at 0xb7370aac>,
'here': <BridgeDevice at /zport/dmd/Devices/Network/Switch/BridgeMIB/devices/switch.skills-1st.co.uk>,
'loop': <Products.PageTemplates.TALES.SafeMapping object at 0xb427114c>,
'modules': <Products.PageTemplates.ZRPythonExpr._SecureModuleImporter instance at 0xb7375b0c>,
'nothing': None,
'options': {'args': ()},
'repeat': <Products.PageTemplates.TALES.SafeMapping object at 0xb427114c>,
'request': <HTTPRequest, URL=http://zen233.class.example.org:8080/zport/dmd/Devices/Network/Switch/BridgeMIB/devices/switch.skills-1st.co.uk/BridgeDeviceDetail>,
'root': <Application at >,
'template': <FSPageTemplate at /zport/BridgeDeviceDetail used for /zport/dmd/Devices/Network/Switch/BridgeMIB/devices/switch.skills-1st.co.uk>,
'traverse_subpath': [],
'user': jane}
* Module Products.PageTemplates.Expressions, line 185, in __call__
* Module Products.PageTemplates.Expressions, line 180, in _eval
* Module Products.PageTemplates.Expressions, line 85, in render
* Module ZenPacks.skills1st.bridge.BridgeInterface, line 113, in getIpRemoteAddress
* Module Products.ZenUtils.ZenScriptBase, line 32, in __init__
* Module Products.ZenUtils.CmdBase, line 80, in __init__
* Module Products.ZenUtils.CmdBase, line 48, in parseconfig
ValueError: need more than 1 value to unpack
Line 113 of BridgeInterface.py is the
dmd = ZenScriptBase(connect=True).dmd
line. If I leave out the lines to define dmd (cos I though it should already know about that), then it barfs trying to find "find".
Any offers for where I am going wrong?
Any offers for a better more effective may to do this?
Cheers,
Jane