fix(ulimit check): try except when checking ulimit (#2096)

Co-authored-by: Sergio Garcia <38561120+sergargar@users.noreply.github.com>
This commit is contained in:
Nacho Rivera
2023-03-16 17:39:46 +01:00
committed by GitHub
parent cc58e06b5e
commit 0edcb7c0d9

View File

@@ -356,14 +356,20 @@ def execute_checks(
audit_progress=0, audit_progress=0,
) )
if not sys.platform.startswith("win32") or not sys.platform.startswith("cygwin"): if os.name != "nt":
from resource import RLIMIT_NOFILE, getrlimit try:
from resource import RLIMIT_NOFILE, getrlimit
# Check ulimit for the maximum system open files # Check ulimit for the maximum system open files
soft, _ = getrlimit(RLIMIT_NOFILE) soft, _ = getrlimit(RLIMIT_NOFILE)
if soft < 4096: if soft < 4096:
logger.warning( logger.warning(
f"Your session file descriptors limit ({soft} open files) is below 4096. We recommend to increase it to avoid errors. Solve it running this command `ulimit -n 4096`. For more info visit https://docs.prowler.cloud/en/latest/troubleshooting/" f"Your session file descriptors limit ({soft} open files) is below 4096. We recommend to increase it to avoid errors. Solve it running this command `ulimit -n 4096`. For more info visit https://docs.prowler.cloud/en/latest/troubleshooting/"
)
except Exception as error:
logger.error("Unable to retrieve ulimit default settings")
logger.error(
f"{error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"
) )
# Execution with the --only-logs flag # Execution with the --only-logs flag