Esempio n. 1
0
 @Override
 public boolean exist(String hostname, HttpServletRequest request) {
   try {
     hosttarget = makeSnmpTarget(request);
     active = new LocalSnmpConnection();
     active.target = hosttarget;
     active.doStart();
     if (SnmpRequester.RAW.doSnmpGet(active, Collections.singleton(sysObjectID)).size() < 0) {
       log(Level.INFO, "SNMP not active on host %s", hostname);
       return false;
     }
     return true;
   } catch (UnknownHostException e) {
     log(Level.INFO, "Host name %s unknown", hostname);
     return false;
   } catch (IOException e1) {
     log(Level.INFO, "SNMP not active on host %s", hostname);
     return false;
   }
 }
Esempio n. 2
0
  @Override
  public void discoverPost(
      String hostname,
      JrdsElement hostEleme,
      Map<String, JrdsDocument> probdescs,
      HttpServletRequest request) {

    boolean withOid = false;
    String withOidStr = request.getParameter("discoverWithOid");
    if (withOidStr != null && "true".equals(withOidStr.toLowerCase())) withOid = true;

    Set<String> done = new HashSet<String>();

    log(Level.DEBUG, "Will search for probes %s", sortedProbeName);
    for (String name : sortedProbeName) {
      ProbeDescSummary summary = summaries.get(name);
      if (summary == null) {
        log(Level.ERROR, "ProbeDesc not valid for %s, skip it", name);
        done.add(name);
        continue;
      }
      if (done.contains(name)) {
        log(Level.TRACE, "ProbeDesc %s already done, it must be hidden", name);
        continue;
      }
      log(Level.TRACE, "Trying to discover probe %s", name);

      try {
        boolean found = false;
        if (summary.isIndexed) {
          found = (enumerateIndexed(hostEleme, summary, withOid) > 0);
        } else {
          found = doesExist(hostEleme, summary);
        }
        if (found) {
          log(Level.DEBUG, "%s found", name);
          done.add(name);
          // Add all the hidden probes desc to the already done one
          String hidesStr = summary.specifics.get("hides");
          if (hidesStr != null && !hidesStr.isEmpty()) {
            for (String hides : hidesStr.split(",")) {
              log(Level.DEBUG, "%s hides %s", name, hides.trim());
              done.add(hides.trim());
            }
          }
        }
      } catch (Exception e1) {
        log(Level.ERROR, e1, "Error detecting %s: %s", name, e1);
      }
    }
    active.doStop();
  }