本文整理汇总了Python中Products.ZenUtils.ZenScriptBase.ZenScriptBase.findDevice方法的典型用法代码示例。如果您正苦于以下问题:Python ZenScriptBase.findDevice方法的具体用法?Python ZenScriptBase.findDevice怎么用?Python ZenScriptBase.findDevice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Products.ZenUtils.ZenScriptBase.ZenScriptBase
的用法示例。
在下文中一共展示了ZenScriptBase.findDevice方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: processResults
# 需要导入模块: from Products.ZenUtils.ZenScriptBase import ZenScriptBase [as 别名]
# 或者: from Products.ZenUtils.ZenScriptBase.ZenScriptBase import findDevice [as 别名]
def processResults(self, cmd, result):
"""
Process the results for command "lsdrive -delim :".
"""
update = False
datapointMap = dict([(dp.id, dp) for dp in cmd.points])
devname = cmd.deviceConfig.device
# returned from datasource component field with ${here/id}
componentid = cmd.component
rresult = Utils.cmdParser(cmd.result.output,'id','DRIVE_ID')
# specific component device
rresult = rresult[componentid]
# drive status raise event
if rresult['status']!='online':
result.events.append(Utils.getEvent(cmd,"Drive status not online",clear=False))
update = True
# drive error sequence number
if rresult['error_sequence_number']!='':
result.events.append(Utils.getEvent(cmd,"Drive error sequence number: "+rresult['error_sequence_number'],clear=False))
update = True
# update current component if needed
if update:
scriptbase = ZenScriptBase(noopts = 1, connect = True)
device = scriptbase.findDevice(devname)
component = device.drives.findObjectsById(componentid)[0]
component.drive_status=rresult['status']
component.error_sequence_number=rresult['error_sequence_number']
commit()
示例2: processResults
# 需要导入模块: from Products.ZenUtils.ZenScriptBase import ZenScriptBase [as 别名]
# 或者: from Products.ZenUtils.ZenScriptBase.ZenScriptBase import findDevice [as 别名]
def processResults(self, cmd, result):
"""
Process the results for command "lsenclosurebattery -delim :".
"""
datapointMap = dict([(dp.id, dp) for dp in cmd.points])
devname = cmd.deviceConfig.device
# returned from datasource component field with ${here/id}
componentid = cmd.component
rresult = Utils.cmdParser(cmd.result.output,'battery_id','BAT_ID')
# specific component device
rresult = rresult[componentid]
# recondition_needed raise event
if rresult['recondition_needed']!='no':
result.events.append(Utils.getEvent(cmd,"Battery recondition needed",clear=False))
#Battery end of life warning raise event
if rresult['end_of_life_warning']!='no':
result.events.append(Utils.getEvent(cmd,"Battery end of life warning",clear=False))
# update current component
# zencommand does not have direct access to the model and components but
# maybe theres another way to do this
scriptbase = ZenScriptBase(noopts = 1, connect = True)
device = scriptbase.findDevice(devname)
component = device.batteries.findObjectsById(componentid)[0]
component.battery_status=rresult['status']
component.charging_status=rresult['charging_status']
component.recondition_needed=rresult['recondition_needed']
component.percent_charged=int(rresult['percent_charged'])
component.end_of_life_warning=rresult['end_of_life_warning']
commit()
示例3: processResults
# 需要导入模块: from Products.ZenUtils.ZenScriptBase import ZenScriptBase [as 别名]
# 或者: from Products.ZenUtils.ZenScriptBase.ZenScriptBase import findDevice [as 别名]
def processResults(self, cmd, results):
# split data into component blocks
lines = cmd.result.output.split('\n')
data = {}
for line in lines:
if len(line) == 0:
continue
splitted = line.split(' ')
if len(splitted) < 2:
continue
data[splitted[0]] = ' '.join(splitted[1:])
scriptbase = ZenScriptBase(noopts = 1, connect = True)
for point in cmd.points:
if point.id not in self.POINTS:
continue
if 'portid' not in point.data:
log.error("No port id provided: %s" % (point.id,))
continue
if 'snmpindex' not in point.data:
log.error("No snmpindex provided: %s" % (point.id,))
continue
oid = self.POINTS[point.id]
devname = cmd.deviceConfig.device
portid = point.data['portid']
snmpindex = point.data['snmpindex']
key = "%s.%d" % (oid, snmpindex,)
if key not in data:
continue
try:
value = float(data[key])
except ValueError:
continue
# Update current model
d = scriptbase.findDevice(devname)
if d is not None and d.getDeviceClassPath() == self.DEVICE_PATH:
port = d.SerialPrt._getOb(portid)
if port is not None:
log.debug("setattr(%s, %s, %s)" % (d, point.id, value,))
setattr(port, point.id, value)
id = d.SerialPrt._setObject(portid, port)
commit()
#print "*** _getOb(%s)" % (portid,)
#print pformat(d.SerialPrt._getOb(portid).__dict__)
else:
log.error("No such attribute: %s on %s" % (
point.id, d.getDeviceName(),))
log.debug("Appending result %s: (%s / %s) %s" % (
point.id, type(value), value, value,))
results.values.append((point, value,))
log.debug(pformat(results))
return results