コード例 #1
0
ファイル: SeltaSted.java プロジェクト: rssntn67/SLT
  /** run */
  @Override
  public void run() {
    if (polling()) {
      log().debug("run: polling Selta STED on primary address: " + getIpaddress());

      boolean pollhierarchy = true;
      SnmpValue lastCommit =
          SnmpUtils.get(getAgentConfig(), SnmpObjId.get(SeltaMibCommon.OID_S_lastCommit));
      if (lastCommit != null) {
        String lastCommitString = SeltaUtils.ConvertDateToString(lastCommit.getBytes());
        if (getLastCommit() == null || !getLastCommit().equals(lastCommitString)) {
          log().info("lastCommit changed from " + getLastCommit() + " to " + lastCommitString);
          setLastCommit(lastCommitString);
          storeProperty("nePrimaryIP", getIpaddress().toString());
          createInventory();
          savePropertiesFile("STED properties");
          pollhierarchy = false;
        }
      }

      SnmpValue lastAlarm =
          SnmpUtils.get(getAgentConfig(), SnmpObjId.get(SeltaMibCommon.OID_S_lastAlarm));
      if (lastAlarm != null) {
        String lastAlarmString = SeltaUtils.ConvertDateToString(lastAlarm.getBytes());
        if (getLastAlarm() == null || !getLastAlarm().equals(lastAlarmString)) {
          log().info("lastAlarm changed from " + getLastAlarm() + " to " + lastAlarmString);
          setLastAlarm(lastAlarmString);
          poll(pollhierarchy);
          savePropertiesFile("STED properties");
        }
      }
    } else {
      log().info("not polling: " + getIpaddress());
    }
  }
コード例 #2
0
  /**
   * Verifies that the result of the SNMP query meets the criteria specified by the operator and the
   * operand from the configuration file.
   *
   * @param result a {@link org.opennms.netmgt.snmp.SnmpValue} object.
   * @param operator a {@link java.lang.String} object.
   * @param operand a {@link java.lang.String} object.
   * @return a boolean.
   */
  protected boolean meetsCriteria(SnmpValue result, String operator, String operand) {

    Boolean retVal = null;

    retVal = isCriteriaNull(result, operator, operand);

    if (retVal == null) {
      String value = result.toString();
      retVal = checkStringCriteria(operator, operand, value);

      if (retVal == null) {
        BigInteger val = BigInteger.valueOf(result.toLong());

        BigInteger intOperand = new BigInteger(operand);
        if (LESS_THAN.equals(operator)) {
          return val.compareTo(intOperand) < 0;
        } else if (LESS_THAN_EQUALS.equals(operator)) {
          return val.compareTo(intOperand) <= 0;
        } else if (GREATER_THAN.equals(operator)) {
          return val.compareTo(intOperand) > 0;
        } else if (GREATER_THAN_EQUALS.equals(operator)) {
          return val.compareTo(intOperand) >= 0;
        } else {
          throw new IllegalArgumentException("operator " + operator + " is unknown");
        }
      }
    } else if (retVal.booleanValue()) {
      return true;
    }

    return retVal.booleanValue();
  }
コード例 #3
0
 @Test
 @JUnitSnmpAgent(host = "192.168.255.10", resource = "classpath:/airPairR3_walk.properties")
 public void dwoTestEndPointImplGetOid() throws UnknownHostException {
   EndPointImpl endPoint = getEndPoint(null, "192.168.255.10");
   SnmpValue snmpVal = endPoint.get(AIR_PAIR_MODEM_LOSS_OF_SIGNAL);
   assertNotNull(snmpVal);
   assertEquals("1", snmpVal.toString());
 }
コード例 #4
0
ファイル: SnmpDetector.java プロジェクト: aashrestha/opennms
 /**
  * getValue
  *
  * @param agentConfig a {@link org.opennms.netmgt.snmp.SnmpAgentConfig} object.
  * @param oid a {@link java.lang.String} object.
  * @return a {@link java.lang.String} object.
  */
 protected String getValue(SnmpAgentConfig agentConfig, String oid) {
   SnmpValue val = SnmpUtils.get(agentConfig, SnmpObjId.get(oid));
   if (val == null || val.isNull() || val.isEndOfMib() || val.isError()) {
     return null;
   } else {
     return val.toString();
   }
 }
