Checking the age of multiple files

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
IkaIka
Posts: 34
Joined: Fri Dec 21, 2018 4:37 am

Checking the age of multiple files

Post by IkaIka »

Hello, I'm having an issue with the check_file_age plugin. While it seems to be working when pointed to a specific file or directory, I've been asked to set up a check for all files within a specific directory. I tried fiddling with the command syntax with varying degrees of success. The goal here is to have Nagios check every single file within the target directory and fire a warning/critical event if either of the files exceeds the threshold.

Code: Select all

command[check_file_age]=/usr/lib/nagios/plugins/check_file_age -w 14400 -c 345600 -f /path/to/target/directory/*
This line seems to work fine at first glance, however it only checks a single file (first in alphabetical order), ignoring other ones.

Code: Select all

command[check_file_age]=/usr/lib/nagios/plugins/check_file_age -w 14400 -c 345600 -D /path/to/target/directory -f *
The --help output had me believe the -D flag sets the target directory, making the file path set by the -F flag relative to it. This doesn't seem to be the case. Using the -D flag alone makes the plugin check only the modification date of the target directory itself, when used with -f or -F it gets completely ignored and in this case, the plugin checks the age of my /bin directory.

I'm also confused about the usage of the -f and -F flags. The --help text says -F is used to supply target file path and -f is shorthand for --prefparse, however some of the documentation claims -f is used to supply target file path.

My Nagios version is 5.5.7, running on CentOS 7. The monitored server is running Debian 7.
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Checking the age of multiple files

Post by npolovenko »

Hello, @IkaIka. This plugin seems to be able to work with only 1 specific file. You may find a different plugin on the https://exchange.nagios.org/ or write your own plugin. Here's a simple example that uses the find command.

Code: Select all

[root@centos7x64 libexec]# cat fileAge.sh
#!/bin/bash

age=$1
path=$2

command=`find $path -type f -mtime +$age -name '*'`

if [[ $? != 0 ]]; then
    echo "Command failed."
elif [[ $command ]]; then
    echo "Error! Files found."
    exit 2;
else
    echo "Ok! No files found."
    exit 0;
fi

Code: Select all

[root@centos7x64 libexec]# ./fileAge 1 /var/log/
Error! Files found.
Where 1 means find all files older then 1 day. And /var/log/ is the directory where to look for files.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
IkaIka
Posts: 34
Joined: Fri Dec 21, 2018 4:37 am

Re: Checking the age of multiple files

Post by IkaIka »

Thank you, @npolovenko. Your script was very useful, I've worked it into our monitoring setup and it's already doing its job. This solves the problem.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Checking the age of multiple files

Post by scottwilkerson »

IkaIka wrote:Thank you, @npolovenko. Your script was very useful, I've worked it into our monitoring setup and it's already doing its job. This solves the problem.
Great!

Locking thread
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Locked