Search in sources :

Example 91 with UndeclaredThrowableException

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

the class HttpCollector method initHttpCollectionConfig.

private static void initHttpCollectionConfig() {
    try {
        LOG.debug("initialize: Initializing collector: {}", HttpCollector.class.getSimpleName());
        HttpCollectionConfigFactory.init();
    } catch (FileNotFoundException e) {
        LOG.error("initialize: Error locating configuration.", e);
        throw new UndeclaredThrowableException(e);
    } catch (IOException e) {
        LOG.error("initialize: Error reading configuration", e);
        throw new UndeclaredThrowableException(e);
    }
}
Also used : UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 92 with UndeclaredThrowableException

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

the class SmtpMonitorIT method testPollSvrStatus554.

@Test
public void testPollSvrStatus554() throws UnknownHostException, InterruptedException {
    m_serverThread = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                m_serverSocket.setSoTimeout(1000);
                Socket s = m_serverSocket.accept();
                System.out.println("S: 554 localhost.localdomain ESMTP bogon");
                s.getOutputStream().write("554 localhost.localdomain ESMTP bogon\r\n".getBytes());
                BufferedReader r = new BufferedReader(new InputStreamReader(s.getInputStream()));
                String command = r.readLine();
                System.out.println("C: " + command);
                if (command.equals("QUIT")) {
                    System.out.println("S: 221-Goodbye, friend.");
                    s.getOutputStream().write("221-Goodbye, friend.\r\n".getBytes());
                    System.out.println("S: 221 See ya");
                    s.getOutputStream().write("221 See ya\r\n".getBytes());
                }
            } catch (Throwable e) {
                throw new UndeclaredThrowableException(e);
            }
        }
    });
    m_serverThread.start();
    ServiceMonitor sm = new SmtpMonitor();
    MonitoredService svc = new MockMonitoredService(1, "Node One", InetAddressUtils.addr("127.0.0.1"), "SMTP");
    Map<String, Object> parms = new HashMap<String, Object>();
    parms.put("port", m_serverSocket.getLocalPort());
    PollStatus ps = sm.poll(svc, parms);
    assertTrue(ps.isUnavailable());
    assertFalse(ps.isUp());
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) MonitoredService(org.opennms.netmgt.poller.MonitoredService) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) BufferedReader(java.io.BufferedReader) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) Test(org.junit.Test)

Example 93 with UndeclaredThrowableException

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

the class SmtpMonitorIT method testPollCase1.

@Test
public void testPollCase1() throws UnknownHostException, InterruptedException {
    m_serverThread = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                m_serverSocket.setSoTimeout(1000);
                Socket s = m_serverSocket.accept();
                System.out.println("S: 220-localhost.localdomain ESMTP bogon");
                s.getOutputStream().write("220-localhost.localdomain ESMTP bogon\r\n".getBytes());
                System.out.println("S: 220-send me mail soon!");
                s.getOutputStream().write("220-send me mail soon!\r\n".getBytes());
                System.out.println("S: 220 send me mail now!");
                s.getOutputStream().write("220 send me mail now!\r\n".getBytes());
                BufferedReader r = new BufferedReader(new InputStreamReader(s.getInputStream()));
                String command = r.readLine();
                System.out.println("C: " + command);
                if (command.startsWith("HELO ")) {
                    System.out.println("S: 250 Hello");
                    s.getOutputStream().write("250 Hello\r\n".getBytes());
                }
                command = r.readLine();
                System.out.println("C: " + command);
                if (command.equals("QUIT")) {
                    System.out.println("S: 250 Hello");
                    s.getOutputStream().write("221 See ya\r\n".getBytes());
                }
            } catch (Throwable e) {
                throw new UndeclaredThrowableException(e);
            }
        }
    });
    m_serverThread.start();
    ServiceMonitor sm = new SmtpMonitor();
    MonitoredService svc = new MockMonitoredService(1, "Node One", InetAddressUtils.addr("127.0.0.1"), "SMTP");
    Map<String, Object> parms = new HashMap<String, Object>();
    parms.put("port", m_serverSocket.getLocalPort());
    PollStatus ps = sm.poll(svc, parms);
    assertTrue(ps.isUp());
    assertFalse(ps.isDown());
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) MonitoredService(org.opennms.netmgt.poller.MonitoredService) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) BufferedReader(java.io.BufferedReader) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) Test(org.junit.Test)

Example 94 with UndeclaredThrowableException

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

the class PercDetector 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);
        SnmpObjId snmpObjectId = SnmpObjId.get(LOGICAL_BASE_OID + '.' + m_arrayNumber);
        SnmpValue value = SnmpUtils.get(agentConfig, snmpObjectId);
        if (value.toInt() != 2) {
            LOG.debug("PercMonitor.poll: Bad Disk Found. Log vol({}) degraded", m_arrayNumber);
            return false;
        }
    } catch (Throwable t) {
        throw new UndeclaredThrowableException(t);
    }
    return true;
}
Also used : SnmpValue(org.opennms.netmgt.snmp.SnmpValue) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId)

Example 95 with UndeclaredThrowableException

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

the class SnmpDetector method isServiceDetected.

@Override
public boolean isServiceDetected(InetAddress address, SnmpAgentConfig agentConfig) {
    try {
        configureAgentPTR(agentConfig);
        configureAgentVersion(agentConfig);
        final String expectedValue = getVbvalue();
        if (this.m_isTable) {
            LOG.debug(getServiceName() + ": table detect enabled");
            final SnmpObjId snmpObjId = SnmpObjId.get(getOid());
            final Map<SnmpInstId, SnmpValue> table = SnmpUtils.getOidValues(agentConfig, DEFAULT_SERVICE_NAME, snmpObjId);
            final List<String> retrievedValues = table.values().stream().map(snmpValue -> m_hex ? snmpValue.toHexString() : snmpValue.toString()).collect(Collectors.toList());
            return isServiceDetected(this.matchType, retrievedValues, expectedValue);
        } else {
            final String retrievedValue = getValue(agentConfig, getOid(), m_hex);
            // we have to ensure that if expectedValue is defined, we use ANY, this is due to backwards compatibility
            MatchType matchType = this.matchType;
            if (matchType == null && expectedValue != null) {
                matchType = MatchType.Any;
            }
            return isServiceDetected(matchType, Lists.newArrayList(retrievedValue), expectedValue);
        }
    } catch (Throwable t) {
        throw new UndeclaredThrowableException(t);
    }
}
Also used : Logger(org.slf4j.Logger) DetectRequest(org.opennms.netmgt.provision.DetectRequest) LoggerFactory(org.slf4j.LoggerFactory) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) Collectors(java.util.stream.Collectors) InetAddress(java.net.InetAddress) Objects(java.util.Objects) SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) List(java.util.List) SnmpUtils(org.opennms.netmgt.snmp.SnmpUtils) Lists(com.google.common.collect.Lists) AgentBasedSyncAbstractDetector(org.opennms.netmgt.provision.support.AgentBasedSyncAbstractDetector) Map(java.util.Map) Pattern(java.util.regex.Pattern) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId)

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