Search in sources :

Example 6 with SnmpInfo

use of org.opennms.web.svclayer.model.SnmpInfo in project opennms by OpenNMS.

the class SnmpConfigRestServiceIT method testGetForUnknownIpSnmpV3.

/**
 * Tests if the default values are set correctly according to the default configuration file if
 * the SNMP version is v3.
 *
 * @throws Exception
 */
@Test
public void testGetForUnknownIpSnmpV3() throws Exception {
    String url = "/snmpConfig/1.1.1.1";
    setSnmpConfigFile(getSnmpDefaultConfigFileForSnmpV3());
    // Testing GET Collection
    SnmpInfo config = getXmlObject(m_jaxbContext, url, 200, SnmpInfo.class);
    SnmpInfo expectedConfig = createSnmpInfoWithDefaultsForSnmpV3("1.1.1.1");
    // check if expected defaults matches actual defaults
    assertConfiguration(expectedConfig, config);
    assertSnmpV1PropertiesHaveNotBeenSet(config);
}
Also used : SnmpInfo(org.opennms.web.svclayer.model.SnmpInfo) Test(org.junit.Test)

Example 7 with SnmpInfo

use of org.opennms.web.svclayer.model.SnmpInfo in project opennms by OpenNMS.

the class SnmpConfigRestServiceIT method testGetForUnknownIpSnmpV1.

/**
 * Tests if the default values are set correctly according to the default configuration file if
 * the SNMP version is v1.
 *
 * @throws Exception
 */
@Test
public void testGetForUnknownIpSnmpV1() throws Exception {
    String url = "/snmpConfig/1.1.1.1";
    // Testing GET Collection
    SnmpInfo config = getXmlObject(m_jaxbContext, url, 200, SnmpInfo.class);
    SnmpInfo expectedConfig = createSnmpInfoWithDefaultsForSnmpV1();
    assertConfiguration(expectedConfig, config);
    assertSnmpV3PropertiesHaveNotBeenSet(config);
}
Also used : SnmpInfo(org.opennms.web.svclayer.model.SnmpInfo) Test(org.junit.Test)

Example 8 with SnmpInfo

use of org.opennms.web.svclayer.model.SnmpInfo in project opennms by OpenNMS.

the class SnmpConfigRestServiceIT method createSnmpInfoWithDefaultsForSnmpV1.

private SnmpInfo createSnmpInfoWithDefaultsForSnmpV1() {
    SnmpAgentConfig defaults = new SnmpAgentConfig();
    SnmpInfo config = new SnmpInfo();
    config.setPort(DEFAULT_PORT);
    config.setRetries(DEFAULT_RETRIES);
    config.setTimeout(DEFAULT_TIMEOUT);
    config.setReadCommunity(DEFAULT_COMMUNITY);
    config.setVersion(DEFAULT_VERSION);
    config.setMaxVarsPerPdu(DEFAULT_MAX_VARS_PER_PDU);
    config.setMaxRepetitions(DEFAULT_MAX_REPETITIONS);
    // defaults are not set via snmp-config.xml, but via defaults in SnmpAgentConfig
    config.setWriteCommunity(defaults.getWriteCommunity());
    config.setMaxRequestSize(defaults.getMaxRequestSize());
    return config;
}
Also used : SnmpInfo(org.opennms.web.svclayer.model.SnmpInfo) SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig)

Example 9 with SnmpInfo

use of org.opennms.web.svclayer.model.SnmpInfo in project opennms by OpenNMS.

the class SnmpConfigRestServiceIT method testSetNewValueForSnmpV3.

