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();
    }
  }
  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"));
  }
  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();
    }
  }
  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"));
  }
  public CReturnValue execute(CCommandLine cl) {
    if (cl.hasOption("FILE")) {
      File f = new File(cl.getOptionValue("FILE"));
      if (f.exists())
        return new CReturnValue(
            IJNRPEConstants.STATE_CRITICAL, "File '" + f.getName() + "' exists");
      else return new CReturnValue(IJNRPEConstants.STATE_OK, "File '" + f.getName() + "' is OK");
    }

    // CReturnValue res = new CReturnValue(IJNRPEConstants.STATE_OK, "CHECK_FILE: OK");
    CReturnValue res = null;

    File f = null;

    if (cl.hasOption("file")) f = new File(cl.getOptionValue("file"));
    else
      return new CReturnValue(
          IJNRPEConstants.STATE_UNKNOWN, "Either param -f or -F must be specified");

    //        if (!f.exists())
    //            return new CReturnValue(IJNRPEConstants.STATE_CRITICAL, "File '" + f.getName() +
    // "' not found");

    // Verifico che il file esista
    if (res == null || res.getReturnCode() != IJNRPEConstants.STATE_CRITICAL)
      res = checkFileExists(f, res);

    if (res == null || res.getReturnCode() != IJNRPEConstants.STATE_CRITICAL)
      res = checkAge(cl, f, res);
    if (res == null || res.getReturnCode() != IJNRPEConstants.STATE_CRITICAL)
      res = checkSize(cl, f, res);
    if (res == null || res.getReturnCode() != IJNRPEConstants.STATE_CRITICAL)
      res = checkContains(cl, f, res);
    if (res == null || res.getReturnCode() != IJNRPEConstants.STATE_CRITICAL)
      res = checkNotContains(cl, f, res);

    return res;
  }