Search in sources :

Example 46 with UndeclaredThrowableException

use of java.lang.reflect.UndeclaredThrowableException in project OpenAM by OpenRock.

the class TOTPAlgorithm method hmac_sha.

/**
     * This method uses the JCE to provide the crypto algorithm.
     * HMAC computes a Hashed Message Authentication Code with the
     * crypto hash algorithm as a parameter.
     *
     * @param crypto   the crypto algorithm (HmacSHA1, HmacSHA256,
     *                 HmacSHA512)
     * @param keyBytes the bytes to use for the HMAC key
     * @param text     the message or text to be authenticated
     */
private static byte[] hmac_sha(String crypto, byte[] keyBytes, byte[] text) {
    try {
        Mac hmac;
        hmac = Mac.getInstance(crypto);
        SecretKeySpec macKey = new SecretKeySpec(keyBytes, "RAW");
        hmac.init(macKey);
        return hmac.doFinal(text);
    } catch (GeneralSecurityException gse) {
        throw new UndeclaredThrowableException(gse);
    }
}
Also used : SecretKeySpec(javax.crypto.spec.SecretKeySpec) GeneralSecurityException(java.security.GeneralSecurityException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) Mac(javax.crypto.Mac)

Example 47 with UndeclaredThrowableException

use of java.lang.reflect.UndeclaredThrowableException in project opennms by OpenNMS.

the class CiscoIpSlaDetector method isServiceDetected.

/**
     * {@inheritDoc}
     *
     * Returns true if the protocol defined by this plugin is supported. If
     * the protocol is not supported then a false value is returned to the
     * caller. The qualifier map passed to the method is used by the plugin to
     * return additional information by key-name. These key-value pairs can be
     * added to service events if needed.
     */
@Override
public boolean isServiceDetected(final InetAddress address, final SnmpAgentConfig agentConfig) {
    try {
        configureAgentPTR(agentConfig);
        configureAgentVersion(agentConfig);
        Map<SnmpInstId, SnmpValue> tagResults = SnmpUtils.getOidValues(agentConfig, "CiscoIpSlaDetector", SnmpObjId.get(RTT_ADMIN_TAG_OID));
        if (tagResults == null) {
            LOG.warn("isServiceDetected: No admin tags received!");
            return false;
        }
        Map<SnmpInstId, SnmpValue> operStateResults = SnmpUtils.getOidValues(agentConfig, "CiscoIpSlaDetector", SnmpObjId.get(RTT_OPER_STATE_OID));
        if (operStateResults == null) {
            LOG.warn("isServiceDetected: No operational states received!");
            return false;
        }
        // Iterate over the list of configured IP SLAs
        for (Entry<SnmpInstId, SnmpValue> ipslaEntry : tagResults.entrySet()) {
            SnmpValue status = operStateResults.get(ipslaEntry.getKey());
            LOG.debug("isServiceDetected: admin-tag={} value={} oper-state={}", m_adminTag, formatValue(ipslaEntry.getValue()), status.toInt());
            //  Check if a configured IP SLA with specific tag exist and is the operational state active 
            if (m_adminTag.equals(formatValue(ipslaEntry.getValue())) && status.toInt() == RTT_MON_OPER_STATE_ACTIVE) {
                LOG.debug("isServiceDetected: admin tag found");
                return true;
            }
        }
    } catch (Throwable t) {
        throw new UndeclaredThrowableException(t);
    }
    return false;
}
Also used : SnmpValue(org.opennms.netmgt.snmp.SnmpValue) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId)

Example 48 with UndeclaredThrowableException

use of java.lang.reflect.UndeclaredThrowableException in project opennms by OpenNMS.

the class DiskUsageDetector method isServiceDetected.

/**
     * {@inheritDoc}
     *
     * Returns true if the protocol defined by this plugin is supported. If the
     * protocol is not supported then a false value is returned to the caller.
     * The qualifier map passed to the method is used by the plugin to return
     * additional information by key-name. These key-value pairs can be added to
     * service events if needed.
     */
@Override
public boolean isServiceDetected(final InetAddress address, final SnmpAgentConfig agentConfig) {
    int matchType = MATCH_TYPE_EXACT;
    try {
        if (getPort() > 0) {
            agentConfig.setPort(getPort());
        }
        if (getTimeout() > 0) {
            agentConfig.setTimeout(getTimeout());
        }
        if (getRetries() > -1) {
            agentConfig.setRetries(getRetries());
        }
        if (getForceVersion() != null) {
            String version = getForceVersion();
            // @see http://issues.opennms.org/browse/NMS-7518
            if ("v1".equalsIgnoreCase(version) || "snmpv1".equalsIgnoreCase(version)) {
                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);
            }
        }
        //
        if (!"".equals(getMatchType())) {
            String matchTypeStr = getMatchType();
            if (matchTypeStr.equalsIgnoreCase("exact")) {
                matchType = MATCH_TYPE_EXACT;
            } else if (matchTypeStr.equalsIgnoreCase("startswith")) {
                matchType = MATCH_TYPE_STARTSWITH;
            } else if (matchTypeStr.equalsIgnoreCase("endswith")) {
                matchType = MATCH_TYPE_ENDSWITH;
            } else if (matchTypeStr.equalsIgnoreCase("regex")) {
                matchType = MATCH_TYPE_REGEX;
            } else {
                throw new RuntimeException("Unknown value '" + matchTypeStr + "' for parameter 'match-type'");
            }
        }
        SnmpObjId hrStorageDescrSnmpObject = SnmpObjId.get(getHrStorageDescr());
        Map<SnmpInstId, SnmpValue> descrResults = SnmpUtils.getOidValues(agentConfig, "DiskUsagePoller", hrStorageDescrSnmpObject);
        if (descrResults.size() == 0) {
            return false;
        }
        for (Map.Entry<SnmpInstId, SnmpValue> e : descrResults.entrySet()) {
            LOG.debug("capsd: SNMPwalk succeeded, addr={} oid={} instance={} value={}", InetAddressUtils.str(agentConfig.getAddress()), hrStorageDescrSnmpObject, e.getKey(), e.getValue());
            if (isMatch(e.getValue().toString(), getDisk(), matchType)) {
                LOG.debug("Found disk '{}' (matching hrStorageDescr was '{}')", getDisk(), e.getValue());
                return true;
            }
        }
        return false;
    } catch (Throwable t) {
        throw new UndeclaredThrowableException(t);
    }
}
Also used : SnmpValue(org.opennms.netmgt.snmp.SnmpValue) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) Map(java.util.Map)