コード例 #5
0
 public Integer getIfIndex() {
   final SnmpValue value = getValue(IF_INDEX);
   if (value != null) {
     return value.toInt();
   } else {
     // ifIndex is the instance id as well
     final SnmpInstId inst = getInstance();
     if (inst != null && inst.length() == 1) {
       return inst.toInt();
     }
   }
   return null;
 }
コード例 #6
0
 private String getPhysAddr() {
   final SnmpValue value = getValue(IF_PHYS_ADDR);
   String hexString = value == null ? null : value.toHexString();
   String displayString = value == null ? null : value.toDisplayString();
   // See ifTableEntry: NMS-4902 (revision cee964fe979e6465aeb4e2efd4772e50ebc54831)
   try {
     if (hexString != null && hexString.length() == 12) {
       // If the hex string is 12 characters long, than the agent is kinda weird and
       // is returning the value as a raw binary value that is 6 bytes in length.
       // But that's OK, as long as we can convert it into a string, that's fine.
       return hexString;
     } else {
       // This is the normal case that most agents conform to: the value is an ASCII
       // string representing the colon-separated MAC address. We just need to reformat
       // it to remove the colons and convert it into a 12-character string.
       return displayString == null || displayString.trim().isEmpty()
           ? null
           : InetAddressUtils.normalizeMacAddress(displayString);
     }
   } catch (IllegalArgumentException e) {
     LOG.warn(e.getMessage(), e);
     return displayString;
   }
 }
コード例 #7
0
ファイル: TableStrategy.java プロジェクト: garylai578/opennms
  public static String getPhysAddrFromValue(SnmpValue value) {
    String hexString = value.toHexString();
    if (hexString.length() != 12) {
      return null;
    }

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < 12; i += 2) {
      sb.append(hexString.substring(i, i + 2));
      if (i < 10) {
        sb.append(':');
      }
    }

    return sb.toString().toUpperCase();
  }
コード例 #8
0
 private Integer getIfAdminStatus() {
   final SnmpValue value = getValue(IF_ADMIN_STATUS);
   return value == null ? null : value.toInt();
 }
コード例 #9
0
 private String getIfAlias() {
   final SnmpValue value = getValue(IF_ALIAS);
   return value == null ? null : value.toDisplayString();
 }
コード例 #10
0
 private String getIfDescr() {
   final SnmpValue value = getValue(IF_DESCR);
   return value == null ? null : value.toDisplayString();
 }
コード例 #11
0
 private String getIfName() {
   final SnmpValue value = getValue(IF_NAME);
   return value == null ? null : value.toDisplayString();
 }
コード例 #12
0
 private Integer getIfOperStatus() {
   final SnmpValue value = getValue(IF_OPER_STATUS);
   return value == null ? null : value.toInt();
 }
コード例 #13
0
 private Integer getIfType() {
   final SnmpValue value = getValue(IF_TYPE);
   return value == null ? null : value.toInt();
 }
コード例 #14
0
 private String getPhysAddr() {
   final SnmpValue value = getValue(IF_PHYS_ADDR);
   return value == null ? null : value.toHexString();
 }
コード例 #15
0
ファイル: TableStrategy.java プロジェクト: garylai578/opennms
  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;
  }
コード例 #16
0
 @Test
 public void testAgent() throws Exception {
   SnmpValue snmpValue = SnmpUtils.get(snmpAgentConfig, SnmpObjId.get(".1.3.6.1.2.1.1.1.0"));
   Assert.assertEquals("Mock Juniper TCA Device", snmpValue.toDisplayString());
 }
コード例 #17
0
 private Long getIfHighSpeed() {
   final SnmpValue value = getValue(IF_HIGH_SPEED);
   return value == null ? null : value.toLong();
 }
コード例 #18
0
 /**
  * getStorableValue
  *
  * @param snmpVal a {@link org.opennms.netmgt.snmp.SnmpValue} object.
  * @return a {@link java.lang.String} object.
  */
 public String getStorableValue(SnmpValue snmpVal) {
   return (snmpVal == null ? null : Long.toString(snmpVal.toLong()));
 }