Package Products :: Package ZenModel :: Module MibModule
[hide private]
[frames] | no frames]

Source Code for Module Products.ZenModel.MibModule

  1  ############################################################################## 
  2  #  
  3  # Copyright (C) Zenoss, Inc. 2007, all rights reserved. 
  4  #  
  5  # This content is made available according to terms specified in 
  6  # License.zenoss under the directory where your Zenoss product is installed. 
  7  #  
  8  ############################################################################## 
  9   
 10   
 11  from Globals import InitializeClass 
 12  from AccessControl import ClassSecurityInfo 
 13  from AccessControl import Permissions 
 14  from zope.interface import implements 
 15   
 16  from Products.ZenRelations.RelSchema import * 
 17  from Products.ZenWidgets import messaging 
 18   
 19  from Products.ZenModel.interfaces import IIndexed 
 20  from Products.ZenModel.ZenossSecurity import * 
 21  from ZenModelRM import ZenModelRM 
 22  from ZenPackable import ZenPackable 
 23   
 24   
25 -class MibModule(ZenModelRM, ZenPackable):
26 27 implements(IIndexed) 28 types = ('COUNTER', 'GAUGE', 'DERIVE', 'ABSOLUTE') 29 30 language = "" 31 contact = "" 32 description = "" 33 34 _properties = ( 35 {'id':'language', 'type':'string', 'mode':'w'}, 36 {'id':'contact', 'type':'string', 'mode':'w'}, 37 {'id':'description', 'type':'string', 'mode':'w'}, 38 ) 39 40 _relations = ZenPackable._relations + ( 41 ("miborganizer", ToOne(ToManyCont, "Products.ZenModel.MibOrganizer", "mibs")), 42 ("nodes", ToManyCont(ToOne, "Products.ZenModel.MibNode", "module")), 43 ("notifications", ToManyCont(ToOne, "Products.ZenModel.MibNotification", "module")), 44 ) 45 46 # Screen action bindings (and tab definitions) 47 factory_type_information = ( 48 { 49 'immediate_view' : 'viewMibModule', 50 'actions' : 51 ( 52 { 'id' : 'overview' 53 , 'name' : 'Overview' 54 , 'action' : 'viewMibModule' 55 , 'permissions' : ( Permissions.view, ) 56 }, 57 { 'id' : 'edit' 58 , 'name' : 'Edit' 59 , 'action' : 'editMibModule' 60 , 'permissions' : ( Permissions.view, ) 61 }, 62 ) 63 }, 64 ) 65 66 security = ClassSecurityInfo() 67
68 - def getModuleName(self):
69 return self.id
70 71
72 - def nodeCount(self):
73 return self.nodes.countObjects()
74 75
76 - def notificationCount(self):
77 return self.notifications.countObjects()
78 79
80 - def deleteMibNodes(self, ids=[], REQUEST=None):
81 """Delete MibNodes 82 """ 83 for node in self.nodes(): 84 id = getattr(node, 'id', None) 85 if id in ids: 86 self.nodes._delObject(id) 87 if REQUEST: 88 messaging.IMessageSender(self).sendToBrowser( 89 'Mappings Deleted', 90 'Mib nodes deleted: %s' % (', '.join(ids)) 91 ) 92 return self.callZenScreen(REQUEST)
93 94
95 - def addMibNode(self, id, oid, nodetype, REQUEST=None):
96 """Add a MibNode 97 """ 98 node = self.createMibNode(id, oid=oid, nodetype=nodetype) 99 if REQUEST: 100 if node: 101 messaging.IMessageSender(self).sendToBrowser( 102 'Mib Node Added', 103 'Node %s was created with oid %s.' % (id, oid) 104 ) 105 else: 106 messaging.IMessageSender(self).sendToBrowser( 107 'Invalid OID', 108 'OID %s is invalid.' % oid, 109 priority=messaging.WARNING 110 ) 111 return self.callZenScreen(REQUEST)
112 113
114 - def createMibNode(self, id, **kwargs):
115 """Create a MibNotification 116 """ 117 from MibNode import MibNode 118 if self.oid2name(kwargs['oid'], exactMatch=True, strip=False): 119 return None 120 node = MibNode(id, **kwargs) 121 self.nodes._setObject(node.id, node) 122 node = self.nodes._getOb(node.id) 123 return node
124 125
126 - def deleteMibNotifications(self, ids=[], REQUEST=None):
127 """Delete MibNotifications 128 """ 129 for notification in self.notifications(): 130 id = getattr(notification, 'id', None) 131 if id in ids: 132 self.notifications._delObject(id) 133 if REQUEST: 134 messaging.IMessageSender(self).sendToBrowser( 135 'Traps Deleted', 136 'Traps deleted: %s' % (', '.join(ids)) 137 ) 138 return self.callZenScreen(REQUEST)
139 140
141 - def addMibNotification(self, id, oid, nodetype, REQUEST=None):
142 """Add a MibNotification 143 """ 144 notification = self.createMibNotification(id, oid=oid, nodetype=nodetype) 145 if REQUEST: 146 if notification: 147 messaging.IMessageSender(self).sendToBrowser( 148 'Trap added', 149 'Trap %s was created with oid %s.' % (id, oid) 150 ) 151 else: 152 messaging.IMessageSender(self).sendToBrowser( 153 'Invalid OID', 154 'OID %s is invalid.' % oid, 155 priority=messaging.WARNING 156 ) 157 return self.callZenScreen(REQUEST)
158 159
160 - def createMibNotification(self, id, **kwargs):
161 """Create a MibNotification 162 """ 163 from MibNotification import MibNotification 164 if self.oid2name(kwargs['oid'], exactMatch=True, strip=False): 165 return None 166 node = MibNotification(id, **kwargs) 167 self.notifications._setObject(node.id, node) 168 node = self.notifications._getOb(node.id) 169 return node
170 171 172 InitializeClass(MibModule) 173