本文整理汇总了Java中org.snmp4j.mp.MPv3类的典型用法代码示例。如果您正苦于以下问题:Java MPv3类的具体用法?Java MPv3怎么用?Java MPv3使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MPv3类属于org.snmp4j.mp包,在下文中一共展示了MPv3类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSNMP
import org.snmp4j.mp.MPv3; //导入依赖的package包/类
/**
* Create SNMP.
*/
private void createSNMP() {
LOG.info("Creating SNMP...");
try {
TransportMapping transport = new DefaultUdpTransportMapping();
transport.listen();
snmp = new Snmp(transport);
// SNMP V3
USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(usm);
LOG.debug("Snmp created.");
snmp.listen();
LOG.debug("Snmp listening...");
} catch (IOException e) {
throw new RuntimeException("Cannot create snmp!!!", e);
}
}
示例2: snmpMessageToHumanReadable
import org.snmp4j.mp.MPv3; //导入依赖的package包/类
static PDU snmpMessageToHumanReadable(String s) throws IOException {
final OctetString message = OctetString.fromHexString(s, ':');
final Address address = new UdpAddress();
final TransportMapping transportMapping = (address instanceof UdpAddress) ?
new DefaultUdpTransportMapping((UdpAddress) address)
: new DefaultTcpTransportMapping((TcpAddress) address);
final MessageDispatcher messageDispatcher = new
MessageDispatcherImpl();
SecurityProtocols.getInstance().addDefaultProtocols();
final SnmpMessageAnalyzer snmpMessageAnalyzer = new SnmpMessageAnalyzer();
final CommandResponder commandResponder = snmpMessageAnalyzer;
messageDispatcher.addCommandResponder(commandResponder);
messageDispatcher.addMessageProcessingModel(new MPv1());
messageDispatcher.addMessageProcessingModel(new MPv2c());
messageDispatcher.addMessageProcessingModel(new MPv3());
messageDispatcher.processMessage(transportMapping, address, ByteBuffer.wrap(message.getValue()));
PDU result = snmpMessageAnalyzer.msg;
snmpMessageAnalyzer.msg = null;
return result;
}
示例3: initialize
import org.snmp4j.mp.MPv3; //导入依赖的package包/类
/**
* Initialize for v3 communications
*/
private static void initialize() {
if (s_initialized) {
return;
}
// LogFactory.setLogFactory(new Log4jLogFactory());
MPv3.setEnterpriseID(5813);
USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(usm);
// Enable extensibility in SNMP4J so that we can subclass some SMI classes to work around
// agent bugs
if (System.getProperty("org.snmp4j.smisyntaxes", null) != null) {
SNMP4JSettings.setExtensibilityEnabled(true);
}
if (Boolean.getBoolean("org.opennms.snmp.snmp4j.forwardRuntimeExceptions")) {
SNMP4JSettings.setForwardRuntimeExceptions(true);
}
s_initialized = true;
}
示例4: start
import org.snmp4j.mp.MPv3; //导入依赖的package包/类
/**
* Start the Snmp session. If you forget the listen() method you will not get any answers because the communication is asynchronous and the
* listen() method listens for answers.
*
* @throws IOException
*/
public void start() throws IOException {
TransportMapping transport = new DefaultUdpTransportMapping();
if (SNMPversion == 3) {
USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(usm);
}
snmp = new Snmp(transport);
if (SNMPversion == 3)
snmp.getUSM().addUser(new OctetString(ver3Username),
new UsmUser(new OctetString(ver3Username), AuthMD5.ID, new OctetString(ver3AuthPasscode), null, null));
// Do not forget this line!
transport.listen();
}
示例5: init
import org.snmp4j.mp.MPv3; //导入依赖的package包/类
private void init() throws UnknownHostException, IOException {
threadPool = ThreadPool.create("Trap", 4);
dispatcher = new MultiThreadedMessageDispatcher(threadPool,
new MessageDispatcherImpl());
listenAddress = GenericAddress.parse("udp:0.0.0.0/"
+ SnmpPref.getTrapsPort());
DefaultUdpTransportMapping transport = new DefaultUdpTransportMapping(
(UdpAddress) listenAddress);
snmp = new Snmp(dispatcher, transport);
snmp.getMessageDispatcher().addMessageProcessingModel(new MPv1());
snmp.getMessageDispatcher().addMessageProcessingModel(new MPv2c());
snmp.getMessageDispatcher().addMessageProcessingModel(new MPv3());
USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(
MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(usm);
snmp.listen();
logger.debug("Listening for traps on "
+ transport.getListenAddress().toString());
}
示例6: initMessageDispatcher
import org.snmp4j.mp.MPv3; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected void initMessageDispatcher() {
dispatcher = new MessageDispatcherImpl();
usm = new USM(SecurityProtocols.getInstance(),
agent.getContextEngineID(),
updateEngineBoots());
mpv3 = new MPv3(usm);
SecurityProtocols.getInstance().addDefaultProtocols();
dispatcher.addMessageProcessingModel(new MPv1());
dispatcher.addMessageProcessingModel(new MPv2c());
dispatcher.addMessageProcessingModel(mpv3);
initSnmpSession();
}
示例7: setUp
import org.snmp4j.mp.MPv3; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
super.setUp();
MockUtil.println("------------ Begin Test "+getName()+" --------------------------");
final Properties p = new Properties();
p.setProperty("log4j.logger.org.snmp4j", "DEBUG");
p.setProperty("log4j.logger.org.snmp4j.agent", "DEBUG");
MockLogAppender.setupLogging(true, p);
// Create a global USM that all client calls will use
MPv3.setEnterpriseID(5813);
m_usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(m_usm);
m_agent = MockSnmpAgent.createAgentAndRun(new ClassPathResource("loadSnmpDataTest.properties"), "127.0.0.1/1691"); // Homage to Empire
}
示例8: createSnmpSession
import org.snmp4j.mp.MPv3; //导入依赖的package包/类
public Snmp createSnmpSession() throws IOException {
TransportMapping transport = new DefaultUdpTransportMapping();
Snmp session = new Snmp(transport);
if (isSnmpV3()) {
// Make a new USM
USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
// Add the specified user to the USM
usm.addUser(
getSecurityName(),
new UsmUser(
getSecurityName(),
getAuthProtocol(),
getAuthPassPhrase(),
getPrivProtocol(),
getPrivPassPhrase()
)
);
// Remove the old SNMPv3 MessageProcessingModel. If you don't do this, you'll end up with
// two SNMPv3 MessageProcessingModel instances in the dispatcher and connections will fail.
MessageProcessingModel oldModel = session.getMessageDispatcher().getMessageProcessingModel(MessageProcessingModel.MPv3);
if (oldModel != null) {
session.getMessageDispatcher().removeMessageProcessingModel(oldModel);
}
// Add a new SNMPv3 MessageProcessingModel with the newly-created USM
session.getMessageDispatcher().addMessageProcessingModel(new MPv3(usm));
}
return session;
}
示例9: SNMPV3Session
import org.snmp4j.mp.MPv3; //导入依赖的package包/类
/**
* 创建SNMPV3会话
* @param userInfo
* @throws IOException
* @throws AgentArgumentException
*/
public SNMPV3Session(SNMPV3UserInfo userInfo) throws IOException, AgentArgumentException {
if(StringUtils.isEmpty(userInfo.getAddress())){
throw new AgentArgumentException("SNMPV3Session创建失败:snmp v3协议的访问地址不能为空");
}
if(StringUtils.isEmpty(userInfo.getUsername())){
throw new AgentArgumentException("SNMPV3Session创建失败:snmp v3协议的访问用户名不能为空");
}
if(!StringUtils.isEmpty(userInfo.getAythType()) && StringUtils.isEmpty(userInfo.getAuthPswd())){
throw new AgentArgumentException("SNMPV3Session创建失败:snmp v3协议指定了认证算法 aythType,就必须要指定认证密码");
}
if(!StringUtils.isEmpty(userInfo.getPrivType()) && StringUtils.isEmpty(userInfo.getPrivPswd())){
throw new AgentArgumentException("SNMPV3Session创建失败:snmp v3协议指定了加密算法 privType,就必须要指定加密密码");
}
this.userInfo = userInfo;
snmp = new Snmp(new DefaultUdpTransportMapping());
USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID(
new OctetString(HostUtil.getHostIp() + UUID.randomUUID().toString())
)), 0);
SecurityModels.getInstance().addSecurityModel(usm);
snmp.listen();
UsmUser user = new UsmUser(
new OctetString(userInfo.getUsername()),
getAuthProtocol(userInfo.getAythType()), new OctetString(userInfo.getAuthPswd()),
getPrivProtocol(userInfo.getPrivType()), new OctetString(userInfo.getPrivPswd()));
snmp.getUSM().addUser(new OctetString(userInfo.getUsername()), user);
target = new UserTarget();
target.setSecurityName(new OctetString(userInfo.getUsername()));
target.setVersion(SnmpConstants.version3);
target.setSecurityLevel(SecurityLevel.AUTH_PRIV);
target.setAddress(GenericAddress.parse(userInfo.getProtocol() + ":" + userInfo.getAddress() + "/" + userInfo.getPort()));
target.setTimeout(TIMEOUT);
target.setRetries(1);
}
示例10: SNMPV3Session
import org.snmp4j.mp.MPv3; //导入依赖的package包/类
/**
* 创建SNMPV3会话
* @param userInfo
* @throws IOException
* @throws AgentArgumentException
*/
public SNMPV3Session(SNMPV3UserInfo userInfo) throws IOException, AgentArgumentException {
if(StringUtils.isEmpty(userInfo.getAddress())){
throw new AgentArgumentException("SNMPV3Session创建失败:snmp v3协议的访问地址不能为空");
}
if(StringUtils.isEmpty(userInfo.getUsername())){
throw new AgentArgumentException("SNMPV3Session创建失败:snmp v3协议的访问用户名不能为空");
}
if(!StringUtils.isEmpty(userInfo.getAythType()) && StringUtils.isEmpty(userInfo.getAuthPswd())){
throw new AgentArgumentException("SNMPV3Session创建失败:snmp v3协议指定了认证算法 aythType,就必须要指定认证密码");
}
if(!StringUtils.isEmpty(userInfo.getPrivType()) && StringUtils.isEmpty(userInfo.getPrivPswd())){
throw new AgentArgumentException("SNMPV3Session创建失败:snmp v3协议指定了加密算法 privType,就必须要指定加密密码");
}
this.userInfo = userInfo;
snmp = new Snmp(new DefaultUdpTransportMapping());
USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(usm);
snmp.listen();
UsmUser user = new UsmUser(
new OctetString(userInfo.getUsername()),
getAuthProtocol(userInfo.getAythType()), new OctetString(userInfo.getAuthPswd()),
getPrivProtocol(userInfo.getPrivType()), new OctetString(userInfo.getPrivPswd()));
snmp.getUSM().addUser(new OctetString(userInfo.getUsername()), user);
target = new UserTarget();
target.setSecurityName(new OctetString(userInfo.getUsername()));
target.setVersion(SnmpConstants.version3);
target.setSecurityLevel(SecurityLevel.AUTH_PRIV);
target.setAddress(GenericAddress.parse(userInfo.getProtocol() + ":" + userInfo.getAddress() + "/" + userInfo.getPort()));
target.setTimeout(8000);
target.setRetries(1);
}
示例11: start
import org.snmp4j.mp.MPv3; //导入依赖的package包/类
/**
* Start the Snmp session. If you forget the listen() method you will not
* get any answers because the communication is asynchronous
* and the listen() method listens for answers.
* @throws IOException
*/
public void start() throws IOException
{
TransportMapping transport = new DefaultUdpTransportMapping();
snmp = new Snmp(transport);
if("3".equals(this.version))//add v3 support
{
USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(usm);
}
// Do not forget this line!
transport.listen();
}
示例12: createPDU
import org.snmp4j.mp.MPv3; //导入依赖的package包/类
@Override
public PDU createPDU(MessageProcessingModel mpm) {
switch (mpm.getID()) {
case MessageProcessingModel.MPv3:
return new ScopedPDU();
case MessageProcessingModel.MPv1:
return new PDUv1();
default:
return new PDU();
}
}
示例13: initMessageDispatcher
import org.snmp4j.mp.MPv3; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected void initMessageDispatcher() {
dispatcher = new MessageDispatcherImpl();
usm = new USM(SecurityProtocols.getInstance(),
agent.getContextEngineID(),
updateEngineBoots());
mpv3 = new MPv3(usm);
SecurityProtocols.getInstance().addDefaultProtocols();
dispatcher.addMessageProcessingModel(new MPv1());
dispatcher.addMessageProcessingModel(new MPv2c());
dispatcher.addMessageProcessingModel(mpv3);
initSnmpSession();
}
示例14: setUp
import org.snmp4j.mp.MPv3; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
// Create a global USM that all client calls will use
MPv3.setEnterpriseID(5813);
m_usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(m_usm);
m_agent = MockSnmpAgent.createAgentAndRun(classPathResource("brocadeTestData1.properties"), "127.0.0.1/1691"); // Homage to Empire
m_requestedVarbinds = new ArrayList<AnticipatedRequest>();
}
示例15: setUp
import org.snmp4j.mp.MPv3; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
// Create a global USM that all client calls will use
MPv3.setEnterpriseID(5813);
m_usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(m_usm);
m_agent = MockSnmpAgent.createAgentAndRun(classPathResource("loadSnmpDataTest.properties"), "127.0.0.1/1691"); // Homage to Empire
m_requestedVarbinds = new ArrayList<AnticipatedRequest>();
}