Search in sources :

Example 1 with XmpConfig

use of org.opennms.netmgt.config.xmpConfig.XmpConfig in project opennms by OpenNMS.

the class XmpCollector method initialize.

/* handleTableQuery() */
/* public methods ************************************ */
/**
     * {@inheritDoc}
     *
     * initialize our XmpCollector with global parameters *
     */
@Override
public void initialize() {
    // initialize our data collection factory
    LOG.debug("initialize(params) called");
    try {
        XmpCollectionFactory.init();
    } catch (Throwable e) {
        LOG.error("initialize: XmpCollectionFactory failed to initialize");
        throw new UndeclaredThrowableException(e);
    }
    try {
        XmpPeerFactory.init();
    } catch (Throwable e) {
        LOG.error("initialize: XmpPeerFactory failed to initialize");
        throw new UndeclaredThrowableException(e);
    }
    try {
        XmpConfigFactory.init();
    } catch (Throwable e) {
        LOG.error("initialize: config factory failed to initialize");
        throw new UndeclaredThrowableException(e);
    }
    if (m_resourceTypesDao == null) {
        m_resourceTypesDao = BeanUtils.getBean("daoContext", "resourceTypesDao", ResourceTypesDao.class);
    }
    // get our top-level object for our protocol config file,
    // xmp-config.xml, already parsed and ready to examine
    XmpConfig protoConfig = XmpConfigFactory.getInstance().getXmpConfig();
    if (protoConfig.hasPort())
        xmpPort = protoConfig.getPort();
    if (protoConfig.hasTimeout())
        timeout = protoConfig.getTimeout();
    // be non-null
    if (protoConfig.getAuthenUser() != null)
        authenUser = protoConfig.getAuthenUser();
    LOG.debug("initialize: authenUser '{}' port {}", authenUser, xmpPort);
    LOG.debug("initialize: keystore found? {}", sockopts.getKeystoreFound());
    return;
}
Also used : ResourceTypesDao(org.opennms.netmgt.config.api.ResourceTypesDao) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) XmpConfig(org.opennms.netmgt.config.xmpConfig.XmpConfig)

Example 2 with XmpConfig

use of org.opennms.netmgt.config.xmpConfig.XmpConfig in project opennms by OpenNMS.

the class XmpDetector method onInit.

public void onInit() {
    LOG.debug("XmpDetector: onInit starting");
    // try to get configuration
    try {
        XmpConfig protoConfig;
        XmpConfigFactory.init();
        protoConfig = XmpConfigFactory.getInstance().getXmpConfig();
        if (protoConfig.hasPort())
            xmpPort = protoConfig.getPort();
        if (protoConfig.hasTimeout())
            xmpTimeout = protoConfig.getTimeout();
        if (protoConfig.getAuthenUser() != null)
            xmpAuthenUser = protoConfig.getAuthenUser();
        sockopts.setConnectTimeout(xmpTimeout);
    } catch (Throwable e) {
        LOG.error("XmpDetector: no config factory, using defaults");
    }
}
Also used : XmpConfig(org.opennms.netmgt.config.xmpConfig.XmpConfig)

Example 3 with XmpConfig

use of org.opennms.netmgt.config.xmpConfig.XmpConfig in project opennms by OpenNMS.

the class XmpMonitor method poll.

