Exemplo n.º 1
0
  @Override
  public OnmsAccessPointCollection call() throws IOException {
    OnmsAccessPointCollection apsUp = new OnmsAccessPointCollection();
    InetAddress ipaddr = m_iface.getIpAddress();

    // Retrieve this interface's SNMP peer object
    SnmpAgentConfig agentConfig = getAgentConfig(ipaddr);
    final String hostAddress = InetAddressUtils.str(ipaddr);
    LOG.debug("poll: setting SNMP peer attribute for interface {}", hostAddress);

    // Get configuration parameters
    String oid = ParameterMap.getKeyedString(m_parameters, "oid", null);
    if (oid == null) {
      throw new IllegalStateException("oid parameter is not set.");
    }
    String operator = ParameterMap.getKeyedString(m_parameters, "operator", null);
    String operand = ParameterMap.getKeyedString(m_parameters, "operand", null);
    String matchstr = ParameterMap.getKeyedString(m_parameters, "match", "true");

    LOG.debug("InstanceStrategy.poll: SnmpAgentConfig address= {}", agentConfig);

    // Establish SNMP session with interface
    try {
      SnmpObjId snmpObjectId = SnmpObjId.get(oid);

      Map<SnmpInstId, SnmpValue> map =
          SnmpUtils.getOidValues(agentConfig, "AccessPointMonitor::InstanceStrategy", snmpObjectId);

      if (map.size() <= 0) {
        throw new IOException("No entries found in table (possible timeout).");
      }

      for (Map.Entry<SnmpInstId, SnmpValue> entry : map.entrySet()) {
        boolean isUp = false;
        SnmpInstId instance = entry.getKey();
        SnmpValue value = entry.getValue();

        // Check the value against the configured criteria
        if (meetsCriteria(value, operator, operand)) {
          if ("true".equals(matchstr)) {
            isUp = true;
          }
        } else if ("false".equals(matchstr)) {
          isUp = true;
        }

        // If the criteria is met, find the AP and add it to the list
        // of online APs
        if (isUp) {
          String physAddr = getPhysAddrFromInstance(instance);
          LOG.debug(
              "AP at instance '{}' with MAC '{}' is considered to be ONLINE on controller '{}'",
              instance,
              physAddr,
              m_iface.getIpAddress());
          OnmsAccessPoint ap = m_accessPointDao.get(physAddr);
          if (ap != null) {
            if (ap.getPollingPackage().compareToIgnoreCase(getPackage().getName()) == 0) {
              // Save the controller's IP address
              ap.setControllerIpAddress(ipaddr);
              apsUp.add(ap);
            } else {
              LOG.info("AP with MAC '{}' is in a different package.", physAddr);
            }
          } else {
            LOG.info("No matching AP in database for instance '{}'.", instance);
          }
        }
      }
    } catch (NumberFormatException e) {
      LOG.error("Number operator used on a non-number ", e);
    } catch (IllegalArgumentException e) {
      LOG.error("Invalid SNMP Criteria ", e);
    } catch (InterruptedException e) {
      LOG.error("Interrupted while polling {}", hostAddress, e);
    }

    return apsUp;
  }
Exemplo n.º 2
0
  public OnmsAccessPointCollection call() throws IOException {
    OnmsAccessPointCollection apsUp = new OnmsAccessPointCollection();
    InetAddress ipaddr = m_iface.getIpAddress();

    // Retrieve this interface's SNMP peer object
    SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(ipaddr);
    if (agentConfig == null) {
      throw new IllegalStateException(
          "SnmpAgentConfig object not available for interface " + ipaddr);
    }
    final String hostAddress = InetAddressUtils.str(ipaddr);
    log().debug("poll: setting SNMP peer attribute for interface " + hostAddress);

    // Get configuration parameters
    String oid = ParameterMap.getKeyedString(m_parameters, "oid", null);
    if (oid == null) {
      throw new IllegalStateException("oid parameter is not set.");
    }

    agentConfig.hashCode();

    // Set timeout and retries on SNMP peer object
    agentConfig.setTimeout(
        ParameterMap.getKeyedInteger(m_parameters, "timeout", agentConfig.getTimeout()));
    agentConfig.setRetries(
        ParameterMap.getKeyedInteger(
            m_parameters,
            "retry",
            ParameterMap.getKeyedInteger(m_parameters, "retries", agentConfig.getRetries())));
    agentConfig.setPort(ParameterMap.getKeyedInteger(m_parameters, "port", agentConfig.getPort()));

    if (log().isDebugEnabled()) {
      log().debug("TableStrategy.poll: SnmpAgentConfig address= " + agentConfig);
    }

    // Establish SNMP session with interface
    try {
      SnmpObjId snmpObjectId = SnmpObjId.get(oid);

      Map<SnmpInstId, SnmpValue> map =
          SnmpUtils.getOidValues(agentConfig, "AccessPointMonitor::TableStrategy", snmpObjectId);

      if (map.size() <= 0) {
        throw new IOException("No entries found in table (possible timeout).");
      }

      for (Map.Entry<SnmpInstId, SnmpValue> entry : map.entrySet()) {
        SnmpValue value = entry.getValue();

        String physAddr = getPhysAddrFromValue(value);

        log()
            .debug(
                "AP at value '"
                    + value.toHexString()
                    + "' with MAC '"
                    + physAddr
                    + "' is considered to be ONLINE on controller '"
                    + m_iface.getIpAddress()
                    + "'");
        OnmsAccessPoint ap = m_accessPointDao.findByPhysAddr(physAddr);
        if (ap != null) {
          if (ap.getPollingPackage().compareToIgnoreCase(getPackage().getName()) == 0) {
            // Save the controller's IP address
            ap.setControllerIpAddress(ipaddr);
            apsUp.add(ap);
          } else {
            log().info("AP with MAC '" + physAddr + "' is in a different package.");
          }
        } else {
          log().info("No matching AP in database for value '" + value.toHexString() + "'.");
        }
      }
    } catch (InterruptedException e) {
      log().error("Interrupted while polling " + hostAddress, e);
    }

    return apsUp;
  }