1
2
3
4
5
6
7
8
9
10
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
27
41
42 addCollectionItem = DTMLFile('dtml/addCollectionItem',globals())
43
44
46
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','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()
82
83 - def __init__(self, id, deviceId='', compPath='', deviceOrganizer='',
84 recurse=False, sequence=0, title=None, buildRelations=True):
91
92
115
116
118 ''' Get the device organizer, component or device
119 that this collection item represents
120 '''
121 thing = None
122 if self.deviceId:
123 thing = self.dmd.Devices.findDevice(self.deviceId)
124 if self.compPath:
125 for part in self.compPath.split('/'):
126 if part:
127 thing = getattr(thing, part, None)
128 if not thing:
129 break
130 elif self.deviceOrganizer:
131 try:
132 thing = self.dmd.getObjByPath(self.deviceOrganizer.lstrip('/'))
133 except KeyError:
134 thing = None
135 return thing
136
137
139 ''' Return a list of the devices and components referenced by this item
140 '''
141 thing = self.getRepresentedItem()
142 if not thing:
143 stuff = []
144 elif self.deviceId:
145 stuff = [thing]
146 elif self.recurse:
147 stuff = thing.getSubDevices()
148 else:
149 stuff = thing.devices()
150 return stuff
151
152
154 ''' Return the number of devices and components matched by this item
155 '''
156 things = self.getDevicesAndComponents()
157 return len(things)
158
159
160
161 InitializeClass(CollectionItem)
162