/** {@inheritDoc} */
@Override
public PollStatus poll(MonitoredService svc, Map<String, Object> parameters) {
    PollStatus status = PollStatus.unavailable();
    InetAddress ipaddr = svc.getAddress();
    XmpConfig protoConfig = XmpConfigFactory.getInstance().getXmpConfig();
    XmpSession session;
    SocketOpts sockopts = new SocketOpts();
    // TODO how to apply timeout and retry to XMP operations?
    int retry = protoConfig.hasRetry() ? protoConfig.getRetry() : DEFAULT_RETRY;
    int timeout = protoConfig.hasTimeout() ? protoConfig.getTimeout() : DEFAULT_TIMEOUT;
    int port = DEFAULT_PORT;
    String authenUser = DEFAULT_AUTHEN_USER;
    String requestType = DEFAULT_REQUEST_TYPE;
    String mib = DEFAULT_REQUEST_MIB;
    String table = DEFAULT_REQUEST_TABLE;
    String object = DEFAULT_REQUEST_OBJECT;
    String instance = DEFAULT_REQUEST_INSTANCE;
    String instanceMatch = null;
    String valueOperator = XmpUtil.EQUALS;
    String valueOperand = null;
    int minMatches = DEFAULT_MIN_MATCHES;
    int maxMatches = DEFAULT_MAX_MATCHES;
    boolean maxMatchesUnbounded = DEFAULT_MAX_MATCHES_UNBOUNDED;
    boolean valueCaseSensitive = DEFAULT_VALUE_CASE_SENSITIVE;
    if (parameters != null) {
        retry = ParameterMap.getKeyedInteger(parameters, "retry", protoConfig.hasRetry() ? protoConfig.getRetry() : DEFAULT_RETRY);
        timeout = ParameterMap.getKeyedInteger(parameters, "timeout", protoConfig.hasTimeout() ? protoConfig.getTimeout() : DEFAULT_TIMEOUT);
        port = ParameterMap.getKeyedInteger(parameters, "port", protoConfig.hasPort() ? protoConfig.getPort() : DEFAULT_PORT);
        authenUser = ParameterMap.getKeyedString(parameters, "authenUser", (protoConfig.getAuthenUser() != null) ? protoConfig.getAuthenUser() : DEFAULT_AUTHEN_USER);
        requestType = ParameterMap.getKeyedString(parameters, "request-type", DEFAULT_REQUEST_TYPE);
        mib = ParameterMap.getKeyedString(parameters, "mib", DEFAULT_REQUEST_MIB);
        table = ParameterMap.getKeyedString(parameters, "table", DEFAULT_REQUEST_TABLE);
        object = ParameterMap.getKeyedString(parameters, "object", DEFAULT_REQUEST_OBJECT);
        instance = ParameterMap.getKeyedString(parameters, "instance", DEFAULT_REQUEST_INSTANCE);
        instanceMatch = ParameterMap.getKeyedString(parameters, "instance-match", DEFAULT_INSTANCE_MATCH);
        valueOperator = ParameterMap.getKeyedString(parameters, "value-operator", "==");
        valueOperand = ParameterMap.getKeyedString(parameters, "value-match", DEFAULT_VALUE_MATCH);
        valueCaseSensitive = ParameterMap.getKeyedBoolean(parameters, "value-case-sensitive", DEFAULT_VALUE_CASE_SENSITIVE);
        minMatches = ParameterMap.getKeyedInteger(parameters, "min-matches", DEFAULT_MIN_MATCHES);
        maxMatches = ParameterMap.getKeyedInteger(parameters, "max-matches", DEFAULT_MAX_MATCHES);
        String maxMatchesUnboundedStr = ParameterMap.getKeyedString(parameters, "max-matches", "unbounded");
        maxMatchesUnbounded = (maxMatchesUnboundedStr.equalsIgnoreCase("unbounded"));
    }
    // for Table and Object.
    if (requestType.equalsIgnoreCase("SelectTableRequest")) {
        if (table.equals(DEFAULT_REQUEST_TABLE)) {
            throw new IllegalArgumentException("When performing a SelectTableRequest, table must be specified");
        }
        if (object.equals(DEFAULT_REQUEST_OBJECT)) {
            throw new IllegalArgumentException("When performing a SelectTableRequest, object must be specified and must be tabular");
        }
    } else // an instance
    if (requestType.equalsIgnoreCase("GetRequest")) {
        if (!table.equals(DEFAULT_REQUEST_TABLE)) {
            throw new IllegalArgumentException("When performing a GetRequest, table must not be specified");
        }
        if (!instance.equals(DEFAULT_REQUEST_INSTANCE)) {
            throw new IllegalArgumentException("When performing a GetRequest, instance must not be specified");
        }
    } else {
        throw new IllegalArgumentException("Unknown request type " + requestType + ", only GetRequest and SelectTableRequest are supported");
    }
    Pattern instanceRegex = null;
    try {
        if (instanceMatch != null) {
            instanceRegex = Pattern.compile(instanceMatch);
        }
    } catch (final PatternSyntaxException e) {
        throw new java.lang.reflect.UndeclaredThrowableException(e);
    }
    long startTime = System.currentTimeMillis();
    // Set the SO_TIMEOUT.  What a concept!
    sockopts.setConnectTimeout(timeout);
    session = new XmpSession(sockopts, ipaddr, port, authenUser);
    boolean result = false;
    if (requestType.equalsIgnoreCase("SelectTableRequest")) {
        try {
            result = XmpUtil.handleTableQuery(session, mib, table, object, instance, instanceRegex, valueOperator, valueOperand, minMatches, maxMatches, maxMatchesUnbounded, valueCaseSensitive);
        } catch (XmpUtilException e) {
            status = PollStatus.unavailable(e.getMessage());
        }
    } else if (requestType.equalsIgnoreCase("GetRequest")) {
        try {
            result = XmpUtil.handleScalarQuery(session, mib, object, valueOperator, valueOperand, valueCaseSensitive);
        } catch (XmpUtilException e) {
            status = PollStatus.unavailable(e.getMessage());
        }
    }
    if (result == true) {
        Double responseTime = new Double(System.currentTimeMillis() - startTime);
        status = PollStatus.available(responseTime);
    }
    return status;
}
Also used : Pattern(java.util.regex.Pattern) PollStatus(org.opennms.netmgt.poller.PollStatus) XmpUtilException(org.opennms.netmgt.protocols.xmp.XmpUtilException) XmpSession(org.krupczak.xmp.XmpSession) XmpConfig(org.opennms.netmgt.config.xmpConfig.XmpConfig) InetAddress(java.net.InetAddress) SocketOpts(org.krupczak.xmp.SocketOpts) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Aggregations

XmpConfig (org.opennms.netmgt.config.xmpConfig.XmpConfig)3 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 InetAddress (java.net.InetAddress)1 Pattern (java.util.regex.Pattern)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 SocketOpts (org.krupczak.xmp.SocketOpts)1 XmpSession (org.krupczak.xmp.XmpSession)1 ResourceTypesDao (org.opennms.netmgt.config.api.ResourceTypesDao)1 PollStatus (org.opennms.netmgt.poller.PollStatus)1 XmpUtilException (org.opennms.netmgt.protocols.xmp.XmpUtilException)1