Checking the age of multiple files

This board serves as an open discussion and support collaboration point for Nagios XI. NOTE: Nagios XI customers should use the Customer Support forum to obtain expedited support.

Checking the age of multiple files

Postby IkaIka » Thu Jun 13, 2019 3:34 am

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.
IkaIka
 
Posts: 14
Joined: Fri Dec 21, 2018 4:37 am

Re: Checking the age of multiple files

Postby npolovenko » Thu Jun 13, 2019 4:02 pm

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.
User avatar
npolovenko
Support Tech
 
Posts: 3442
Joined: Mon May 15, 2017 5:00 pm


Return to Nagios XI

Who is online

Users browsing this forum: Google [Bot] and 12 guests