| Trees | Indices | Help |
|
|---|
|
|
1 ##############################################################################
2 #
3 # Copyright (C) Zenoss, Inc. 2011, 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 __doc__ = '''SnmpTrapConfig
12
13 Provides configuration for an OID translation service.
14 '''
15
16 import logging
17 log = logging.getLogger('zen.HubService.SnmpTrapConfig')
18
19 import Globals
20
21 from twisted.spread import pb
22 from twisted.internet import reactor, defer
23
24 from Products.ZenCollector.services.config import CollectorConfigService
25 from Products.ZenHub.zodb import onUpdate, onDelete
26
27 from Products.ZenModel.Device import Device
28 from Products.ZenModel.DeviceClass import DeviceClass
29 from Products.ZenModel.MibBase import MibBase
30 from Products.Zuul.interfaces import ICatalogTool
31
32 SNMPV3_USER_ZPROPS = ["zSnmpEngineId",
33 "zSnmpSecurityName",
34 "zSnmpAuthType",
35 "zSnmpAuthPassword",
36 "zSnmpPrivType",
37 "zSnmpPrivPassword",
38 ]
41 id = 'MIB payload'
42
44 version = None
45 engine_id = None
46 username = None
47 authentication_type = None # MD5 or SHA
48 authentication_passphrase = None
49 privacy_protocol = None # DES or AES
50 privacy_passphrase = None
54 pb.setUnjellyableForClass(User, User)
57
59 return [ FakeDevice() ]
60
62 proxy = CollectorConfigService._createDeviceProxy(self, device)
63 proxy.configCycleInterval = 3600
64 proxy.name = "SNMP Trap Configuration"
65 proxy.device = device.id
66
67 # Gather all OID -> Name mappings from /Mibs catalog
68 proxy.oidMap = dict(
69 (b.oid, b.id) for b in self.dmd.Mibs.mibSearch() if b.oid
70 )
71
72 return proxy
73
74 @defer.inlineCallbacks
76
77 # if v3 and has at least one v3 user property, then we want to create a user
78 if obj.getProperty("zSnmpVer", None) == "v3":
79 has_user = any(obj.hasProperty(zprop) for zprop in SNMPV3_USER_ZPROPS)
80 else:
81 has_user = False
82
83 if has_user:
84 # only send v3 users that have at least one local zProp defined
85 user = User()
86 user.version = int(obj.zSnmpVer[1])
87 user.engine_id = obj.zSnmpEngineId
88 user.username = obj.zSnmpSecurityName
89 user.authentication_type = obj.zSnmpAuthType
90 user.authentication_passphrase = obj.zSnmpAuthPassword
91 user.privacy_protocol = obj.zSnmpPrivType
92 user.privacy_passphrase = obj.zSnmpPrivPassword
93 for listener in self.listeners:
94 yield listener.callRemote('createUser', user)
95 else:
96 # give way in the reactor loop while walking all users
97 d = defer.Deferred()
98 reactor.callLater(0, d.callback, None)
99 yield d
100
102 cat = ICatalogTool(self.dmd)
103 brains = cat.search(("Products.ZenModel.Device.Device", "Products.ZenModel.DeviceClass.DeviceClass"))
104 for brain in brains:
105 device = brain.getObject()
106 self._create_user(device)
107
108 @onUpdate(DeviceClass)
111
112 @onUpdate(Device)
115
116 @onUpdate(MibBase)
120
121 @onDelete(MibBase)
125
126
127 if __name__ == '__main__':
128 from pprint import pprint
129 from Products.ZenHub.ServiceTester import ServiceTester
133 ServiceTester.buildOptions(self)
134 self.parser.add_option('--resolve', dest='request',
135 help="Specify a specific OID or name to map to the name or OID.")
136 self.parser.add_option('--exactMatch', dest='exactMatch',
137 action='store_true', default=True,
138 help="When resolving to name, use an exact match")
139 self.parser.add_option('--fuzzyMatch', dest='exactMatch',
140 action='store_false',
141 help="When resolving to name, don't use an exact match")
142 self.parser.add_option('--list', dest='list',
143 action='store_true', default=False,
144 help="List all OIDs?")
145
147 name = self.dmd.Mibs.oid2name(self.options.request,
148 exactMatch=self.options.exactMatch)
149 if name:
150 log.info("\t%s => %s", self.options.request, name)
151
152 oid = self.dmd.Mibs.name2oid(self.options.request)
153 if oid:
154 log.info("\t%s => %s", self.options.request, oid)
155
160
163
165 if self.options.request:
166 self.resolve()
167 elif self.options.list:
168 self.list()
169 else:
170 self.showDeviceInfo()
171
172 tester = TrapTester(SnmpTrapConfig)
173 tester.run()
174
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1.1812 on Mon Jul 30 17:11:32 2012 | http://epydoc.sourceforge.net |