コード例 #1
0
  private String[] findlatest(String[] onlysecuritym, File dir) {
    Hashtable list = new Hashtable();
    String filename;
    Vector parsed;
    Vector similarlist;
    String Key;
    if (onlysecuritym != null) {
      for (int i = 0; i < onlysecuritym.length; i++) {
        filename = onlysecuritym[i];
        parsed = MonitoringUtils.parseString(filename, '_');
        if (MonitoringUtils.debug > 0) {
          for (int z = 0; z < parsed.size(); z++) {
            System.out.println("parsed data is : " + z + "  ::  " + (String) parsed.elementAt(z));
          }
        }
        if (parsed.size() > 2) {
          Key = (String) parsed.elementAt(1);
          if (list.containsKey(Key)) {
            similarlist = (Vector) list.get(Key);
            similarlist.add(filename);
            list.put(Key, similarlist);
          } else {
            similarlist = new Vector();
            similarlist.add(filename);
            list.put(Key, similarlist);
          }
        } else {
          System.err.println("Error in parsing the log file name::" + filename);
        }
      }
    }
    Enumeration keylist = list.keys();
    String nodename;
    String latestfile = null;
    Date latestdate = null;
    Date tempdate;
    File completepath;
    parsed = new Vector();
    long ldate;
    for (; keylist.hasMoreElements(); ) {
      nodename = (String) keylist.nextElement();
      similarlist = (Vector) list.get(nodename);

      for (int i = 0; i < similarlist.size(); i++) {
        filename = (String) similarlist.elementAt(i);
        if (latestdate == null) {
          completepath = new File(dir, filename);
          ldate = completepath.lastModified();
          latestdate = new Date(ldate);
          latestfile = filename;
        } else {
          completepath = new File(dir, filename);
          ldate = completepath.lastModified();
          tempdate = new Date(ldate);
          if (tempdate.after(latestdate)) {
            latestdate = tempdate;
            latestfile = filename;
          }
          latestfile = filename;
        }
      }
      if (latestfile != null) parsed.add(latestfile);
      else System.err.println("Could not get latest file for ::" + nodename);
      latestdate = null;
      latestfile = null;
    }
    return MonitoringUtils.toStringArray(parsed);
  }
コード例 #2
0
  /**
   * Called inside of an open transaction whenever the plugin was explicitly told to run or when
   * there are changes to any of our subscriptions.
   */
  public void execute() {
    if (MonitoringUtils.debug > 0) {
      System.out.println("In exec of Sensor");
    }
    if (!publishedcapabilities) {
      if (MonitoringUtils.debug > 0) System.out.println("In Sensor Plugin publishing capabilities");
      publishedcapabilities = publishcapabilities();
      File filelist = null;
      if (Services.contains("SecurityException")) {
        String filename = secprop.getProperty(secprop.BOOTSTRAP_LOGFILE);
        if (filename != null) {
          int lastindex = filename.lastIndexOf(File.separator);
          filename = filename.substring(0, lastindex);
          filelist = new File(filename);
        } else {
          if (MonitoringUtils.debug > 0)
            System.out.println(
                "Could not get the log file name for security exception through java property .Probably org.cougaar.core.security.bootstrap.SecurityManagerLogFile is not set ---- using default values");
          String cougaarpath = secprop.getProperty(secprop.COUGAAR_INSTALL_PATH);
          StringBuffer logfilepath = new StringBuffer();
          logfilepath.append(cougaarpath);
          if (MonitoringUtils.debug > 0)
            System.out.println("got cougaar install path" + logfilepath.toString());
          logfilepath.append(File.separatorChar);
          logfilepath.append("log" + File.separatorChar + "bootstrap" + File.separator);
          if (MonitoringUtils.debug > 0)
            System.out.println("IN Sensor Plugin got log  path" + logfilepath.toString());
          filelist = new File(logfilepath.toString());
        }
        String[] filenames = null;
        if (filelist != null) {
          filenames = filelist.list();
          if ((filenames != null) && (filenames.length > 0)) {
            if (MonitoringUtils.debug > 0) {
              for (int i = 0; i < filenames.length; i++) {
                System.out.println("file name at : " + i + "  :: " + filenames[i]);
              }
            }
            String[] uniquelog = findUniquePerNode(filenames, filelist, "SecurityManager");
            if (MonitoringUtils.debug > 0) {
              for (int i = 0; i < uniquelog.length; i++) {
                System.out.println("file name unique at : " + i + "  :: " + uniquelog[i]);
              }
            }
            fi = new FileInputStream[uniquelog.length];
            File tempfile = null;
            for (int i = 0; i < uniquelog.length; i++) {
              tempfile = new File(filelist, uniquelog[i]);
              try {
                fi[i] = new FileInputStream(tempfile);
              } catch (IOException ioexp) {
                System.err.println(
                    "Error while opening file stream for file :::  " + tempfile.toString());
                ioexp.printStackTrace();
              }
            }
            nodename = findNodeName(fi);
            for (int i = 0; i < uniquelog.length; i++) {
              tempfile = new File(filelist, uniquelog[i]);
              try {
                fi[i] = new FileInputStream(tempfile);
              } catch (IOException ioexp) {
                System.err.println(
                    "Error while opening file stream for file :::  " + tempfile.toString());
                ioexp.printStackTrace();
              }
            }
          }
        }
      }
    }

    process_publishCmd(allcmd.getAddedList());
    double slp = Math.random();
    double crit = Math.random();
    while ((crit * 10) > 4 || ((crit * 10) == 0)) {
      crit = Math.random();
      // System.out.println("crit while gen is :"+crit*10);
    }
    slp *= 10 * 0.6;
    sleeptime = ((int) slp) * 100000l;
    if (sleeptime == 0) {
      sleeptime = 1000000l;
    }
    publishdata();
    wakeAfter(sleeptime);
  }