Plugin | Check Folder Time Stamp

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
vgeyser
Posts: 8
Joined: Tue Sep 03, 2013 1:34 am

Plugin | Check Folder Time Stamp

Post by vgeyser »

We have multiple folders in a directory where the time stamp on these folders changes.
In these folders there is files from two months back and then also the latest files that gets generated on a minute basis.
The plugin needs to monitor the FOLDER time stamp so that we can get an alert if E.G. it gets older then 5 hours old.
[Please note that these FOLDERS names might change on a daily basis as well. We just need to make sure that any Folders in that directory is not older then 5 hours]

Thanks
User avatar
eloyd
Cool Title Here
Posts: 2129
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Plugin | Check Folder Time Stamp

Post by eloyd »

Some thoughts...maybe not a complete answer:

Code: Select all

stat -c "%Y" <filename>
This will give you the file creation time in seconds since Unix epoch. NOW - 5 hours will always be 5 x 60 x 60 seconds = 18000 seconds. So if:

Code: Select all

fileTime=`stat -c "%Y" filename`
NOW=`date +%s`
age=`expr $NOW - $fileTime`
[ "$age" -gt "18000" ] && echo "file is older than 5 hours"
That should get you started.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoydI'm a Nagios Fanatic!
vgeyser
Posts: 8
Joined: Tue Sep 03, 2013 1:34 am

Re: Plugin | Check Folder Time Stamp

Post by vgeyser »

is there not a plugin that I can install on nagios that can monitor this folders?
User avatar
eloyd
Cool Title Here
Posts: 2129
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Plugin | Check Folder Time Stamp

Post by eloyd »

I just wrote you one in my previous note. You are welcome to search the Nagios Exchange for something that already does this, but by changing one line and adding two more to what I already wrote, it would be a plugin:

Code: Select all

fileName="$1"
fileTime=`stat -c "%Y" ${fileName}`
NOW=`date +%s`
age=`expr $NOW - $fileTime`
[ "$age" -gt "18000" ] && echo "CRITICAL: ${fileName} is older than 5 hours" && exit 2
echo "OK: ${fileName} is not older than 5 hours" && exit 0
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoydI'm a Nagios Fanatic!
vgeyser
Posts: 8
Joined: Tue Sep 03, 2013 1:34 am

Re: Plugin | Check Folder Time Stamp

Post by vgeyser »

Hi Eloyd, I hope I don't sound to silly but am not a regular user of nagios and not sure how this work when you give me this code.
if it's not mush to ask can you please help me with steps to get this on nagios for it to look at a server to monitor the folders?
User avatar
eloyd
Cool Title Here
Posts: 2129
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Plugin | Check Folder Time Stamp

Post by eloyd »

I can certainly help you with that, but it may not be today. If you want to start learning about Nagios plugin development, check https://nagios-plugins.org/doc/guidelines.html. Mostly, you need to take the script I gave you, save it as /usr/local/nagios/libexec/check_file_time on your Nagios server, and then create a commands.cfg configuration that calls it so you can use a services.cfg service definition to check it. You may need to get NRPE involved to run it on a remote server (it is unclear to me if you are running this check on the Nagios server or some other server), but this all really isn't hard, you just have to put the stuff in the right place.

I may submit something to the Nagios Exchange for this later, but the basics of what you need to do are above. I'll see if I can get back to it later today or over the weekend for you.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoydI'm a Nagios Fanatic!
User avatar
eloyd
Cool Title Here
Posts: 2129
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Plugin | Check Folder Time Stamp

Post by eloyd »

Hey, I just submitted a basic plugin to the Nagios Exchange, but you can get the same thing here: http://bitnetix.com/nagios/plugins/check_file_time.

Usage: check_file_time -f <filename> -w <warn_seconds> -c <crit_seconds>

If <filename> was last modified more than <warn_seconds> ago, it will return a WARNING. If it was last modified more than <crit_seconds> ago, it will return a CRITICAL. Otherwise, it will return an OK.

Add that to a command definition and call it for your service check on the local Nagios host and you should be good to go.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoydI'm a Nagios Fanatic!
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Plugin | Check Folder Time Stamp

Post by sreinhardt »

Thanks eloyd! Keep up that MVP status! vgeyser, let us know if you have more questions!
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
vgeyser
Posts: 8
Joined: Tue Sep 03, 2013 1:34 am

Re: Plugin | Check Folder Time Stamp

Post by vgeyser »

Hi Eloyd,

Thanks for the help that you provided to me, really appreciated this.
It looks to me with your code I need to specify each folder that needs to be monitored?

Let me give you more information about our setup about the server.
This server that we need to monitor with Nagios is a voice recording server.
On the D: drive we have a folder called "recorderdate" that was created in May and the time stamp on this folder does not change.
In this folder we have about 250 other folder that needs to get updated every 30min and these folders gets updated with the time stamp.
The only problem that we might have here is that these folders names might change from time to time.
I just need to make sure that all the folders in the recorderdate folder get updated on a regular time.
User avatar
eloyd
Cool Title Here
Posts: 2129
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Plugin | Check Folder Time Stamp

Post by eloyd »

Yes, as written, you need to specify the folder name:

Usage: check_file_time -f <filename> -w <warn_seconds> -c <crit_seconds>

However, the fact that you desire to check the folder on a Windows box means everything I told you won't work. This plugin is designed for a Unix environment. You will need to look into either NSClient++ or a scripting solution that lets you achieve what you want, plus you will need to implement it through an agent or SNMP (NSClient++ is an agent, so I would start with that).

I don't monitor Windows boxes very much, so any further assistance I provide will mostly be the results of my Google searches for "nsclient++ check file age"
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoydI'm a Nagios Fanatic!
Locked