Package ZenModel :: Module MibOrganizer
[hide private]
[frames] | no frames]

Source Code for Module ZenModel.MibOrganizer

  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 as published by 
  8  # the Free Software Foundation. 
  9  # 
 10  # For complete information please visit: http://www.zenoss.com/oss/ 
 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 Acquisition import aq_base 
 21   
 22  from Products.ZenRelations.RelSchema import * 
 23  from Products.ZenUtils.Search import makeCaseInsensitiveKeywordIndex 
 24   
 25  from Organizer import Organizer 
 26  from MibModule import MibModule 
 27  from ZenPackable import ZenPackable 
 28   
29 -def manage_addMibOrganizer(context, id, REQUEST = None):
30 """make a device class""" 31 sc = MibOrganizer(id) 32 context._setObject(id, sc) 33 sc = context._getOb(id) 34 if REQUEST is not None: 35 REQUEST['RESPONSE'].redirect(context.absolute_url() + '/manage_main')
36 37 addMibOrganizer = DTMLFile('dtml/addMibOrganizer',globals()) 38 39
40 -class MibOrganizer(Organizer, ZenPackable):
41 """ 42 DeviceOrganizer is the base class for device organizers. 43 It has lots of methods for rolling up device statistics and information. 44 """ 45 meta_type = "MibOrganizer" 46 dmdRootName = "Mibs" 47 default_catalog = 'mibSearch' 48 49 security = ClassSecurityInfo() 50 51 _relations = Organizer._relations + ZenPackable._relations + ( 52 ("mibs", ToManyCont(ToOne,"Products.ZenModel.MibModule","miborganizer")), 53 ) 54 55 56 # Screen action bindings (and tab definitions) 57 factory_type_information = ( 58 { 59 'immediate_view' : 'mibOrganizerOverview', 60 'actions' : 61 ( 62 { 'id' : 'overview' 63 , 'name' : 'Overview' 64 , 'action' : 'mibOrganizerOverview' 65 , 'permissions' : ( Permissions.view, ) 66 }, 67 { 'id' : 'viewHistory' 68 , 'name' : 'Modifications' 69 , 'action' : 'viewHistory' 70 , 'permissions' : ( Permissions.view, ) 71 }, 72 ) 73 }, 74 ) 75 76
77 - def __init__(self, id=None):
78 if not id: id = self.dmdRootName 79 super(MibOrganizer, self).__init__(id) 80 if self.id == self.dmdRootName: 81 self.createCatalog()
82 83
84 - def oid2name(self, oid):
85 """Return a name in for and oid. 86 """ 87 brains = self.getDmdRoot("Mibs").mibSearch({'oid': oid}) 88 if len(brains) > 0: return brains[0].id 89 return ""
90 91
92 - def name2oid(self, name):
93 """Return an oid based on a name in the form MIB::name. 94 """ 95 brains = self.getDmdRoot("Mibs").mibSearch({'id': name}) 96 if len(brains) > 0: return brains[0].oid 97 return ""
98 99
100 - def countClasses(self):
101 """Count all mibs with in a MibOrganizer. 102 """ 103 count = self.mibs.countObjects() 104 for group in self.children(): 105 count += group.countClasses() 106 return count
107 108
109 - def createMibModule(self, name, path="/"):
110 """Create a MibModule 111 """ 112 mibs = self.getDmdRoot(self.dmdRootName) 113 mod = None 114 if not mod: 115 modorg = mibs.createOrganizer(path) 116 mod = MibModule(name) 117 modorg.mibs._setObject(mod.id, mod) 118 mod = modorg.mibs._getOb(mod.id) 119 return mod
120 121
122 - def manage_addMibModule(self, id, REQUEST=None):
123 """Create a new service class in this Organizer. 124 """ 125 mm = MibModule(id) 126 self.mibs._setObject(id, mm) 127 if REQUEST: 128 REQUEST['message'] = "Mib Module created" 129 return self.callZenScreen(REQUEST) 130 else: 131 return self.mibs._getOb(id)
132 133
134 - def removeMibModules(self, ids=None, REQUEST=None):
135 """Remove MibModules from an EventClass. 136 """ 137 if not ids: return self() 138 if type(ids) == types.StringType: ids = (ids,) 139 for id in ids: 140 self.mibs._delObject(id) 141 if REQUEST: 142 REQUEST['message'] = "Mib Module deleted" 143 return self()
144 145
146 - def moveMibModules(self, moveTarget, ids=None, REQUEST=None):
147 """Move MibModules from this EventClass to moveTarget. 148 """ 149 if not moveTarget or not ids: return self() 150 if type(ids) == types.StringType: ids = (ids,) 151 target = self.getChildMoveTarget(moveTarget) 152 for id in ids: 153 rec = self.mibs._getOb(id) 154 rec._operation = 1 # moving object state 155 self.mibs._delObject(id) 156 target.mibs._setObject(id, rec) 157 if REQUEST: 158 REQUEST['message'] = "Mib Module moved" 159 REQUEST['RESPONSE'].redirect(target.getPrimaryUrlPath())
160 161
162 - def reIndex(self):
163 """Go through all devices in this tree and reindex them.""" 164 zcat = self._getOb(self.default_catalog) 165 zcat.manage_catalogClear() 166 for mibmod in self.mibs(): 167 mibmod.index_object() 168 for miborg in self.getSubOrganizers(): 169 for mibmod in miborg.mibs(): 170 mibmod.index_object()
171 172
173 - def createCatalog(self):
174 """Create a catalog for mibs searching""" 175 from Products.ZCatalog.ZCatalog import manage_addZCatalog 176 177 # XXX update to use ManagableIndex 178 manage_addZCatalog(self, self.default_catalog, self.default_catalog) 179 zcat = self._getOb(self.default_catalog) 180 cat = zcat._catalog 181 cat.addIndex('oid', makeCaseInsensitiveKeywordIndex('oid')) 182 cat.addIndex('id', makeCaseInsensitiveKeywordIndex('id')) 183 cat.addIndex('summary', makeCaseInsensitiveKeywordIndex('summary')) 184 zcat.addColumn('getPrimaryId') 185 zcat.addColumn('id') 186 zcat.addColumn('oid')
187 188 189 190 191 InitializeClass(MibOrganizer) 192