Trees | Indices | Help |
|
---|
|
1 ########################################################################### 2 # 3 # This program is part of Zenoss Core, an open source monitoring platform. 4 # Copyright (C) 2011 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__ = '''SnmpTrapConfig 15 16 Provides configuration for an OID translation service. 17 ''' 18 19 import logging 20 log = logging.getLogger('zen.HubService.SnmpTrapConfig') 21 22 import Globals 23 24 from twisted.spread import pb 25 from twisted.internet import reactor, defer 26 27 from Products.ZenCollector.services.config import CollectorConfigService 28 from Products.ZenHub.zodb import onUpdate, onDelete 29 30 from Products.ZenModel.Device import Device 31 from Products.ZenModel.DeviceClass import DeviceClass 32 from Products.ZenModel.MibBase import MibBase 33 from Products.Zuul.interfaces import ICatalogTool 34 35 SNMPV3_USER_ZPROPS = ["zSnmpEngineId", 36 "zSnmpSecurityName", 37 "zSnmpAuthType", 38 "zSnmpAuthPassword", 39 "zSnmpPrivType", 40 "zSnmpPrivPassword", 41 ]44 id = 'MIB payload'4547 version = None 48 engine_id = None 49 username = None 50 authentication_type = None # MD5 or SHA 51 authentication_passphrase = None 52 privacy_protocol = None # DES or AES 53 privacy_passphrase = None57 pb.setUnjellyableForClass(User, User)60130 131 132 if __name__ == '__main__': 133 from pprint import pprint 134 from Products.ZenHub.ServiceTester import ServiceTester62 return [ FakeDevice() ]6365 proxy = CollectorConfigService._createDeviceProxy(self, device) 66 proxy.configCycleInterval = 3600 67 proxy.name = "SNMP Trap Configuration" 68 proxy.device = device.id 69 70 # Gather all OID -> Name mappings from /Mibs catalog 71 proxy.oidMap = dict( 72 (b.oid, b.id) for b in self.dmd.Mibs.mibSearch() if b.oid 73 ) 74 75 return proxy76 77 @defer.inlineCallbacks79 80 # if v3 and has at least one v3 user property, then we want to create a user 81 if obj.getProperty("zSnmpVer", None) == "v3": 82 has_user = any(obj.hasProperty(zprop) for zprop in SNMPV3_USER_ZPROPS) 83 else: 84 has_user = False 85 86 if has_user: 87 # only send v3 users that have at least one local zProp defined 88 user = User() 89 user.version = int(obj.zSnmpVer[1]) 90 user.engine_id = obj.zSnmpEngineId 91 user.username = obj.zSnmpSecurityName 92 user.authentication_type = obj.zSnmpAuthType 93 user.authentication_passphrase = obj.zSnmpAuthPassword 94 user.privacy_protocol = obj.zSnmpPrivType 95 user.privacy_passphrase = obj.zSnmpPrivPassword 96 for listener in self.listeners: 97 yield listener.callRemote('createUser', user) 98 else: 99 # give way in the reactor loop while walking all users 100 d = defer.Deferred() 101 reactor.callLater(0, d.callback, None) 102 yield d103105 cat = ICatalogTool(self.dmd) 106 brains = cat.search(("Products.ZenModel.Device.Device", "Products.ZenModel.DeviceClass.DeviceClass")) 107 for brain in brains: 108 device = brain.getObject() 109 self._create_user(device)110 111 @onUpdate(DeviceClass)113 self._create_user(object)114 115 @onUpdate(Device)117 self._create_user(object)118 119 @onUpdate(MibBase)121 for listener in self.listeners: 122 listener.callRemote('notifyConfigChanged') 123 self._procrastinator.doLater()124 125 @onDelete(MibBase)127 for listener in self.listeners: 128 listener.callRemote('notifyConfigChanged') 129 self._procrastinator.doLater()176 177 tester = TrapTester(SnmpTrapConfig) 178 tester.run() 179138 ServiceTester.buildOptions(self) 139 self.parser.add_option('--resolve', dest='request', 140 help="Specify a specific OID or name to map to the name or OID.") 141 self.parser.add_option('--exactMatch', dest='exactMatch', 142 action='store_true', default=True, 143 help="When resolving to name, use an exact match") 144 self.parser.add_option('--fuzzyMatch', dest='exactMatch', 145 action='store_false', 146 help="When resolving to name, don't use an exact match") 147 self.parser.add_option('--list', dest='list', 148 action='store_true', default=False, 149 help="List all OIDs?")150152 name = self.dmd.Mibs.oid2name(self.options.request, 153 exactMatch=self.options.exactMatch) 154 if name: 155 log.info("\t%s => %s", self.options.request, name) 156 157 oid = self.dmd.Mibs.name2oid(self.options.request) 158 if oid: 159 log.info("\t%s => %s", self.options.request, oid)160 165 168170 if self.options.request: 171 self.resolve() 172 elif self.options.list: 173 self.list() 174 else: 175 self.showDeviceInfo()
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1.1812 on Tue Oct 11 12:51:40 2011 | http://epydoc.sourceforge.net |