Exemplo n.º 1
0
 private int exec(String s, ArrayList array) {
   int i = -1;
   BufferedReader bufferedreader = null;
   Process process = null;
   try {
     process = CommandLine.execSync(s);
     bufferedreader = FileUtils.MakeInputReader(process.getInputStream());
     do {
       String s1 = bufferedreader.readLine();
       if (s1 == null) {
         i = process.exitValue();
         break;
       }
       if (s1.startsWith(VALID_RES_END_INDICATOR)) {
         i = Integer.parseInt(s1.substring(VALID_RES_END_INDICATOR.length()));
         break;
       }
       array.add(s1);
     } while (true);
   } catch (Exception exception) {
     LogManager.log("error", exception.getMessage());
     i = -1;
     array.clear();
   }
   if (bufferedreader != null) {
     try {
       bufferedreader.close();
     } catch (IOException ioexception) {
       LogManager.log("error", ioexception.getMessage());
     }
   }
   if (process != null) {
     process.destroy();
   }
   return i;
 }
  protected boolean update() {
    if (Platform.isWindows()) {
      for (int i = 0; i < getStateValues().length; i++) {
        unsetProperty(getStateValues()[i]);
      }

      if ((getMediaTrace() & 4) != 0) {
        mediaDebug("MediaPlayerMonitorBase(): Entered");
      }
      Array array = new Array();
      String s = getMediaCommand();
      if ((getMediaTrace() & 4) != 0) {
        mediaDebug("getMediaCommand(): " + s);
      }
      CommandLine commandline = new CommandLine();
      array = commandline.exec(s);
      int j = commandline.getExitValue();
      if ((getMediaTrace() & 4) != 0) {
        mediaDebug("mediaCommand: " + s + ",getExitValue(): " + j);
      }
      for (Enumeration enumeration = array.elements();
          enumeration.hasMoreElements();
          mediaDebug("Results: " + enumeration.nextElement())) {}
      boolean flag = false;
      if (j == 0) {
        try {
          BufferedReader bufferedreader = new BufferedReader(new FileReader(mediaLog));
          do {
            String s1;
            if ((s1 = bufferedreader.readLine()) == null) {
              break;
            }
            if (parseRecord(s1)) {
              flag = true;
            }
          } while (true);
          if (flag) {
            String s3 = "URL: " + getProperty(getPMediaURL());
            Array array1 = getCounters();
            for (int l = 0; l < array1.size(); l++) {
              if (l == 0) {
                s3 = s3 + "&nbsp";
              }
              String s4 = prepLabel((String) array1.at(l));
              s3 = s3 + s4 + "&nbsp;" + getProperty(getStateValues()[l]);
              if (l < array1.size() - 1) {
                s3 = s3 + ", ";
              }
            }

            setProperty(pStateString, s3);
            setProperty(getPStatus(), "ok");
          }
        } catch (FileNotFoundException filenotfoundexception) {
          LogManager.log("Error", "Error Opening: " + mediaLog + " " + filenotfoundexception);
          setProperty(pStateString, "Error opening media log file: " + mediaLog);
          setProperty(getPStatus(), "Error");
        } catch (IOException ioexception) {
          LogManager.log("Error", "Error reading: " + mediaLog + " " + ioexception);
          setProperty(pStateString, "Error reading media log file: " + mediaLog);
          setProperty(getPStatus(), "Error");
        }
      }
      if (!flag) {
        String s2 = "";
        StringBuffer stringbuffer = new StringBuffer();
        String s5 = "";
        System.out.println("Error in monitor !");
        try {
          BufferedReader bufferedreader1 = new BufferedReader(new FileReader(mediaLog + "_"));
          do {
            String s6;
            if ((s6 = bufferedreader1.readLine()) == null) {
              break;
            }
            stringbuffer.append(s6);
            int k = s6.indexOf("Error:");
            if (k >= 0) {
              if (s2.length() > 0) {
                s2 = s2 + "<br>";
              }
              s2 = s2 + s6.substring(k + 6).trim();
            }
          } while (true);
        } catch (FileNotFoundException filenotfoundexception1) {
          s2 = "File Not Found Exception occurrred while reading error log file.";
        } catch (IOException ioexception1) {
          s2 = "I/O Exception occurred while reading error log file.";
        }
        if (s2.length() > 0) {
          setError(handleUpdateError(s2));
        } else {
          setError(stringbuffer.toString());
        }
      }
      File file = new File(mediaLog);
      if (file != null) {
        if ((getMediaTrace() & 2) != 0) {
          mediaDebug("Delete Temp File: " + mediaLog);
        }
        try {
          file.delete();
        } catch (SecurityException securityexception) {
          LogManager.log(
              "Error",
              "MediaPlayerMonitorBase Security Exception caught deleting temp file: " + mediaLog);
        }
      } else {
        LogManager.log("Error", "MediaPlayerMonitorBase Error deleting temp file: " + mediaLog);
      }
      file = new File(mediaLog + "_");
      if (file != null) {
        if ((getMediaTrace() & 2) != 0) {
          mediaDebug("Delete Temp File: " + mediaLog + "_");
        }
        try {
          file.delete();
        } catch (SecurityException securityexception1) {
          LogManager.log(
              "Error",
              "MediaPlayerMonitorBase Security Exception caught deleting temp file: " + mediaLog);
        }
      } else {
        LogManager.log(
            "Error", "MediaPlayerMonitorBase Error deleting temp file: " + mediaLog + "_");
      }
      if ((getMediaTrace() & 4) != 0) {
        mediaDebug("MediaPlayerMonitorBase(): Exited");
      }
      return true;
    } else {
      return false;
    }
  }
