Search in sources :

Example 1 with SnmpEventInfo

use of org.opennms.netmgt.config.SnmpEventInfo in project opennms by OpenNMS.

the class SnmpInfo method createEventInfo.

/**
	 * Creates a {@link SnmpEventInfo} object from <code>this</code>.
	 * 
	 * @param firstIpAddress
	 *            a {@link java.lang.String} object which represents the first IP Address of the {@link SnmpEventInfo}. Must not be null.
	 * @param lastIpAddress represents the last IP Address of the {@link SnmpEventInfo}. May be null.
	 * @return a {@link org.opennms.netmgt.config.SnmpEventInfo} object. 
	 * @throws java.net.UnknownHostException if any.
	 */
public SnmpEventInfo createEventInfo(String firstIpAddress, String lastIpAddress) throws UnknownHostException {
    SnmpEventInfo eventInfo = new SnmpEventInfo();
    eventInfo.setVersion(m_version);
    eventInfo.setAuthPassPhrase(m_authPassPhrase);
    eventInfo.setAuthProtocol(m_authProtocol);
    eventInfo.setReadCommunityString(m_readCommunity);
    eventInfo.setWriteCommunityString(m_writeCommunity);
    eventInfo.setContextEngineId(m_contextEngineId);
    eventInfo.setContextName(m_contextName);
    eventInfo.setEngineId(m_engineId);
    eventInfo.setEnterpriseId(m_enterpriseId);
    eventInfo.setFirstIPAddress(firstIpAddress);
    eventInfo.setLastIPAddress(lastIpAddress);
    eventInfo.setPrivPassPhrase(m_privPassPhrase);
    eventInfo.setPrivProtocol(m_privProtocol);
    eventInfo.setSecurityName(m_securityName);
    eventInfo.setProxyHost(m_proxyHost);
    eventInfo.setLocation(m_location);
    if (m_port != null)
        eventInfo.setPort(m_port.intValue());
    if (m_retries != null)
        eventInfo.setRetryCount(m_retries.intValue());
    if (m_timeout != null)
        eventInfo.setTimeout(m_timeout.intValue());
    if (m_maxRepetitions != null)
        eventInfo.setMaxRepetitions(m_maxRepetitions.intValue());
    if (m_maxVarsPerPdu != null)
        eventInfo.setMaxVarsPerPdu(m_maxVarsPerPdu.intValue());
    if (m_maxRequestSize != null)
        eventInfo.setMaxRequestSize(m_maxRequestSize.intValue());
    if (m_securityLevel != null)
        eventInfo.setSecurityLevel(m_securityLevel.intValue());
    if (m_maxRequestSize != null)
        eventInfo.setMaxRequestSize(m_maxRequestSize.intValue());
    return eventInfo;
}
Also used : SnmpEventInfo(org.opennms.netmgt.config.SnmpEventInfo)

Example 2 with SnmpEventInfo

use of org.opennms.netmgt.config.SnmpEventInfo in project opennms by OpenNMS.

the class SnmpConfigRestService method setSnmpInfo.

/**
     * <p>setSnmpInfo</p>
     *
     * @param ipAddress a {@link java.lang.String} object.
     * @param snmpInfo a {@link org.opennms.web.snmpinfo.SnmpInfo} object.
     * @return a {@link javax.ws.rs.core.Response} object.
     */
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
@Path("{ipAddr}")
public Response setSnmpInfo(@PathParam("ipAddr") final String ipAddress, final SnmpInfo snmpInfo) {
    writeLock();
    try {
        final SnmpEventInfo eventInfo;
        if (ipAddress.contains("-")) {
            final String[] addrs = SnmpConfigRestService.getAddresses(ipAddress);
            eventInfo = snmpInfo.createEventInfo(addrs[0], addrs[1]);
        } else {
            eventInfo = snmpInfo.createEventInfo(ipAddress);
        }
        m_accessService.define(eventInfo);
        return Response.noContent().build();
    } catch (final Throwable e) {
        throw getException(Status.INTERNAL_SERVER_ERROR, "Can't update SNMP configuration for {} : {}", ipAddress, e.getMessage());
    } finally {
        writeUnlock();
    }
}
Also used : SnmpEventInfo(org.opennms.netmgt.config.SnmpEventInfo) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 3 with SnmpEventInfo

