Hello,
i hope i can get some advice from the community on how to check the age of a group of files on a linux machine.
The situation is as follows: We have an old Linux Server which sends SMS. Various programs store textfiles on a share on that server and a programm checks for new files every few seconds, sends the message to the cell phone number which is in the file name and then stores the textfile in an archive. Sometimes the delivery of short messages stops because someone (or something) tries to send a message to a cell phone number which doesn't exist. So i would like nagios to check if there are any numer of files older than 10 minutes in that directory.
The problem is: I have tried to use the standard plugin check_file_age and let it search for all files (*) in this directory which are older than 600 seconds. As long as there is a file everything is fine. The response is critical if there's an old file and OK if are files which are not yet old enough. But when there is no file at all (in other words directory is empty) i also receive a critical response from the plugin. And the directory is empty for 99% of the day. So this plugin is pretty useless for me in this case.
I also tried to check it via a Windows Host which checks the file age via NSClient++ over the network. But NSClient++ would neither accept UNC nor a connected network drive as value for the path parameter in CheckFile2.
Since the server in question is quite old and its' OS is out of support, do you know a plugin i can use for linux which works similar to NSClients' CheckFile2 and doesn't require python or perl ? There are a few more servers and installing python or perl on them would be quite some pain.
Greetings, Ved
Checking File Age on Linux
Re: Checking File Age on Linux
You could just write a wrapper script around check_file_age. It would look something like this (the actual code here won't work though):
And of course, you should probably file a bug report with the Nagios plugins team so that this kind of workaround won't even be needed in the future.
Code: Select all
#!/bin/sh
if [ `ls "$1" | wc -l` -eq 0 ]; then
echo OK
exit 0
else
exec /usr/local/nagios/libexec/check_file_age cmdline...
fiRe: Checking File Age on Linux
Thanks Griffin,
the wrapper was a great idea.
I couldn't figure out how to implement the command inside the if-condition. So this is how i got it to work :
It's roughly tested, so if anyone needs it, feel free to use.
Greetings, Ved.
the wrapper was a great idea.
I couldn't figure out how to implement the command inside the if-condition. So this is how i got it to work :
Code: Select all
#!/bin/sh
filecount=`ls "$1" | wc -l`
if [ $filecount == 0 ] then
echo "OK - $1 - 0 files"
exit 0
else
exec /usr/local/nagios/libexec/check_fileage -d $1 -w $2 -c -$3 -t $4
fi
Greetings, Ved.
Re: Checking File Age on Linux
Glad you got it working!