Skip to content

Commit 16eec9f

Browse files
committed
fix(file-age): handle FileNotFoundError race condition when files disappear on busy file systems
1 parent 3e56ed1 commit 16eec9f

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Monitoring Plugins:
3939
* about-me: error in perfdata if using `--dmidecode` and there is no HW information
4040
* about-me: fix various errors with `sys_dimensions` on some machines
4141
* by-ssh: add missing `--verbose` parameter
42+
* file-age: handle `FileNotFoundError` race condition when files disappear on busy file systems
4243
* fs-ro: ignore `/run/credentials` (https://systemd.io/CREDENTIALS/)
4344
* keycloak-stats: fix incorrect symlink for lib
4445
* ntp-\*: prevent `TypeError: ''=' not supported between instances of 'int' and 'str'`

check-plugins/file-age/file-age

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,17 @@ def main():
215215
if args.FILENAME:
216216
path = Path(args.FILENAME)
217217
for item in sorted(Path(path.anchor).glob(str(path.relative_to(path.anchor)))):
218-
if item.is_file() and args.ONLY_DIRS:
219-
continue
220-
if item.is_dir() and args.ONLY_FILES:
221-
continue
218+
try:
219+
if item.is_file() and args.ONLY_DIRS:
220+
continue
221+
if item.is_dir() and args.ONLY_FILES:
222+
continue
222223

223-
# brandnew files might get negative values
224-
age = abs(lib.time.now() - item.stat().st_mtime)
224+
# brandnew files might get negative values
225+
age = abs(lib.time.now() - item.stat().st_mtime)
226+
except FileNotFoundError:
227+
# it is normal that files disappear while reading
228+
continue
225229
ages.append(age)
226230
item_state = STATE_OK
227231
# not using elif, as the item could contribute to both the warn_count and crit_count

0 commit comments

Comments
 (0)