Exemplo n.º 3
0
  /** CAUTION: Decompiled by hand. */
  protected boolean update() {
    long l = Platform.timeMillis();
    int i = -1;
    String[] as = (new String[] {""});
    String s = getProperty(pExpression);
    long l1 = getPropertyAsLong(pMaxMeasurement);
    int j = getPropertyAsInteger(pCacheLife);
    boolean flag = j > 0;
    ArrayList array = new ArrayList();
    String s1 = "";

    try {
      String s2 = I18N.toDefaultEncoding(getProperty(pScript));
      String s3 = I18N.toDefaultEncoding(getProperty(pRemoteScript));
      String s4 = null;
      String s7 = I18N.toDefaultEncoding(getProperty(pLocalScriptLocation));
      if (s7.length() == 0) {
        s7 = "scripts";
      } else if (s7.indexOf("../") >= 0 || s7.indexOf("..\\") >= 0) {
        failMonitorRun(i, "Illegal Script Location contains ../ construct");
        return true;
      }

      s1 = getProperty(pMachineName);
      if (Machine.isNTSSH(s1) && s2.equals("USE COMMAND")) {
        failMonitorRun(i, "Can't use this option with remote NT ssh connection");
        return true;
      }

      if (Platform.isRemote(s1) && Machine.getMachine(s1) == null) {
        failMonitorRun(i, "Remote host unreachable");
        return true;
      }

      if (Platform.isNTRemote(s1) && !Machine.isNTSSH(s1)) {
        failMonitorRun(i, "NT host must be configured as NT ssh remote ");
        return true;
      }

      if (s3.equals("none") && s2.equals("USE COMMAND")) {
        failMonitorRun(i, "Need to specify a script");
        return true;
      }

      if (s3.length() != 0 && !s3.equals("none")) {
        try {
          s4 = getCommandFromLocalFile(s3);
          s4 = TextUtils.replaceParameters(s4, getParameters(), getReplacementChars());
        } catch (IOException ioexception) {
          LogManager.log("Error", " File load error " + ioexception.toString());
          setProperty(pNoData, "n/a");
        }
      } else {
        if (!Platform.isRemote(s1)) {
          String s8 = Platform.getRoot() + "/" + s7 + "/" + s2;
          File file = new File(s8);
          s4 = file.getAbsolutePath();
        } else {
          String s9 = "scripts" + Machine.getMachinePathSeparator(s1) + s2;
          OSAdapter osadapter = Machine.getAdapter(s1);
          if (osadapter != null) {
            CommandLine commandline = new CommandLine();
            String s11 = osadapter.getCommandSetting("fileExists", "changeDirectory");
            if (s11.length() > 0) {
              s4 = s11;
            } else {
              s4 = "/usr/bin/cd";
            }
            commandline.exec(s4, s1, Platform.getLock(s1));
          }
          RemoteFile remotefile = new RemoteFile(s1, s9);
          s4 = remotefile.getFullPath();
        }
        s4 = s4 + " " + getParameters();
        System.out.println("Script: " + s4);
      }
      LogManager.log("RunMonitor", "Script monitor command: " + s4 + ", machine: " + s1);
      String s10 = s1;
      if (s10.startsWith("\\\\")) {
        s10 = s10.substring(2);
      }
      Machine machine = Machine.getNTMachine(s10);
      int j1 = getPropertyAsInteger(pTimeout) * 1000;
      if (j1 < 0) {
        j1 = getSettingAsLong("_scriptMonitorTimeout", -1) * 1000;
      }
      String s12 = getScriptServerName(s1);
      String s14 =
          getProperty(pScript).equals("USE COMMAND")
              ? getProperty(pRemoteScript)
              : getProperty(pScript);
      ScriptMonitorCache scriptmonitorcache =
          new ScriptMonitorCache(s12, s14, getPropertyAsInteger(pCacheLife));
      if (!flag && alertDebug) {
        System.out.println("Caching is disabled.");
      }
      boolean flag1 = scriptmonitorcache.isFresh();
      if (flag && flag1 && scriptmonitorcache.getExitValue() == 0) {
        if (alertDebug) {
          System.out.println(
              "Caching is enabled, the cache life time is set to: "
                  + getPropertyAsInteger(pCacheLife));
        }
        if (alertDebug) {
          System.out.println(
              "The cache is still good, not exec'ing script, cache last modified on: "
                  + scriptmonitorcache.getLastModDate());
        }
        array = scriptmonitorcache.getOutput();
        i = scriptmonitorcache.getExitValue();
      } else if (machine != null && Machine.isNTSSH(s10)) {
        if (s4.indexOf("\\\\" + s10) > 0) {
          s4 = TextUtils.replaceString(s4, "\\\\" + s10, "");
        }
        s4 = "scripts\\" + s4.substring(s4.indexOf(s2));
        if (j1 > 0) {
          s4 = CommandLine.getExecSyncCmd(s10, s4, j1, true);
        }
        SSHCommandLine sshcommandline = new SSHCommandLine();
        array = sshcommandline.exec(s4, machine, false);
        i = sshcommandline.exitValue;
      } else {
        CommandLine commandline1 = new CommandLine();
        array = commandline1.exec(s4, s1, Platform.monitorLock, j1);
        i = commandline1.getExitValue();
      }
      if (flag && !flag1) {
        if (alertDebug) {
          System.out.println("Exec'd script and updating cache.");
        }
        scriptmonitorcache.update(i, array);
      }
      if (i < 0) {
        String s16 = "Failed to run script";
        if (i == Monitor.kURLTimeoutError) {
          s16 = "Script timed out";
        }
        failMonitorRun(i, s16);
        return true;
      }

      StringBuffer stringbuffer1 = new StringBuffer();
      String s17;
      Enumeration enumeration = (Enumeration) array.iterator();
      while (enumeration.hasMoreElements()) {
        s17 = (String) enumeration.nextElement();
        LogManager.log("RunMonitor", "Script monitor machine " + s1 + " output: " + s17);
        if (s17.startsWith(CommandLine.PERFEX_EXECSYNC_TIMEOUT)) {
          failMonitorRun(-1, "Error: Timeout");
          return true;
        }
        if (s17.indexOf("not found") > 0
            || s17.indexOf("Not Found") > 0
            || s17.indexOf("denied") > 0
            || s17.indexOf("Denied") > 0
            || s17.indexOf("cannot execute") > 0
            || s17.indexOf("such file or directory") > 0) {
          failMonitorRun(-1, s17);
          return true;
        }

        stringbuffer1.append(s17);
        stringbuffer1.append("\n");
        if (s.length() > 0 && !TextUtils.isRegularExpression(s) && s17.indexOf(s) != -1) {
          long l4 = TextUtils.findLong(s17, "", "");
          if (l4 != -1L) {
            as[0] = String.valueOf(l4);
          }
        }
      }

      if (TextUtils.isSubstituteExpression(s)) {
        s = TextUtils.substitute(s, this);
      }
      if (s.length() > 0 && TextUtils.isRegularExpression(s)) {
        String s18 = stringbuffer1.toString();
        Perl5Util perl5util = new Perl5Util();
        if (perl5util.match(s, s18)) {
          int i2 = perl5util.groups();
          if (i2 > 0) {
            if (i2 == 1) {
              as = new String[i2];
              as[0] = perl5util.group(0);
            } else {
              if (--i2 > maxNumberOfMatches) {
                i2 = maxNumberOfMatches;
              }
              as = new String[i2];
              for (int j2 = 0; j2 < as.length && j2 < maxNumberOfMatches; j2++) {
                as[j2] = perl5util.group(j2 + 1);
              }
            }
          }
        } else {
          failMonitorRun(-1, "Content Match Error");
          return true;
        }
      }
    } catch (Exception exception) {
      LogManager.log("RunMonitor", "Script monitor error: " + exception + " machine: " + s1);
      setProperty(pNoData, "n/a");
    }

    LogManager.log("RunMonitor", "Script monitor exit: " + i + " machine: " + s1);
    setProperty(pScriptOutput, "");
    if (as[0].trim().length() == 0) {
      as[0] = "n/a";
      long l2 = getSettingAsLong("_scriptMonitorLinesToSave", 25);
      String s5 = "";
      for (int k = 0; k < array.size() && (long) k < l2; k++) {
        s5 = s5 + array.get(k);
        s5 = s5 + "^";
      }

      s5 = s5.replace('\r', ' ');
      s5 = s5.replace('\n', '^');
      setProperty(pScriptOutput, s5);
    }
    long l3 = Platform.timeMillis() - l;
    String s6 = TextUtils.floatToString((float) l3 / 1000F, 2) + " sec";
    if (stillActive()) {
      synchronized (this) {
        for (int i1 = 0; i1 < as.length; i1++) {
          setProperty(pMatchValue[i1], as[i1]);
        }

        setProperty(pStatus, i);
        if (i != 0) {
          setProperty(pNoData, "n/a");
        }
        setProperty(pRoundTripTime, l3);
        setProperty(pMeasurement, getMeasurement(pRoundTripTime, l1));
        if (s.length() > 0) {
          HashMap hashmap = getLabels();
          StringBuffer stringbuffer = new StringBuffer();
          for (int k1 = 0; k1 < as.length; k1++) {
            String s13 = getNameFromIndex(k1);
            String s15 = (String) hashmap.get(s13);
            if (s15 == null) {
              s15 = s13;
            }
            stringbuffer.append(s15 + "=" + as[k1] + (k1 >= as.length - 1 ? "" : ","));
          }

          setProperty(pStateString, stringbuffer);
        } else {
          setProperty(pStateString, "exit: " + i + ", " + s6);
        }
      }
    }
    return true;
  }