Пример #1
0
  private CReturnValue checkSize(CCommandLine cl, File f, CReturnValue res) {
    if (cl.hasOption("sizecritical")) {
      String sCriticalThreshold = cl.getOptionValue("sizecritical");
      BigDecimal bdSize = new BigDecimal("" + f.length());

      if (ThresholdUtil.isValueInRange(sCriticalThreshold, bdSize))
        return updateRes(
            res,
            new CReturnValue(
                IJNRPEConstants.STATE_CRITICAL,
                "FILE CRITICAL - '"
                    + f.getName()
                    + "' is shorter than "
                    + sCriticalThreshold
                    + " bytes"));
    }

    if (cl.hasOption("sizewarning")) {
      String sWarningThreshold = cl.getOptionValue("sizewarning");
      BigDecimal bdSize = new BigDecimal("" + f.length());

      if (ThresholdUtil.isValueInRange(sWarningThreshold, bdSize))
        return updateRes(
            res,
            new CReturnValue(
                IJNRPEConstants.STATE_WARNING,
                "FILE WARNING - '"
                    + f.getName()
                    + "' is shorter than "
                    + sWarningThreshold
                    + " bytes"));
    }

    return updateRes(res, new CReturnValue(IJNRPEConstants.STATE_OK, "FILE OK"));
  }
Пример #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();
    }
  }
Пример #3
0
  private CReturnValue checkAge(CCommandLine cl, File f, CReturnValue res) {
    if (cl.hasOption("critical")) {
      long lLastAccess = f.lastModified();
      long lNow = System.currentTimeMillis();
      BigDecimal lAge = new BigDecimal("" + ((lNow - lLastAccess) / 1000));
      String sCriticalThreshold = cl.getOptionValue("critical");

      if (ThresholdUtil.isValueInRange(sCriticalThreshold, lAge))
        return updateRes(
            res,
            new CReturnValue(
                IJNRPEConstants.STATE_CRITICAL,
                "FILE CRITICAL - File '"
                    + f.getName()
                    + "' is older than "
                    + sCriticalThreshold
                    + " seconds"));
    }

    if (cl.hasOption("warning")) {
      long lLastAccess = f.lastModified();
      long lNow = System.currentTimeMillis();
      BigDecimal lAge = new BigDecimal("" + ((lNow - lLastAccess) / 1000));
      String sWarningThreshold = cl.getOptionValue("warning");

      if (ThresholdUtil.isValueInRange(sWarningThreshold, lAge))
        return updateRes(
            res,
            new CReturnValue(
                IJNRPEConstants.STATE_WARNING,
                "FILE WARNING - '"
                    + f.getName()
                    + "' is older than "
                    + sWarningThreshold
                    + " seconds"));
    }

    return updateRes(res, new CReturnValue(IJNRPEConstants.STATE_OK, "FILE OK"));
  }