@Test
public void testSetNewValueForSnmpV3() throws Exception {
    String url = "/snmpConfig/1.1.1.1";
    // Testing GET Collection
    SnmpInfo changedConfig = getXmlObject(m_jaxbContext, url, 200, SnmpInfo.class);
    SnmpInfo expectedConfig = createSnmpInfoWithDefaultsForSnmpV3("1.1.1.1");
    // check if expected defaults matches actual defaults
    assertConfiguration(expectedConfig, changedConfig);
    // change values
    changedConfig.setAuthPassPhrase("authPassPhrase");
    changedConfig.setAuthProtocol("authProtocol");
    changedConfig.setReadCommunity("readCommunity");
    changedConfig.setWriteCommunity("writeCommunity");
    changedConfig.setContextEngineId("contextEngineId");
    changedConfig.setContextName("contextName");
    changedConfig.setEngineId("engineId");
    changedConfig.setEnterpriseId("enterpriseId");
    changedConfig.setMaxRepetitions(1000);
    changedConfig.setMaxVarsPerPdu(2000);
    changedConfig.setPort(3000);
    changedConfig.setProxyHost("127.0.0.1");
    changedConfig.setPrivPassPhrase("privPassPhrase");
    changedConfig.setPrivProtocol("privProtocol");
    changedConfig.setRetries(4000);
    changedConfig.setSecurityLevel(5000);
    changedConfig.setSecurityName("securityName");
    changedConfig.setTimeout(6000);
    changedConfig.setVersion("v3");
    changedConfig.setMaxRequestSize(7000);
    // store them via REST
    putXmlObject(m_jaxbContext, url, 204, changedConfig);
    // prepare expected Result
    expectedConfig = new SnmpInfo();
    expectedConfig.setAuthPassPhrase("authPassPhrase");
    expectedConfig.setAuthProtocol("authProtocol");
    expectedConfig.setContextEngineId("contextEngineId");
    expectedConfig.setContextName("contextName");
    expectedConfig.setEngineId("engineId");
    expectedConfig.setEnterpriseId("enterpriseId");
    expectedConfig.setMaxRepetitions(1000);
    expectedConfig.setMaxVarsPerPdu(2000);
    expectedConfig.setPort(3000);
    expectedConfig.setProxyHost("127.0.0.1");
    expectedConfig.setPrivPassPhrase("privPassPhrase");
    expectedConfig.setPrivProtocol("privProtocol");
    expectedConfig.setRetries(4000);
    expectedConfig.setSecurityLevel(5000);
    expectedConfig.setSecurityName("securityName");
    expectedConfig.setTimeout(6000);
    expectedConfig.setVersion("v3");
    expectedConfig.setMaxRequestSize(7000);
    expectedConfig.setReadCommunity(null);
    expectedConfig.setWriteCommunity(null);
    // read via REST
    SnmpInfo newConfig = getXmlObject(m_jaxbContext, url, 200, SnmpInfo.class);
    // check ...
    // ... if changes were made
    assertConfiguration(expectedConfig, newConfig);
    dumpConfig();
}
Also used : SnmpInfo(org.opennms.web.svclayer.model.SnmpInfo) Test(org.junit.Test)

Example 10 with SnmpInfo

use of org.opennms.web.svclayer.model.SnmpInfo in project opennms by OpenNMS.

the class SnmpConfigServlet method process.

/*
	 * Processes the request.
	 */
private void process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    SnmpInfo snmpInfo = createFromRequest(request);
    String firstIPAddress = request.getParameter("firstIPAddress");
    String lastIPAddress = request.getParameter("lastIPAddress");
    String ipAddress = request.getParameter("ipAddress");
    String location = request.getParameter("location");
    LOG.debug("doPost: snmpInfo:{}, firstIpAddress:{}, lastIpAddress:{}", snmpInfo.toString(), firstIPAddress, lastIPAddress);
    final SnmpConfigServletAction action = determineAction(request);
    boolean sendEvent = parseCheckboxValue(request.getParameter("sendEventOption"));
    boolean saveLocally = parseCheckboxValue(request.getParameter("saveLocallyOption"));
    switch(action) {
        case GetConfigForIp:
            request.setAttribute("snmpConfigForIp", new SnmpInfo(SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr(ipAddress), location)));
            request.setAttribute("firstIPAddress", ipAddress);
            request.setAttribute("location", location);
            break;
        case Save:
            boolean success = false;
            SnmpEventInfo eventInfo = snmpInfo.createEventInfo(firstIPAddress, lastIPAddress);
            if (saveLocally) {
                SnmpPeerFactory.getInstance().define(eventInfo);
                SnmpPeerFactory.getInstance().saveCurrent();
                success |= true;
            }
            if (sendEvent) {
                success |= sendEvent(eventInfo.createEvent("web ui"));
            }
            // the value doesn't matter, but it must be not null
            if (success)
                request.setAttribute("success", "success");
            break;
        default:
        case Default:
            break;
    }
    request.setAttribute("snmpConfig", Files.toString(SnmpPeerFactory.getFile(), StandardCharsets.UTF_8));
    RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/admin/snmpConfig.jsp");
    dispatcher.forward(request, response);
}
Also used : SnmpInfo(org.opennms.web.svclayer.model.SnmpInfo) SnmpEventInfo(org.opennms.netmgt.config.SnmpEventInfo) RequestDispatcher(javax.servlet.RequestDispatcher)

Aggregations

SnmpInfo (org.opennms.web.svclayer.model.SnmpInfo)10 Test (org.junit.Test)5 Path (javax.ws.rs.Path)2 SnmpEventInfo (org.opennms.netmgt.config.SnmpEventInfo)2 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)2 InetAddress (java.net.InetAddress)1 RequestDispatcher (javax.servlet.RequestDispatcher)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 PUT (javax.ws.rs.PUT)1 Produces (javax.ws.rs.Produces)1 Transactional (org.springframework.transaction.annotation.Transactional)1