本文整理汇总了Python中pysnmp.entity.config.addNotificationTarget函数的典型用法代码示例。如果您正苦于以下问题:Python addNotificationTarget函数的具体用法?Python addNotificationTarget怎么用?Python addNotificationTarget使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了addNotificationTarget函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cfgNtfOrg
def cfgNtfOrg(self, authData, transportTarget, notifyType, tagList):
addrName, paramsName = self.cfgCmdGen(
authData, transportTarget, tagList
)
k = paramsName, tagList, notifyType
if self.__knownNotifyNames.has_key(k):
notifyName, _ = self.__knownNotifyNames[k]
else:
notifyName = 'n%s' % cmdgen.nextID()
config.addNotificationTarget(
self.snmpEngine,
notifyName,
paramsName,
tagList,
notifyType
)
self.__knownNotifyNames[k] = notifyName, paramsName
if not self.__knownAuths.has_key(authData):
subTree = (1,3,6)
config.addTrapUser(
self.snmpEngine,
authData.securityModel,
authData.securityName,
authData.securityLevel,
subTree
)
self.__knownAuths[authData] = subTree
if self.snmpContext is None:
self.snmpContext = context.SnmpContext(self.snmpEngine)
config.addContext(
self.snmpEngine, '' # this is leaky
)
return notifyName
示例2: configure
def configure(self, snmpEngine, authData, transportTarget, notifyType,
contextName, **options):
cache = self._getCache(snmpEngine)
notifyName = None
# Create matching transport tags if not given by user. Not good!
if not transportTarget.tagList:
transportTarget.tagList = str(
hash((authData.securityName, transportTarget.transportAddr))
)
if isinstance(authData, CommunityData) and not authData.tag:
authData.tag = transportTarget.tagList.split()[0]
addrName, paramsName = self._cmdGenLcdCfg.configure(
snmpEngine, authData, transportTarget, contextName, **options)
tagList = transportTarget.tagList.split()
if not tagList:
tagList = ['']
for tag in tagList:
notifyNameKey = paramsName, tag, notifyType
if notifyNameKey in cache['name']:
notifyName, paramsName, useCount = cache['name'][notifyNameKey]
cache['name'][notifyNameKey] = notifyName, paramsName, useCount + 1
else:
notifyName = 'n%s' % self.nextID()
config.addNotificationTarget(
snmpEngine, notifyName, paramsName, tag, notifyType)
cache['name'][notifyNameKey] = notifyName, paramsName, 1
authDataKey = authData.securityName, authData.securityModel, authData.securityLevel, contextName
if authDataKey in cache['auth']:
authDataX, subTree, useCount = cache['auth'][authDataKey]
cache['auth'][authDataKey] = authDataX, subTree, useCount + 1
else:
subTree = (1, 3, 6)
config.addVacmUser(
snmpEngine,authData.securityModel, authData.securityName,
authData.securityLevel, (), (), subTree,
contextName=contextName)
cache['auth'][authDataKey] = authData, subTree, 1
return notifyName
示例3: setTrapReceiver
def setTrapReceiver(self, host, community):
config.addV1System(self._snmpEngine, 'nms-area', community)
config.addVacmUser(self._snmpEngine, 2, 'nms-area', 'noAuthNoPriv',
notifySubTree=(1, 3, 6, 1, 4, 1))
config.addTargetParams(self._snmpEngine,
'nms-creds', 'nms-area', 'noAuthNoPriv', 1)
config.addTargetAddr(self._snmpEngine, 'my-nms', udp.domainName,
(host, 162), 'nms-creds',
tagList='all-my-managers')
# set last parameter to 'notification' to have it send
# informs rather than unacknowledged traps
config.addNotificationTarget(
self._snmpEngine,
'test-notification', 'my-filter',
'all-my-managers', 'trap')
示例4: initTarget
def initTarget(host='127.0.0.1', port=162, community='LIC_OSS'):
#global snmpEngine, snmpContext, ntfOrg
# Create SNMP engine instance
snmpEngine = engine.SnmpEngine()
# SecurityName <-> CommunityName mapping
config.addV1System(snmpEngine, 'my-area', community)
# Specify security settings per SecurityName (SNMPv2c -> 1)
config.addTargetParams(snmpEngine, 'my-creds', 'my-area', 'noAuthNoPriv', 1)
# Setup transport endpoint and bind it with security settings yielding
# a target name
config.addSocketTransport(
snmpEngine,
udp.domainName,
udp.UdpSocketTransport().openClientMode()
)
config.addTargetAddr(
snmpEngine, 'my-nms',
udp.domainName, (host, port),
'my-creds',
tagList='all-my-managers'
)
# Specify what kind of notification should be sent (TRAP or INFORM),
# to what targets (chosen by tag) and what filter should apply to
# the set of targets (selected by tag)
config.addNotificationTarget(
snmpEngine, 'my-notification', 'my-filter', 'all-my-managers', 'trap'
)
# Allow NOTIFY access to Agent's MIB by this SNMP model (2), securityLevel
# and SecurityName
config.addContext(snmpEngine, '')
config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (), (), (1,3,6))
# *** SNMP engine configuration is complete by this line ***
# Create default SNMP context where contextEngineId == SnmpEngineId
snmpContext = context.SnmpContext(snmpEngine)
# Create Notification Originator App instance.
ntfOrg = ntforg.NotificationOriginator(snmpContext)
return snmpEngine, ntfOrg
示例5: cfgNtfOrg
def cfgNtfOrg(self, authData, transportTarget, notifyType):
addrName, paramsName = self.cfgCmdGen(authData, transportTarget)
tagList = transportTarget.tagList.split()
if not tagList:
tagList = ['']
for tag in tagList:
notifyNameKey = paramsName, tag, notifyType
if notifyNameKey in self.__knownNotifyNames:
notifyName, paramsName, useCount = self.__knownNotifyNames[notifyNameKey]
self.__knownNotifyNames[notifyNameKey] = notifyName, paramsName, useCount + 1
else:
notifyName = 'n%s' % nextID()
config.addNotificationTarget(
self.snmpEngine,
notifyName,
paramsName,
tag,
notifyType
)
self.__knownNotifyNames[notifyNameKey] = notifyName, paramsName, 1
authDataKey = authData.securityName, authData.securityModel
if authDataKey in self.__knownAuths:
authDataX, subTree, useCount = self.__knownAuths[authDataKey]
self.__knownAuths[authDataKey] = authDataX, subTree, useCount + 1
else:
subTree = (1,3,6)
config.addTrapUser(
self.snmpEngine,
authData.securityModel,
authData.securityName,
authData.securityLevel,
subTree
)
self.__knownAuths[authDataKey] = authData, subTree, 1
if self.snmpContext is None:
self.snmpContext = context.SnmpContext(self.snmpEngine)
config.addContext(
self.snmpEngine, '' # this is leaky
)
return notifyName
示例6: cfgNtfOrg
def cfgNtfOrg(self, snmpEngine, authData, transportTarget, notifyType):
cache = self._getNtfCache(snmpEngine)
addrName, paramsName = self.cfgCmdGen(
snmpEngine, authData, transportTarget
)
tagList = transportTarget.tagList.split()
if not tagList:
tagList = ['']
for tag in tagList:
notifyNameKey = paramsName, tag, notifyType
if notifyNameKey in cache['name']:
notifyName, paramsName, useCount = cache['name'][notifyNameKey]
cache['name'][notifyNameKey] = notifyName, paramsName, useCount + 1
else:
notifyName = 'n%s' % nextID()
config.addNotificationTarget(
snmpEngine,
notifyName,
paramsName,
tag,
notifyType
)
cache['name'][notifyNameKey] = notifyName, paramsName, 1
authDataKey = authData.securityName, authData.securityModel
if authDataKey in cache['auth']:
authDataX, subTree, useCount = cache['auth'][authDataKey]
cache['auth'][authDataKey] = authDataX, subTree, useCount + 1
else:
subTree = (1,3,6)
config.addTrapUser(
snmpEngine,
authData.securityModel,
authData.securityName,
authData.securityLevel,
subTree
)
cache['auth'][authDataKey] = authData, subTree, 1
return notifyName
示例7: sent
snmpEngine,
udp.domainName,
udp.UdpSocketTransport().openClientMode()
)
config.addTargetAddr(
snmpEngine, 'my-nms',
udp.domainName, ('104.236.166.95', 162),
'my-creds',
tagList='all-my-managers'
)
# Specify what kind of notification should be sent (TRAP or INFORM),
# to what targets (chosen by tag) and what filter should apply to
# the set of targets (selected by tag)
config.addNotificationTarget(
snmpEngine, 'my-notification', 'my-filter', 'all-my-managers', 'inform'
)
# Allow NOTIFY access to Agent's MIB by this SNMP model (3), securityLevel
# and SecurityName
config.addContext(snmpEngine, '')
config.addVacmUser(snmpEngine, 3, 'usr-md5-none', 'authNoPriv', (), (), (1, 3, 6))
# *** SNMP engine configuration is complete by this line ***
# Create Notification Originator App instance.
ntfOrg = ntforg.NotificationOriginator()
# Error/confirmation receiver
# noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
示例8: sent
udp.domainName, ('127.0.0.2', 162),
'my-creds',
tagList='all-my-managers'
)
# Third target
config.addTargetAddr(
snmpEngine, 'my-nms-3',
udp.domainName, ('127.0.0.3', 162),
'my-creds',
tagList='all-my-managers'
)
# Specify what kind of notification should be sent (TRAP or INFORM)
# to what targets (chosen by tag) and with what credentials.
config.addNotificationTarget(
snmpEngine, 'my-notification', 'my-creds', 'all-my-managers', 'trap'
)
# Allow NOTIFY access to Agent's MIB by this SNMP model (2), securityLevel
# and SecurityName
config.addContext(snmpEngine, '')
config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (), (), (1,3,6))
# *** SNMP engine configuration is complete by this line ***
# Create Notification Originator App instance.
ntfOrg = ntforg.NotificationOriginator()
# Build and submit notification message to dispatcher
ntfOrg.sendVarBinds(
snmpEngine,
示例9:
config.usmDESPrivProtocol, 'privkey1'
)
# Transport params
config.addTargetParams(snmpEngine, 'myParams', 'test-user', 'authPriv')
#config.addTargetParams(snmpEngine, 'myParams', 'test-agent', 'noAuthNoPriv', 0)
# Transport addresses
config.addTargetAddr(
snmpEngine, 'myNMS', config.snmpUDPDomain,
('127.0.0.1', 162), 'myParams', tagList='myManagementStations'
)
# Notification targets
config.addNotificationTarget(
# snmpEngine, 'myNotifyName', 'myParams', 'myManagementStations', 'trap'
snmpEngine, 'myNotifyName', 'myParams', 'myManagementStations', 'inform'
)
# Setup transport endpoint
config.addSocketTransport(
snmpEngine,
udp.domainName,
udp.UdpSocketTransport().openClientMode()
)
# Agent-side VACM setup
config.addContext(snmpEngine, '')
config.addVacmUser(snmpEngine, 1, 'test-agent', 'noAuthNoPriv',
(), (), (1,3,6)) # v1
config.addVacmUser(snmpEngine, 2, 'test-agent', 'noAuthNoPriv',
(), (), (1,3,6)) # v2c
示例10: setTrapReceiver
def setTrapReceiver(self, host, community):
config.addV1System(self._snmpEngine, 'nms-area',community)
config.addVacmUser(self._snmpEngine, 2, 'nms-area','noAuthNoPriv', notifySubTree=(1,3,6,1,4,1))
config.addTargetParams(self._snmpEngine, 'nms-creds', 'nms-area','noAuthNoPriv',1)
config.addTargetAddr(self._snmpEngine, 'my-nms', udp.domainName, (host, 162), 'nms-creds',tagList = 'all-my-managers')
config.addNotificationTarget(self._snmpEngine, 'test-notification', 'my-filter', 'all-my-managers', 'trap')
示例11: sent
udp.domainName,
udp.UdpTwistedTransport().openClientMode()
)
config.addTargetAddr(
snmpEngine, 'my-nms-1',
udp.domainName, ('127.0.0.1', 162),
'my-creds-1',
tagList='all-my-managers'
)
#
# Specify what kind of notification should be sent (TRAP or INFORM)
# to what targets (chosen by tag) and with what credentials.
#
config.addNotificationTarget(
snmpEngine, 'my-notification', 'my-creds', 'all-my-managers', doInform and 'inform' or 'trap'
)
#
# Notifications carry potentially confidential information from
# the Agent. Therefore access control is to be setup allowing
# NotificationOriginator access to certain portions of Agent MIB.
#
config.addContext(snmpEngine, '')
# SNMPv1
config.addVacmUser(snmpEngine, 1, 'my-area', 'noAuthNoPriv', (), (), (1,3,6))
# SNMPv2c
config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (), (), (1,3,6))
# SNMPv3
config.addVacmUser(snmpEngine, 3, 'usr-md5-des', 'authPriv', (), (), (1,3,6))
config.addVacmUser(snmpEngine, 3, 'usr-md5-none', 'authPriv', (), (), (1,3,6))
示例12: __init__
def __init__(self, mibPath, temperatureValue, snmpRelays, criticalStatus=True):
from types import ListType, TupleType,StringTypes
from re import compile,search
from socket import gethostbyname
extractPaths=compile(r'[,:]')
checkIP=compile(r'(\d{1,3}\.){3}\d{1,3}')
# Create SNMP engine instance
self.snmpEngine = engine.SnmpEngine()
if not temperatureValue:
raise ValueError, 'A temperature must be provided'
self.temperature=temperatureValue
#print "============>mibPath type: %s" %type(mibPath)
if type(mibPath) in StringTypes:
mibPathTuple=tuple(extractPaths.split(mibPath))
elif type(mibPath) in (ListType, TupleType):
mibPathTuple=tuple(mibPath)
else:
mibPathTuple=('/usr/local/share/snmp/python/',)
mibBuilder = self.snmpEngine.msgAndPduDsp.mibInstrumController.mibBuilder
#print mibPathTuple
mibSources = mibBuilder.getMibPath() + mibPathTuple
mibBuilder.setMibPath(*mibSources)
mibBuilder.loadModules( 'USC-IGFAE-MIB' )
if type(snmpRelays) in StringTypes:
snmpRelays=snmpRelays.split(',')
elif not type(snmpRelays) in (ListType,TupleType):
raise TypeError, 'The list of SNMP relays must be a string or a list or tuple of strings'
(temperatureCritical, temperatureOK, self.roomTemp) = mibBuilder.importSymbols('USC-IGFAE-MIB','temperatureCritical', 'temperatureOK', 'roomTemp' )
# SecurityName <-> CommunityName mapping
config.addV1System(self.snmpEngine, 'Arduino', 'ups')
# Specify security settings per SecurityName (SNMPv2c -> 1)
config.addTargetParams(self.snmpEngine, 'creds', 'Arduino', 'noAuthNoPriv', 0)
# Setup transport endpoint and bind it with security settings yielding
# a target name
config.addSocketTransport(
self.snmpEngine,
udp.domainName,
udp.UdpSocketTransport().openClientMode()
)
index=0
for machine in snmpRelays:
index=index+1
if not checkIP.match(machine):
try:
machine=gethostbyname(machine)
except:
continue
#print "==============>SNMP relay IP: %s" % machine
config.addTargetAddr(
self.snmpEngine, 'NMS%s' % index,
udp.domainName, (machine, 162),
'creds',
tagList='managers'
)
# Specify what kind of notification should be sent (TRAP or INFORM),
# to what targets (chosen by tag) and what filter should apply to
# the set of targets (selected by tag)
config.addNotificationTarget(
self.snmpEngine, 'sendShutdownTrap', 'my-filter', 'managers', 'trap'
)
# Allow NOTIFY access to Agent's MIB by this SNMP model (2), securityLevel
# and SecurityName
config.addContext(self.snmpEngine, '')
config.addVacmUser(self.snmpEngine, 1, 'Arduino', 'noAuthNoPriv',
(), (), (1,3,6))
# *** SNMP engine configuration is complete by this line ***
# Create default SNMP context where contextEngineId == SnmpEngineId
snmpContext = context.SnmpContext(self.snmpEngine)
if criticalStatus:
self.trap=temperatureCritical
else:
self.trap=temperatureOK
# Create Notification Originator App instance.
ntforg.NotificationOriginator.__init__(self,snmpContext)
示例13: sent
# First target
config.addTargetAddr(
snmpEngine, "my-nms-1", udp.domainName, ("195.218.195.228", 162), "my-creds", tagList="all-my-managers"
)
# Second target
config.addTargetAddr(
snmpEngine, "my-nms-2", udp.domainName, ("195.218.195.228", 162), "my-creds", tagList="all-my-managers"
)
# Third target
config.addTargetAddr(
snmpEngine, "my-nms-3", udp.domainName, ("195.218.195.228", 162), "my-creds", tagList="all-my-managers"
)
# Specify what kind of notification should be sent (TRAP or INFORM)
# to what targets (chosen by tag) and with what credentials.
config.addNotificationTarget(snmpEngine, "my-notification", "my-creds", "all-my-managers", "trap")
# Allow NOTIFY access to Agent's MIB by this SNMP model (2), securityLevel
# and SecurityName
config.addContext(snmpEngine, "")
config.addVacmUser(snmpEngine, 2, "my-area", "noAuthNoPriv", (), (), (1, 3, 6))
# *** SNMP engine configuration is complete by this line ***
# Create Notification Originator App instance.
ntfOrg = ntforg.NotificationOriginator()
# Build and submit notification message to dispatcher
ntfOrg.sendVarBinds(
snmpEngine,
# Notification targets