Page 1 of 2
Check file age
Posted: Tue Jun 30, 2015 7:14 pm
by spiderpig
Hi,
I am trying to monitor a .txt file on a windows server machine, if the file gets older than x days it should by flagged in Nagios.
I'm using
https://exchange.nagios.org/directory/P ... ck/details
I got it working on a linux
"./check_fileage.py -f /var/test.txt -w 1440 -c 2880"
but without a luck on a windows share, I even set the share and permission to everyone so that is not the issue.
what is the right syntax ?
Re: Check file age
Posted: Tue Jun 30, 2015 8:11 pm
by Box293
spiderpig wrote:but without a luck on a windows share, I even set the share and permission to everyone so that is not the issue.
What is the exact command you are using to check a file on a share?
How are you accessing the share?
Are you testing as the user nagios?
Code: Select all
su nagios
./check_fileage.py blah blah blah
As a side note, if your Windows servers have NSClient++ installed, then this functionality is already built in:
Check a folder to determine if any files exist that are older than two hours. Generate a critical alert if at least 1 file matches this criteria.
Code: Select all
Command:
check_nrpe -H 192.168.142.137 -c CheckFiles -a path='D:\\Important Stuff\\Important File.txt' 'filter=written < -2h' 'master-syntax={%total% Files Found}' MaxCrit=1
Output when files matching criteria are found:
{3 Files Found}, found files: 3 > critical|'found files'=1;0;1
Output when NO files matching criteria are found:
{0 Files Found}|'found files'=0;0;1
I have a bunch of examples like this on my website:
https://sites.google.com/a/box293.com/n ... ders?pli=1
Re: Check file age
Posted: Wed Jul 01, 2015 5:48 am
by spiderpig
I was trying to use "./check_fileage.py -f \\server\test.txt -w 1440 -c 2880" as a root user
probably that is wrong
I tried running this on the nagios server but got an error.
check_nrpe -H myserver -c CheckFiles -a path='C:\\mypath\\test.txt' 'filter=written < -2h' 'master-syntax={%total% Files Found}' MaxCrit=1
"Unknown: No handler for that command"
Is this error because I'm using a old nsclient++ client?
I'm using a 0.3.8.76 2010-05-27 x64
Re: Check file age
Posted: Wed Jul 01, 2015 9:08 am
by jdalrymple
spiderpig wrote:I was trying to use "./check_fileage.py -f \\server\test.txt -w 1440 -c 2880" as a root user
probably that is wrong

So you were actually trying to check the age of a file on an SMB share from a Linux/UNIX host? Normal \\UNCSERVER\UNCSHARE constructs don't work in most Linux/UNIX shells.
Can you be more descriptive about where you were running your python script and also where the file actually is? Is it local to the machine from which you're running the python script? Also is that machine in fact the Nagios server?
Re: Check file age
Posted: Wed Jul 01, 2015 10:03 am
by spiderpig
I'm trying to run the python script from the Nagios server(centos), the script is located in /var/tmp.
The file that I am trying to monitor is on a windows host, running the NSClient++ service.
Re: Check file age
Posted: Wed Jul 01, 2015 10:16 am
by jdalrymple
The high level process is that you'll have to move the script to Windows and make it run there.
After making it run on Windows you'll have to define a command in nsc.ini (you may wish to take advantage of the opportunity to upgrade, in which case it would be nsclient.ini)
Once your command is defined you'll be running check_nrpe from the Nagios host, directing it towards NRPE daemon on the Windows host which will execute your script.
That's the order of operations - but as Box293 said, nsclient++ has the ability built in and it will simplify the whole process. Use his example - but again, good time to upgrade so that you're on the same page he is. Often times the usage changes between nsclient++ versions.
Re: Check file age
Posted: Wed Jul 01, 2015 6:25 pm
by Box293
I did check using NSClient++ 0.3.8.76 and I got the same error "UNKNOWN: No handler for that command".
When trying the same command using NSClient++ 0.3.9.330 it worked.
I suggest upgrading the the 0.3.9 version of NSClient++, that will be the easiest option.
Re: Check file age
Posted: Fri Jul 03, 2015 9:16 am
by spiderpig
Box293 wrote:I did check using NSClient++ 0.3.8.76 and I got the same error "UNKNOWN: No handler for that command".
When trying the same command using NSClient++ 0.3.9.330 it worked.
I suggest upgrading the the 0.3.9 version of NSClient++, that will be the easiest option.
Thank you, it worked now manually after I installed NSClient++ 0.39. What should I add in the host cfg file so it will work automatically with the other checks for this server ?
should I add in the nsc.ini on the client and also on in the host.cfg on ther server?
Re: Check file age
Posted: Mon Jul 06, 2015 1:22 am
by Box293
If it manually worked then your nsc.ini file doesn't require any additional changes.
Your check_command would look something like:
Code: Select all
check_nrpe!CheckFiles!-a path='D:\\Important Stuff\\Important File.txt' 'filter=written < -2h' 'master-syntax={%total% Files Found}' MaxCrit=1
Re: Check file age
Posted: Mon Jul 06, 2015 6:07 am
by spiderpig
ok, but the big question is, where do I put this command?
should I put it in the .cfg for the server?