use of org.opennms.netmgt.config.SnmpEventInfo in project opennms by OpenNMS.

the class SnmpPoller method reloadSnmpConfig.

/**
     * <p>reloadSnmpConfig</p>
     *
     * @param event a {@link org.opennms.netmgt.xml.event.Event} object.
     */
@EventHandler(uei = EventConstants.CONFIGURE_SNMP_EVENT_UEI)
public void reloadSnmpConfig(Event event) {
    LOG.debug("reloadSnmpConfig: managing event: {}", event.getUei());
    try {
        Thread.sleep(5000);
    } catch (final InterruptedException e) {
        LOG.debug("interrupted while waiting for reload", e);
        Thread.currentThread().interrupt();
    }
    SnmpEventInfo info = null;
    try {
        info = new SnmpEventInfo(event);
        if (StringUtils.isBlank(info.getFirstIPAddress())) {
            LOG.error("configureSNMPHandler: event contained invalid firstIpAddress. {}", event);
            return;
        }
    } catch (final Throwable e) {
        LOG.error("reloadSnmpConfig: ", e);
        return;
    }
    final IPAddressRange range = new IPAddressRange(info.getFirstIPAddress(), info.getLastIPAddress());
    for (final IPAddress ipaddr : range) {
        LOG.debug("reloadSnmpConfig: found ipaddr: {}", ipaddr);
        if (getNetwork().hasPollableInterface(ipaddr.toDbString())) {
            LOG.debug("reloadSnmpConfig: recreating the Interface to poll: {}", ipaddr);
            getNetwork().delete(ipaddr.toDbString());
            scheduleNewSnmpInterface(ipaddr.toDbString());
        } else {
            LOG.debug("reloadSnmpConfig: no Interface found for ipaddr: {}", ipaddr);
        }
    }
}
Also used : SnmpEventInfo(org.opennms.netmgt.config.SnmpEventInfo) IPAddressRange(org.opennms.core.network.IPAddressRange) IPAddress(org.opennms.core.network.IPAddress) EventHandler(org.opennms.netmgt.events.api.annotations.EventHandler)

Example 4 with SnmpEventInfo

use of org.opennms.netmgt.config.SnmpEventInfo in project opennms by OpenNMS.

the class SnmpConfigRestService method updateInterface.

/**
     * Updates a specific interface
     *
     * @param ipAddress a {@link java.lang.String} object.
     * @param params a {@link org.opennms.web.rest.support.MultivaluedMapImpl} object.
     * @return a {@link javax.ws.rs.core.Response} object.
     */
@PUT
@Path("{ipAddr}")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Transactional
public Response updateInterface(@PathParam("ipAddr") final String ipAddress, final MultivaluedMapImpl params) {
    writeLock();
    try {
        final SnmpInfo info = new SnmpInfo();
        setProperties(params, info);
        final SnmpEventInfo eventInfo;
        if (ipAddress.contains("-")) {
            final String[] addrs = SnmpConfigRestService.getAddresses(ipAddress);
            eventInfo = info.createEventInfo(addrs[0], addrs[1]);
        } else {
            eventInfo = info.createEventInfo(ipAddress);
        }
        m_accessService.define(eventInfo);
        return Response.noContent().build();
    } catch (final Throwable e) {
        throw getException(Status.INTERNAL_SERVER_ERROR, "Can't update SNMP configuration for {} : {}", ipAddress, e.getMessage());
    } finally {
        writeUnlock();
    }
}
Also used : SnmpInfo(org.opennms.web.svclayer.model.SnmpInfo) SnmpEventInfo(org.opennms.netmgt.config.SnmpEventInfo) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with SnmpEventInfo

use of org.opennms.netmgt.config.SnmpEventInfo 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

SnmpEventInfo (org.opennms.netmgt.config.SnmpEventInfo)6 Consumes (javax.ws.rs.Consumes)2 PUT (javax.ws.rs.PUT)2 Path (javax.ws.rs.Path)2 SnmpInfo (org.opennms.web.svclayer.model.SnmpInfo)2 RequestDispatcher (javax.servlet.RequestDispatcher)1 IPAddress (org.opennms.core.network.IPAddress)1 IPAddressRange (org.opennms.core.network.IPAddressRange)1 EventHandler (org.opennms.netmgt.events.api.annotations.EventHandler)1 Transactional (org.springframework.transaction.annotation.Transactional)1