Search in sources :

Example 1 with Definition

use of org.opennms.netmgt.config.snmp.Definition in project opennms by OpenNMS.

the class SnmpEventInfoTest method testCreateDefForSnmpV1.

@Test
public void testCreateDefForSnmpV1() {
    SnmpEventInfo snmpEventInfo = new SnmpEventInfo();
    snmpEventInfo.setAuthPassPhrase("authPassPhrase");
    snmpEventInfo.setAuthProtocol("authProtocol");
    snmpEventInfo.setReadCommunityString("readCommunityString");
    snmpEventInfo.setWriteCommunityString("writeCommunityString");
    snmpEventInfo.setContextEngineId("contextEngineId");
    snmpEventInfo.setContextName("contextName");
    snmpEventInfo.setEngineId("engineId");
    snmpEventInfo.setEnterpriseId("enterpriseId");
    snmpEventInfo.setMaxRepetitions(1000);
    snmpEventInfo.setMaxVarsPerPdu(2000);
    snmpEventInfo.setMaxRequestSize(7000);
    snmpEventInfo.setPort(3000);
    snmpEventInfo.setPrivPassPhrase("privPassPhrase");
    snmpEventInfo.setPrivProtocol("privProtocol");
    snmpEventInfo.setProxyHost("127.0.0.1");
    snmpEventInfo.setRetryCount(4000);
    snmpEventInfo.setSecurityLevel(5000);
    snmpEventInfo.setTimeout(6000);
    snmpEventInfo.setVersion("v1");
    // check v1/commons properties
    Definition def = snmpEventInfo.createDef();
    assertEquals(snmpEventInfo.getReadCommunityString(), def.getReadCommunity());
    assertEquals(snmpEventInfo.getMaxRepetitions(), def.getMaxRepetitions().intValue());
    assertEquals(snmpEventInfo.getMaxVarsPerPdu(), def.getMaxVarsPerPdu().intValue());
    assertEquals(snmpEventInfo.getPort(), def.getPort().intValue());
    assertEquals(snmpEventInfo.getProxyHost(), def.getProxyHost());
    assertEquals(snmpEventInfo.getRetryCount(), def.getRetry().intValue());
    assertEquals(snmpEventInfo.getTimeout(), def.getTimeout().intValue());
    assertEquals(snmpEventInfo.getVersion(), def.getVersion());
    assertEquals(snmpEventInfo.getMaxRequestSize(), def.getMaxRequestSize().intValue());
    assertEquals(snmpEventInfo.getWriteCommunityString(), def.getWriteCommunity());
    // v3 properties must not be set
    assertNull(def.getAuthPassphrase());
    assertNull(def.getAuthProtocol());
    assertNull(def.getContextEngineId());
    assertNull(def.getContextName());
    assertNull(def.getEngineId());
    assertNull(def.getEnterpriseId());
    assertNull(def.getPrivacyPassphrase());
    assertNull(def.getPrivacyProtocol());
}
Also used : Definition(org.opennms.netmgt.config.snmp.Definition) Test(org.junit.Test)

Example 2 with Definition

use of org.opennms.netmgt.config.snmp.Definition in project opennms by OpenNMS.

the class SnmpEventInfo method createDef.

/**
     * Creates an SNMP config definition representing the data in this class.
     * The defintion will either have one specific IP element or one Range element.
     *
     * @return a {@link org.opennms.netmgt.config.snmp.Definition} object.
     */
