Trees | Indices | Help |
|
---|
|
1 ########################################################################### 2 # 3 # This program is part of Zenoss Core, an open source monitoring platform. 4 # Copyright (C) 2007, Zenoss Inc. 5 # 6 # This program is free software; you can redistribute it and/or modify it 7 # under the terms of the GNU General Public License version 2 or (at your 8 # option) any later version as published by the Free Software Foundation. 9 # 10 # For complete information please visit: http://www.zenoss.com/oss/ 11 # 12 ########################################################################### 13 14 __doc__="""CollectionItem 15 16 Defines attributes for how a data source will be graphed 17 and builds the nessesary rrd commands. 18 """ 19 20 from Globals import InitializeClass 21 from Globals import DTMLFile 22 from AccessControl import ClassSecurityInfo, Permissions 23 from Products.ZenRelations.RelSchema import * 24 from ZenModelRM import ZenModelRM 25 from Products.ZenUtils.Utils import unused 26 2730 ''' This is here so than zope will let us copy/paste/rename 31 CollectionItems. 32 ''' 33 unused(deviceId, compPath, sequence) 34 ci = CollectionItem(id) 35 context._setObject(id, ci) 36 ci.deviceId = deviceId 37 ci.compPath = compPath 38 ci.sequence = sequence 39 if REQUEST is not None: 40 return REQUEST['RESPONSE'].redirect(context.absolute_url() +'/manage_main')41 42 addCollectionItem = DTMLFile('dtml/addCollectionItem',globals()) 43 4446 47 meta_type = 'CollectionItem' 48 49 sequence = 0 50 deviceId = '' 51 compPath = '' 52 deviceOrganizer = '' 53 recurse = False 54 55 _properties = ( 56 {'id':'sequence', 'type':'long', 'mode':'w'}, 57 {'id':'deviceId', 'type':'string', 'mode':'w'}, 58 {'id':'compPath', 'type':'string', 'mode':'w'}, 59 {'id':'deviceOrganizer', 'type':'string', 'mode':'w'}, 60 {'id':'recurse', 'type':'boolean', 'mode':'w'}, 61 ) 62 63 _relations = ( 64 ('collection', ToOne(ToManyCont,'Products.ZenModel.Collection','collection_items')), 65 ) 66 67 factory_type_information = ( 68 { 69 'immediate_view' : 'editCollectionItem', 70 'actions' : 71 ( 72 { 'id' : 'edit' 73 , 'name' : 'Collection Item' 74 , 'action' : 'editCollectionItem' 75 , 'permissions' : ( Permissions.view, ) 76 }, 77 ) 78 }, 79 ) 80 81 security = ClassSecurityInfo() 82160 161 162 163 InitializeClass(CollectionItem) 16483 - def __init__(self, id, deviceId='', compPath='', deviceOrganizer='', 84 recurse=False, sequence=0, title=None, buildRelations=True):85 ZenModelRM.__init__(self, id, title, buildRelations) 86 self.deviceId = deviceId 87 self.compPath = compPath 88 self.deviceOrganizer = deviceOrganizer 89 self.recurse = recurse 90 self.sequence = sequence91 9294 ''' Return a string that represents this item 95 ''' 96 thing = self.getRepresentedItem() 97 if not thing: 98 desc = 'missing' 99 elif self.deviceId: 100 if self.compPath: 101 name = callable(thing.name) and thing.name() or thing.name 102 desc = '%s %s' % (self.deviceId, name) 103 else: 104 desc = self.deviceId 105 if withLink and thing: 106 desc = '<a href="%s">%s</a>' % (thing.getPrimaryUrlPath(),desc) 107 else: 108 if withLink and thing: 109 desc = '<a href="%s">%s</a>' % (thing.getPrimaryUrlPath(), 110 self.deviceOrganizer) 111 else: 112 desc = self.deviceOrganizer 113 if self.recurse: 114 desc += ' and suborganizers' 115 return desc116 117119 ''' Get the device organizer, component or device 120 that this collection item represents 121 ''' 122 thing = None 123 if self.deviceId: 124 thing = self.dmd.Devices.findDevice(self.deviceId) 125 if self.compPath: 126 for part in self.compPath.split('/'): 127 if part: 128 thing = getattr(thing, part, None) 129 if not thing: 130 break 131 elif self.deviceOrganizer: 132 try: 133 thing = self.dmd.getObjByPath(self.deviceOrganizer.lstrip('/')) 134 except KeyError: 135 thing = None 136 return thing137 138140 ''' Return a list of the devices and components referenced by this item 141 ''' 142 thing = self.getRepresentedItem() 143 if not thing: 144 stuff = [] 145 elif self.deviceId: 146 stuff = [thing] 147 elif self.recurse: 148 stuff = thing.getSubDevices(lambda d: d.monitorDevice()) 149 else: 150 stuff = [ dev for dev in thing.devices() if dev.monitorDevice() ] 151 stuff.sort(lambda x, y: cmp(x.primarySortKey(), y.primarySortKey())) 152 return stuff153 154156 ''' Return the number of devices and components matched by this item 157 ''' 158 things = self.getDevicesAndComponents() 159 return len(things)
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1.1812 on Tue Oct 11 12:51:47 2011 | http://epydoc.sourceforge.net |