Esempio n. 1
0
  private CReturnValue checkNotContains(CCommandLine cl, File f, CReturnValue res) {
    if (!cl.hasOption("notcontains"))
      return updateRes(res, new CReturnValue(IJNRPEConstants.STATE_OK, "FILE OK"));

    CStreamManager sm = new CStreamManager();

    try {
      BufferedReader r = new BufferedReader(new InputStreamReader(sm.getInputStream(f)));
      String sLine = null;

      String[] vsPatterns = cl.getOptionValue("notcontains").split(",");

      while ((sLine = r.readLine()) != null) {
        for (int i = 0; i < vsPatterns.length; i++)
          if (sLine.indexOf(vsPatterns[i]) != -1)
            return updateRes(
                res,
                new CReturnValue(
                    IJNRPEConstants.STATE_CRITICAL,
                    "FILE CRITICAL - String '" + cl.getOptionValue("notcontains") + "' found"));
      }
      return updateRes(
          res,
          new CReturnValue(
              IJNRPEConstants.STATE_OK,
              "FILE OK: String '" + cl.getOptionValue("notcontains") + "' not found"));
    } catch (Exception e) {
      return updateRes(
          res, new CReturnValue(IJNRPEConstants.STATE_UNKNOWN, "FILE UNKNOWN - " + e.getMessage()));
    } finally {
      sm.closeAll();
    }
  }
Esempio n. 2
0
  private CReturnValue checkContains(CCommandLine cl, File f, CReturnValue res) {
    if (!cl.hasOption("contains"))
      return updateRes(res, new CReturnValue(IJNRPEConstants.STATE_OK, "FILE OK"));

    CStreamManager sm = new CStreamManager();

    try {
      BufferedReader r = new BufferedReader(new InputStreamReader(sm.getInputStream(f)));
      String sLine = null;

      String sWarningThreshold = ":0";
      String sCriticalThreshold = ":0";

      String sPattern = cl.getOptionValue("contains");
      if (sPattern.indexOf(',') != -1) {
        String[] vsParts = sPattern.split(",");
        sWarningThreshold = vsParts[1];
        if (vsParts.length > 1) sCriticalThreshold = vsParts[2];
        sPattern = vsParts[0];
      }

      int iCount = 0;

      while ((sLine = r.readLine()) != null) {
        if (sLine.indexOf(sPattern) != -1) iCount++;
        // return updateRes(res, new CReturnValue(IJNRPEConstants.STATE_OK, "FILE OK"));
      }

      if (ThresholdUtil.isValueInRange(sCriticalThreshold, iCount))
        return updateRes(
            res,
            new CReturnValue(
                IJNRPEConstants.STATE_CRITICAL,
                "FILE CRITICAL - String '" + sPattern + "' found " + iCount + " times"));
      if (ThresholdUtil.isValueInRange(sWarningThreshold, iCount))
        return updateRes(
            res,
            new CReturnValue(
                IJNRPEConstants.STATE_WARNING,
                "FILE WARNING - String '" + sPattern + "' found " + iCount + " times"));

      return updateRes(
          res,
          new CReturnValue(
              IJNRPEConstants.STATE_OK,
              "FILE OK - String '" + sPattern + "' found " + iCount + " times"));
    } catch (Exception e) {
      return updateRes(
          res, new CReturnValue(IJNRPEConstants.STATE_UNKNOWN, "FILE UNKNOWN - " + e.getMessage()));
    } finally {
      sm.closeAll();
    }
  }