public Definition createDef() {
    Definition definition = new Definition();
    if (StringUtils.isNotEmpty(getVersion()))
        definition.setVersion(getVersion());
    if (getRetryCount() != 0)
        definition.setRetry(Integer.valueOf(getRetryCount()));
    if (getTimeout() != 0)
        definition.setTimeout(Integer.valueOf(getTimeout()));
    if (getPort() != 0)
        definition.setPort(Integer.valueOf(getPort()));
    if (getMaxRepetitions() != 0)
        definition.setMaxRepetitions(Integer.valueOf(getMaxRepetitions()));
    if (getMaxVarsPerPdu() != 0)
        definition.setMaxVarsPerPdu(Integer.valueOf(getMaxVarsPerPdu()));
    if (getMaxRequestSize() != 0)
        definition.setMaxRequestSize(Integer.valueOf(getMaxRequestSize()));
    if (StringUtils.isNotEmpty(getProxyHost()))
        definition.setProxyHost(getProxyHost());
    if (StringUtils.isNotEmpty(getLocation()))
        definition.setLocation(getLocation());
    // version dependend parameters
    if (getVersion() != null && getVersion().equals("v3")) {
        if (StringUtils.isNotEmpty(getAuthPassphrase()))
            definition.setAuthPassphrase(getAuthPassphrase());
        if (StringUtils.isNotEmpty(getAuthProtocol()))
            definition.setAuthProtocol(getAuthProtocol());
        if (StringUtils.isNotEmpty(getContextEngineId()))
            definition.setContextEngineId(getContextEngineId());
        if (StringUtils.isNotEmpty(getContextName()))
            definition.setContextName(getContextName());
        if (StringUtils.isNotEmpty(getEngineId()))
            definition.setEngineId(getEngineId());
        if (StringUtils.isNotEmpty(getEnterpriseId()))
            definition.setEnterpriseId(getEnterpriseId());
        if (StringUtils.isNotEmpty(getPrivPassPhrase()))
            definition.setPrivacyPassphrase(getPrivPassPhrase());
        if (StringUtils.isNotEmpty(getPrivProtocol()))
            definition.setPrivacyProtocol(getPrivProtocol());
        if (StringUtils.isNotEmpty(getSecurityName()))
            definition.setSecurityName(getSecurityName());
        if (getSecurityLevel() > 0)
            definition.setSecurityLevel(getSecurityLevel());
    } else {
        //v1, v2c or invalid version
        if (getReadCommunityString() != null)
            definition.setReadCommunity(getReadCommunityString());
        if (getWriteCommunityString() != null)
            definition.setWriteCommunity(getWriteCommunityString());
    }
    if (isSpecific()) {
        definition.addSpecific(getFirstIPAddress());
    } else {
        // first ip address of range must be < than last ip address of range
        if (BigInteger.ZERO.compareTo(InetAddressUtils.difference(getFirstIPAddress(), getLastIPAddress())) < 0) {
            LOG.error("createDef: Can not create Definition when specified last is < first IP address: {}", this);
            throw new IllegalArgumentException("First: " + getFirstIPAddress() + " is greater than: " + getLastIPAddress());
        }
        Range range = new Range();
        range.setBegin(getFirstIPAddress());
        range.setEnd(getLastIPAddress());
        definition.addRange(range);
    }
    LOG.debug("createDef: created new Definition from: {}", this);
    return definition;
}
Also used : Definition(org.opennms.netmgt.config.snmp.Definition) Range(org.opennms.netmgt.config.snmp.Range)

Example 3 with Definition

use of org.opennms.netmgt.config.snmp.Definition in project opennms by OpenNMS.

the class SnmpPeerFactory method getAgentConfig.

public SnmpAgentConfig getAgentConfig(final InetAddress agentInetAddress, String location, final int requestedSnmpVersion) {
    getReadLock().lock();
    try {
        if (getSnmpConfig() == null) {
            final SnmpAgentConfig agentConfig = new SnmpAgentConfig(agentInetAddress);
            if (requestedSnmpVersion == SnmpAgentConfig.VERSION_UNSPECIFIED) {
                agentConfig.setVersion(SnmpAgentConfig.DEFAULT_VERSION);
            } else {
                agentConfig.setVersion(requestedSnmpVersion);
            }
            return agentConfig;
        }
        final SnmpAgentConfig agentConfig = new SnmpAgentConfig(agentInetAddress);
        // Now set the defaults from the getSnmpConfig()
        setSnmpAgentConfig(agentConfig, new Definition(), requestedSnmpVersion);
        final AddressSnmpConfigVisitor visitor = new AddressSnmpConfigVisitor(agentInetAddress, location);
        getSnmpConfig().visit(visitor);
        final Definition matchingDef = visitor.getDefinition();
        if (matchingDef != null) {
            setSnmpAgentConfig(agentConfig, matchingDef, requestedSnmpVersion);
        }
        return agentConfig;
    } finally {
        getReadLock().unlock();
    }
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) AddressSnmpConfigVisitor(org.opennms.netmgt.config.snmp.AddressSnmpConfigVisitor) Definition(org.opennms.netmgt.config.snmp.Definition)