Example 49 with UndeclaredThrowableException

use of java.lang.reflect.UndeclaredThrowableException in project opennms by OpenNMS.

the class OpenManageChassisDetector method isServiceDetected.

/**
     * {@inheritDoc}
     *
     * Returns true if the protocol defined by this plugin is supported. If
     * the protocol is not supported then a false value is returned to the
     * caller. The qualifier map passed to the method is used by the plugin to
     * return additional information by key-name. These key-value pairs can be
     * added to service events if needed.
     */
@Override
public boolean isServiceDetected(final InetAddress address, final SnmpAgentConfig agentConfig) {
    try {
        configureAgentPTR(agentConfig);
        configureAgentVersion(agentConfig);
        // Get the OpenManage chassis status
        String chassisStatus = getValue(agentConfig, CHASSIS_STATUS_OID, isHex());
        // If no chassis status received, do not detect the protocol and quit
        if (chassisStatus == null) {
            LOG.warn("isServiceDetected: Cannot receive chassis status");
            return false;
        } else {
            LOG.debug("isServiceDetected: OpenManageChassis: {}", chassisStatus);
        }
        // Validate chassis status, check status is somewhere between OTHER and NON_RECOVERABLE
        if (Integer.parseInt(chassisStatus) >= DELL_STATUS.OTHER.value() && Integer.parseInt(chassisStatus) <= DELL_STATUS.NON_RECOVERABLE.value()) {
            // OpenManage chassis status detected
            LOG.debug("isServiceDetected: OpenManageChassis: is valid, protocol supported.");
            return true;
        }
    } catch (Throwable t) {
        throw new UndeclaredThrowableException(t);
    }
    return false;
}
Also used : UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException)

Example 50 with UndeclaredThrowableException

use of java.lang.reflect.UndeclaredThrowableException in project opennms by OpenNMS.

the class TrapListener method start.

public void start() {
    final int m_snmpTrapPort = m_config.getSnmpTrapPort();
    final InetAddress address = getInetAddress();
    try {
        LOG.info("Listening on {}:{}", address == null ? "[all interfaces]" : InetAddressUtils.str(address), m_snmpTrapPort);
        SnmpUtils.registerForTraps(this, address, m_snmpTrapPort, m_config.getSnmpV3Users());
        m_registeredForTraps = true;
        LOG.debug("init: Creating the trap session");
    } catch (final IOException e) {
        if (e instanceof java.net.BindException) {
            Logging.withPrefix("OpenNMS.Manager", new Runnable() {

                @Override
                public void run() {
                    LOG.error("init: Failed to listen on SNMP trap port {}, perhaps something else is already listening?", m_snmpTrapPort, e);
                }
            });
            LOG.error("init: Failed to listen on SNMP trap port {}, perhaps something else is already listening?", m_snmpTrapPort, e);
            throw new UndeclaredThrowableException(e, "Failed to listen on SNMP trap port " + m_snmpTrapPort + ", perhaps something else is already listening?");
        } else {
            LOG.error("init: Failed to initialize SNMP trap socket on port {}", m_snmpTrapPort, e);
            throw new UndeclaredThrowableException(e, "Failed to initialize SNMP trap socket on port " + m_snmpTrapPort);
        }
    }
}
Also used : UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) IOException(java.io.IOException) InetAddress(java.net.InetAddress)

Aggregations

UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)121 IOException (java.io.IOException)36 InvocationTargetException (java.lang.reflect.InvocationTargetException)14 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)14 Test (org.junit.Test)12 BufferedReader (java.io.BufferedReader)10 InputStreamReader (java.io.InputStreamReader)10 ServerSocket (java.net.ServerSocket)10 Socket (java.net.Socket)9 PollStatus (org.opennms.netmgt.poller.PollStatus)9 HashMap (java.util.HashMap)8 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)7 AuthorizationException (org.apache.hadoop.security.authorize.AuthorizationException)7 BadRequestException (org.apache.hadoop.yarn.webapp.BadRequestException)7 Method (java.lang.reflect.Method)6 AccessControlException (java.security.AccessControlException)6 SQLException (java.sql.SQLException)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)6