1
2
3
4
5
6
7
8
9
10
11
12
13
14 import types
15
16 from Globals import DTMLFile
17 from Globals import InitializeClass
18 from AccessControl import ClassSecurityInfo
19 from AccessControl import Permissions
20 from Products.ZenModel.ZenossSecurity import *
21
22 from Products.ZenRelations.RelSchema import *
23 from Products.ZenUtils.Search import makeCaseInsensitiveKeywordIndex
24 from Products.ZenWidgets import messaging
25
26 from Organizer import Organizer
27 from MibModule import MibModule
28 from ZenPackable import ZenPackable
29
37
38 addMibOrganizer = DTMLFile('dtml/addMibOrganizer',globals())
39
40
41 -def _oid2name(mibSearch, oid, exactMatch=True, strip=False):
42 """Return a name for an oid. This function is extracted out of the
43 MibOrganizer class and takes mibSearch as a parameter to make it easier to
44 unit test.
45 """
46 oid = oid.strip('.')
47
48 if exactMatch:
49 brains = mibSearch(oid=oid)
50 if len(brains) > 0:
51 return brains[0].id
52 else:
53 return ""
54
55 oidlist = oid.split('.')
56 for i in range(len(oidlist), 0, -1):
57 brains = mibSearch(oid='.'.join(oidlist[:i]))
58 if len(brains) < 1: continue
59 if len(oidlist[i:]) > 0 and not strip:
60 return "%s.%s" % (brains[0].id, '.'.join(oidlist[i:]))
61 else:
62 return brains[0].id
63 return ""
64
65
67 """
68 DeviceOrganizer is the base class for device organizers.
69 It has lots of methods for rolling up device statistics and information.
70 """
71 meta_type = "MibOrganizer"
72 dmdRootName = "Mibs"
73 default_catalog = 'mibSearch'
74
75 security = ClassSecurityInfo()
76
77 _relations = Organizer._relations + ZenPackable._relations + (
78 ("mibs", ToManyCont(ToOne,"Products.ZenModel.MibModule","miborganizer")),
79 )
80
81
82
83 factory_type_information = (
84 {
85 'immediate_view' : 'mibOrganizerOverview',
86 'actions' :
87 (
88 { 'id' : 'overview'
89 , 'name' : 'Overview'
90 , 'action' : 'mibOrganizerOverview'
91 , 'permissions' : ( Permissions.view, )
92 },
93 { 'id' : 'viewHistory'
94 , 'name' : 'Modifications'
95 , 'action' : 'viewHistory'
96 , 'permissions' : (ZEN_VIEW_MODIFICATIONS,)
97 },
98 )
99 },
100 )
101
102
108
109
110 - def oid2name(self, oid, exactMatch=True, strip=False):
115
116
118 """Return an oid based on a name in the form MIB::name.
119 """
120 brains = self.getDmdRoot("Mibs").mibSearch({'id': name})
121 if len(brains) > 0: return brains[0].oid
122 return ""
123
124
132
133
145
146
160
161
163 """Remove MibModules from an EventClass.
164 """
165 if not ids: return self()
166 if type(ids) == types.StringType: ids = (ids,)
167 for id in ids:
168 self.mibs._delObject(id)
169 if REQUEST:
170 messaging.IMessageSender(self).sendToBrowser(
171 'Mib Module Deleted',
172 'Mib modules deleted: %s' % ', '.join(ids)
173 )
174 return self()
175
176
194
195
197 """Go through all devices in this tree and reindex them."""
198 zcat = self._getOb(self.default_catalog)
199 zcat.manage_catalogClear()
200 for org in [self,] + self.getSubOrganizers():
201 for mib in org.mibs():
202 for thing in mib.nodes() + mib.notifications():
203 thing.index_object()
204
205
220
221
222
223
224 InitializeClass(MibOrganizer)
225