Example 4 with Definition

use of org.opennms.netmgt.config.snmp.Definition in project opennms by OpenNMS.

the class SnmpEventInfoTest method testCreateDefForSnmpV3.

@Test
public void testCreateDefForSnmpV3() {
    SnmpEventInfo snmpEventInfo = new SnmpEventInfo();
    snmpEventInfo.setAuthPassPhrase("authPassPhrase");
    snmpEventInfo.setAuthProtocol("authProtocol");
    snmpEventInfo.setReadCommunityString("communityString");
    snmpEventInfo.setWriteCommunityString("writeCommunityString");
    snmpEventInfo.setContextEngineId("contextEngineId");
    snmpEventInfo.setContextName("contextName");
    snmpEventInfo.setEngineId("engineId");
    snmpEventInfo.setEnterpriseId("enterpriseId");
    snmpEventInfo.setMaxRepetitions(1000);
    snmpEventInfo.setMaxVarsPerPdu(2000);
    snmpEventInfo.setMaxRequestSize(7000);
    snmpEventInfo.setPort(3000);
    snmpEventInfo.setProxyHost("127.0.0.1");
    snmpEventInfo.setPrivPassPhrase("privPassPhrase");
    snmpEventInfo.setPrivProtocol("privProtocol");
    snmpEventInfo.setRetryCount(4000);
    snmpEventInfo.setSecurityLevel(5000);
    snmpEventInfo.setTimeout(6000);
    snmpEventInfo.setVersion("v3");
    // check v3/commons propertiess
    Definition def = snmpEventInfo.createDef();
    assertEquals(snmpEventInfo.getAuthPassphrase(), def.getAuthPassphrase());
    assertEquals(snmpEventInfo.getAuthProtocol(), def.getAuthProtocol());
    assertEquals(snmpEventInfo.getContextEngineId(), def.getContextEngineId());
    assertEquals(snmpEventInfo.getContextName(), def.getContextName());
    assertEquals(snmpEventInfo.getEngineId(), def.getEngineId());
    assertEquals(snmpEventInfo.getEnterpriseId(), def.getEnterpriseId());
    assertEquals(snmpEventInfo.getPrivPassPhrase(), def.getPrivacyPassphrase());
    assertEquals(snmpEventInfo.getPrivProtocol(), def.getPrivacyProtocol());
    assertEquals(snmpEventInfo.getMaxRepetitions(), def.getMaxRepetitions().intValue());
    assertEquals(snmpEventInfo.getMaxVarsPerPdu(), def.getMaxVarsPerPdu().intValue());
    assertEquals(snmpEventInfo.getMaxRequestSize(), def.getMaxRequestSize().intValue());
    assertEquals(snmpEventInfo.getPort(), def.getPort().intValue());
    assertEquals(snmpEventInfo.getProxyHost(), def.getProxyHost());
    assertEquals(snmpEventInfo.getRetryCount(), def.getRetry().intValue());
    assertEquals(snmpEventInfo.getTimeout(), def.getTimeout().intValue());
    assertEquals(snmpEventInfo.getVersion(), def.getVersion());
    // v1/v2 properties must not be set
    assertNull(def.getReadCommunity());
    assertNull(def.getWriteCommunity());
}
Also used : Definition(org.opennms.netmgt.config.snmp.Definition) Test(org.junit.Test)

Aggregations

Definition (org.opennms.netmgt.config.snmp.Definition)4 Test (org.junit.Test)2 AddressSnmpConfigVisitor (org.opennms.netmgt.config.snmp.AddressSnmpConfigVisitor)1 Range (org.opennms.netmgt.config.snmp.Range)1 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)1