@Override public int hashCode() { int hash = Objects.hash(getAddress(), getProxyFor(), getPort(), getTimeout(), getRetries(), getMaxVarsPerPdu(), getMaxRepetitions(), getMaxRequestSize(), getVersion(), getSecurityLevel(), getSecurityName(), getAuthPassPhrase(), getAuthProtocol(), getPrivPassPhrase(), getPrivProtocol(), getContextName(), getEngineId(), getContextEngineId(), getEnterpriseId(), getReadCommunity(), getWriteCommunity()); return hash; }
protected SnmpAgentConfig buildAgentConfig(String address, int port, int securityLevel, String securityName, String authPassPhrase, String authProtocol, String privPassPhrase, String privProtocol, PDU pdu) throws UnknownHostException, Exception { if (! (pdu instanceof ScopedPDU)) { throw new SnmpException("PDU is not a ScopedPDU (this should not happen)"); } SnmpAgentConfig config = new SnmpAgentConfig(); config.setAddress(InetAddress.getByName(address)); config.setPort(port); config.setVersion(SnmpAgentConfig.VERSION3); config.setSecurityLevel(securityLevel); config.setSecurityName(securityName); config.setAuthPassPhrase(authPassPhrase); config.setAuthProtocol(authProtocol); config.setPrivPassPhrase(privPassPhrase); config.setPrivProtocol(privProtocol); return config; }
protected SnmpAgentConfig buildAgentConfig(String address, int port, String community, PDU pdu) throws UnknownHostException { SnmpAgentConfig config = new SnmpAgentConfig(); config.setAddress(InetAddress.getByName(address)); config.setPort(port); config.setVersion(pdu instanceof PDUv1 ? SnmpAgentConfig.VERSION1 : SnmpAgentConfig.VERSION2C); return config; }
/** * <p>getAgentConfig</p> * * @return a {@link org.opennms.netmgt.snmp.SnmpAgentConfig} object. */ public SnmpAgentConfig getAgentConfig() { SnmpAgentConfig agentConfig = getCollectionAgent().getAgentConfig(); agentConfig.setPort(m_snmpCollection.getSnmpPort(agentConfig.getPort())); agentConfig.setRetries(m_snmpCollection.getSnmpRetries(agentConfig.getRetries())); agentConfig.setTimeout(m_snmpCollection.getSnmpTimeout(agentConfig.getTimeout())); agentConfig.setReadCommunity(m_snmpCollection.getSnmpReadCommunity(agentConfig.getReadCommunity())); agentConfig.setWriteCommunity(m_snmpCollection.getSnmpWriteCommunity(agentConfig.getWriteCommunity())); agentConfig.setProxyFor(m_snmpCollection.getSnmpProxyFor(agentConfig.getProxyFor())); agentConfig.setVersion(m_snmpCollection.getSnmpVersion(agentConfig.getVersion())); agentConfig.setMaxVarsPerPdu(m_snmpCollection.getSnmpMaxVarsPerPdu(agentConfig.getMaxVarsPerPdu())); agentConfig.setMaxRepetitions(m_snmpCollection.getSnmpMaxRepetitions(agentConfig.getMaxRepetitions())); agentConfig.setMaxRequestSize(m_snmpCollection.getSnmpMaxRequestSize(agentConfig.getMaxRequestSize())); agentConfig.setSecurityName(m_snmpCollection.getSnmpSecurityName(agentConfig.getSecurityName())); agentConfig.setAuthPassPhrase(m_snmpCollection.getSnmpAuthPassPhrase(agentConfig.getAuthPassPhrase())); agentConfig.setAuthProtocol(m_snmpCollection.getSnmpAuthProtocol(agentConfig.getAuthProtocol())); agentConfig.setPrivPassPhrase(m_snmpCollection.getSnmpPrivPassPhrase(agentConfig.getPrivPassPhrase())); agentConfig.setPrivProtocol(m_snmpCollection.getSnmpPrivProtocol(agentConfig.getPrivProtocol())); return agentConfig; }
public String toString() { StringBuffer buff = new StringBuffer("AgentConfig["); buff.append("Address: "+getAddress()); buff.append(", ProxyForAddress: "+getProxyFor()); buff.append(", Port: "+getPort()); buff.append(", Community: "+getReadCommunity()); buff.append(", Timeout: "+getTimeout()); buff.append(", Retries: "+getRetries()); buff.append(", MaxVarsPerPdu: "+getMaxVarsPerPdu()); buff.append(", MaxRepetitions: "+getMaxRepetitions()); buff.append(", Max request size: "+getMaxRequestSize()); buff.append(", Version: "+versionToString(getVersion())); if (getVersion() == VERSION3) { buff.append(", Security level: "+getSecurityLevel()); buff.append(", Security name: "+getSecurityName()); buff.append(", auth-passphrase: "+getAuthPassPhrase()); buff.append(", auth-protocol: "+getAuthProtocol()); buff.append(", priv-passprhase: "+getPrivPassPhrase()); buff.append(", priv-protocol: "+getPrivProtocol()); } buff.append("]"); return buff.toString(); }
private SnmpAgentConfig getAgentConfig(InetAddress ipaddr) { // Retrieve this interface's SNMP peer object SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(ipaddr); if (agentConfig == null) { throw new IllegalStateException("SnmpAgentConfig object not available for interface " + ipaddr); } agentConfig.hashCode(); // Set timeout and retries on SNMP peer object agentConfig.setTimeout(ParameterMap.getKeyedInteger(m_parameters, "timeout", agentConfig.getTimeout())); agentConfig.setRetries(ParameterMap.getKeyedInteger(m_parameters, "retry", ParameterMap.getKeyedInteger(m_parameters, "retries", agentConfig.getRetries()))); agentConfig.setPort(ParameterMap.getKeyedInteger(m_parameters, "port", agentConfig.getPort())); return agentConfig; }
buff.append("Address: " + InetAddrUtils.str(m_address)); buff.append(", ProxyForAddress: " + InetAddrUtils.str(m_proxyFor)); buff.append(", Port: " + getPort()); buff.append(", Timeout: " + getTimeout()); buff.append(", Retries: " + getRetries()); buff.append(", MaxVarsPerPdu: " + getMaxVarsPerPdu()); buff.append(", MaxRepetitions: " + getMaxRepetitions()); buff.append(", MaxRequestSize: " + getMaxRequestSize()); buff.append(", Version: " + versionToString(getVersion())); if (isVersion3()) { buff.append(", SecurityLevel: " + getSecurityLevel()); buff.append(", SecurityName: " + getSecurityName()); buff.append(", AuthPassPhrase: XXXXXXXX"); //getAuthPassPhrase() buff.append(", AuthProtocol: " + getAuthProtocol()); buff.append(", PrivPassphrase: XXXXXXXX"); //getPrivPassPhrase() buff.append(", PrivProtocol: " + getPrivProtocol()); buff.append(", ContextName: " + getContextName()); buff.append(", EngineId: " + getEngineId()); buff.append(", ContextEngineId: " + getContextEngineId()); buff.append(", EnterpriseId:" + getEnterpriseId()); } else { buff.append(", ReadCommunity: XXXXXXXX"); //getReadCommunity()
public static SnmpAgentConfig fromMap(Map<String, String> map) { SnmpAgentConfig config = new SnmpAgentConfig(); if (map.get("address") != null) config.setAddress(InetAddrUtils.addr(map.get("address"))); if (map.get("proxyFor") != null) config.setProxyFor(InetAddrUtils.addr(map.get("proxyFor"))); if (map.get("port") != null) config.setPort(Integer.parseInt(map.get("port"))); if (map.get("timeout") != null) config.setTimeout(Integer.parseInt(map.get("timeout"))); if (map.get("retries") != null) config.setRetries(Integer.parseInt(map.get("retries"))); if (map.get("max-vars-per-pdu") != null) config.setMaxVarsPerPdu(Integer.parseInt(map.get("max-vars-per-pdu"))); if (map.get("max-repetitions") != null) config.setMaxRepetitions(Integer.parseInt(map.get("max-repetitions"))); if (map.get("max-request-size") != null) config.setMaxRequestSize(Integer.parseInt(map.get("max-request-size"))); if (map.get("version") != null) config.setVersion(Integer.parseInt(map.get("version"))); if (map.get("security-level") != null) config.setSecurityLevel(Integer.parseInt(map.get("security-level"))); if (map.get("security-name") != null) config.setSecurityName(map.get("security-name")); if (map.get("auth-passphrase") != null) config.setAuthPassPhrase(map.get("auth-passphrase")); if (map.get("auth-protocol") != null) config.setAuthProtocol(map.get("auth-protocol")); if (map.get("priv-passphrase") != null) config.setPrivPassPhrase(map.get("priv-passphrase")); if (map.get("priv-protocol") != null) config.setPrivProtocol(map.get("priv-protocol")); if (map.get("context-name") != null) config.setContextName(map.get("context-name")); if (map.get("engine-id") != null) config.setEngineId(map.get("engine-id")); if (map.get("context-engine-id") != null) config.setContextEngineId(map.get("context-engine-id")); if (map.get("enterprise-id") != null) config.setEnterpriseId(map.get("enterprise-id")); if (map.get("read-community") != null) config.setReadCommunity(map.get("read-community")); if (map.get("write-community") != null) config.setWriteCommunity(map.get("write-community")); return config; } }
/** * Create an SNMP V3 inform based on the content of the specified trap configuration, and send it to the appropriate destination. * * @param trapConfig The trap configuration mapping object * @throws SnmpTrapException if any. */ private void forwardV3Inform(SnmpTrapConfig trapConfig) throws SnmpTrapException { SnmpV3TrapBuilder trap = SnmpUtils.getV3InformBuilder(); populateTrapBuilder(trap, trapConfig); try { SnmpAgentConfig config = getAgentConfig(trapConfig); trap.sendInform(config.getAddress().getHostAddress(), config.getPort(), config.getTimeout(), config.getTimeout(), config.getSecurityLevel(), config.getSecurityName(), config.getAuthPassPhrase(), config.getAuthProtocol(), config.getPrivPassPhrase(), config.getPrivProtocol()); } catch (Throwable e) { throw new SnmpTrapException("Failed to send trap "+e.getMessage(), e); } }
private void setCommonAttributes(final SnmpAgentConfig agentConfig, final Definition def, final int version) { agentConfig.setVersion(version); agentConfig.setPort(def.getPort()); agentConfig.setRetries(def.getRetry()); agentConfig.setTimeout((int)def.getTimeout()); agentConfig.setMaxRequestSize(def.getMaxRequestSize()); agentConfig.setMaxVarsPerPdu(def.getMaxVarsPerPdu()); agentConfig.setMaxRepetitions(def.getMaxRepetitions()); InetAddress proxyHost = InetAddressUtils.addr(def.getProxyHost()); if (proxyHost != null) { agentConfig.setProxyFor(agentConfig.getAddress()); agentConfig.setAddress(proxyHost); } }
@Override public SnmpWalker createWalker(final SnmpAgentConfig agentConfig, final String name, final CollectionTracker tracker) { LOG.debug("createWalker({}/{}, {}, {})", InetAddrUtils.str(agentConfig.getAddress()), agentConfig.getPort(), name, tracker.getClass().getName()); final SnmpAgentAddress aa = new SnmpAgentAddress(agentConfig.getAddress(), agentConfig.getPort()); final PropertyOidContainer oidContainer = getOidContainer(aa); return new MockSnmpWalker(aa, agentConfig.getVersion(), oidContainer, name, tracker, agentConfig.getMaxVarsPerPdu(), agentConfig.getRetries()); }
/** * Create an SNMP V2 inform based on the content of the specified trap configuration, and send it to the appropriate destination. * * @param trapConfig The trap configuration mapping object * @throws SnmpTrapException if any. */ private void forwardV2Inform(SnmpTrapConfig trapConfig) throws SnmpTrapException { SnmpV2TrapBuilder trap = SnmpUtils.getV2InformBuilder(); populateTrapBuilder(trap, trapConfig); try { SnmpAgentConfig config = getAgentConfig(trapConfig); trap.sendInform(config.getAddress().getHostName(), config.getPort(), config.getTimeout(), config.getRetries(), config.getReadCommunity()); } catch (Throwable e) { throw new SnmpTrapException("Failed to send trap "+e.getMessage(), e); } }
agentConfig.setPort(getPort()); agentConfig.setTimeout(getTimeout()); agentConfig.setRetries(getRetries()); agentConfig.setVersion(SnmpAgentConfig.VERSION1); } else if ("v2".equalsIgnoreCase(version) || "v2c".equalsIgnoreCase(version) || "snmpv2".equalsIgnoreCase(version) || "snmpv2c".equalsIgnoreCase(version)) { agentConfig.setVersion(SnmpAgentConfig.VERSION2C); } else if ("v3".equalsIgnoreCase(version) || "snmpv3".equalsIgnoreCase(version)) { agentConfig.setVersion(SnmpAgentConfig.VERSION3); LOG.debug("capsd: SNMPwalk succeeded, addr={} oid={} instance={} value={}", InetAddressUtils.str(agentConfig.getAddress()), hrStorageDescrSnmpObject, e.getKey(), e.getValue());
/** * Create an SNMP V2 trap based on the content of the specified trap configuration, and send it to the appropriate destination. * * @param trapConfig The trap configuration mapping object * @throws SnmpTrapException if any. */ private void forwardV2Trap(SnmpTrapConfig trapConfig) throws SnmpTrapException { SnmpTrapBuilder trap = SnmpUtils.getV2TrapBuilder(); populateTrapBuilder(trap, trapConfig); try { SnmpAgentConfig config = getAgentConfig(trapConfig); trap.send(config.getAddress().getHostAddress(), config.getPort(), config.getReadCommunity()); } catch (Throwable e) { throw new SnmpTrapException("Failed to send trap "+e.getMessage(), e); } }
public InetAddress getInetAddress() { return m_config.getAddress(); }
ipAddr = InetAddressUtils.addr(getIpaddress()); SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(ipAddr); if (hasPort) agentConfig.setPort(port); if (hasTimeout) agentConfig.setTimeout(timeout); if (hasRetries) agentConfig.setRetries(retries); if (hasMaxVarsPerPdu) agentConfig.setMaxVarsPerPdu(maxVarsPerPdu);
protected PropertyOidContainer getOidContainer(final SnmpAgentConfig agentConfig) { return getOidContainer(new SnmpAgentAddress(agentConfig.getAddress(), agentConfig.getPort())); }
/** * <p>configureAgentPTR</p> * * @param agentConfig a {@link org.opennms.netmgt.snmp.SnmpAgentConfig} object. */ protected void configureAgentPTR(SnmpAgentConfig agentConfig) { if (getPort() > 0) { agentConfig.setPort(getPort()); } if (getTimeout() > 0) { agentConfig.setTimeout(getTimeout()); } if (getRetries() > -1) { agentConfig.setRetries(getRetries()); } }
community = agentConfig.getReadCommunity().length() + 2; overhead += trapConfig.getEnterpriseId().length() + 14; // Trap-OID Varbind if (trapConfig.getVersion().isV3()) { switch (agentConfig.getSecurityLevel()) { case 1: overhead += 92; break; case 2: overhead += 120; break; case 3: overhead += 130; break; overhead += agentConfig.getSecurityName().length() + 2;
@Override public SnmpAgentConfig getAgentConfig(final InetAddress address, String location) { final SnmpAgentConfigProxyMapper mapper = SnmpAgentConfigProxyMapper.getInstance(); final SnmpAgentAddress agentAddress = mapper.getAddress(address); final String addressString = str(address); if (agentAddress == null) { LOG.debug( "No agent address mapping found for {}! Try adding a @JUnitSnmpAgent(host=\"{}\", resource=\"...\" entry...", addressString, addressString); return super.getAgentConfig(address, location); } final SnmpAgentConfig config = new SnmpAgentConfig(agentAddress.getAddress()); config.setProxyFor(address); config.setPort(agentAddress.getPort()); LOG.debug("proxying {} -> {}", addressString, agentAddress); return config; }