private CReturnValue updateRes(CReturnValue res, CReturnValue newVal) { if (res == null) return newVal; switch (res.getReturnCode()) { case IJNRPEConstants.STATE_CRITICAL: return res; case IJNRPEConstants.STATE_WARNING: if (newVal.getReturnCode() != IJNRPEConstants.STATE_CRITICAL) return res; return newVal; case IJNRPEConstants.STATE_OK: if (newVal.getReturnCode() == IJNRPEConstants.STATE_OK) return res; return newVal; default: return res; } }
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; }