Check Directory for Sub-Directories (Check_Files)

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.
Locked
warnox
Posts: 39
Joined: Thu Nov 20, 2014 5:22 am

Check Directory for Sub-Directories (Check_Files)

Post by warnox »

Hi,

I need to monitor a directory (F:\ABC) to make sure a sub directory is created each day (F:\ABC\050815, F:\ABC\060815...). I believe it should be possible to do this via Check_Files but I'm not sure exactly how, since I can't find any information which is folder specific.

If anyone can point me in the right direction that would be great.

Using Nagios 4.0.8 and NSClient 0.4.3.

Thanks in advance.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Check Directory for Sub-Directories (Check_Files)

Post by tmcdonald »

I assume the new directory is created according to a predictable naming scheme? If so you will need some way to tell the Check_Files path parameter which full path to use. You can use the linux command `date +%d%m%y` (note the backticks) to get the date format you appear to be using, and you can stick that in your commands.cfg as the path name.
Former Nagios employee
warnox
Posts: 39
Joined: Thu Nov 20, 2014 5:22 am

Re: Check Directory for Sub-Directories (Check_Files)

Post by warnox »

That plan is a whole lot better than what I was working with (filtering for folders created in the last week and alerting if none of the folders were created in the last day).

Got it to work with the command below, I think that will be sufficient. If you have any suggestions for improvements I'm all ears :)

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H 192.168.1.60 -c check_files -a file="c:\\TEMP" "max-depth=1" "filter=filename='`date +%d%m%y`'" "critical=count<1" empty-syntax=CRITICAL
Now, because I had to upgrade the client to 0.4.3, check_disk picks up System Volumes and alerts, doh.
warnox
Posts: 39
Joined: Thu Nov 20, 2014 5:22 am

Re: Check Directory for Sub-Directories (Check_Files)

Post by warnox »

Spoke too soon. Do you know what the options are for 'empty-state'? I tried 'CRITICAL' and '2' but whatever I put in Nagios returns 'UNKNOWN'. This was apparently a bug in previous versions but should be fixed now.

I'm not sure how to return the 'state' value when manually executing 'check_nrpe'.

Thanks again.
User avatar
lmiltchev
Former Nagios Staff
Posts: 13587
Joined: Mon May 23, 2011 12:15 pm

Re: Check Directory for Sub-Directories (Check_Files)

Post by lmiltchev »

The check seems to be working for me. I am running NSClient++ v.0.4.3.143.

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H x.x.x.x
I (0.4.3.143 2015-04-29) seem to be doing fine...
I created an empty folder on my workstation (c:\tmp\empty) and tested the check from the CLI:

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H x.x.x.x -c check_files -a file="c:\tmp" "max-depth=1" "filter=filename='empty'" "critical=count<1" empty-state=CRITICAL empty-syntax=CRITICAL
OK: All 1 files are ok|'count'=1;0;1
echo $?
0
/usr/local/nagios/libexec/check_nrpe -H x.x.x.x -c check_files -a file="c:\tmp" "max-depth=1" "filter=filename='full'" "critical=count<1" empty-state=CRITICAL empty-syntax=CRITICAL
CRITICAL|'count'=0;0;1
echo $?
2
Be sure to check out our Knowledgebase for helpful articles and solutions!
warnox
Posts: 39
Joined: Thu Nov 20, 2014 5:22 am

Re: Check Directory for Sub-Directories (Check_Files)

Post by warnox »

Cool, that does seem to work, I had CRITICAL as 'CRITICAL' so I guess that's where it was failing.

All good now, thanks both for your help!

Final command I used is:

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H 192.168.1.60 -c check_files -a file="c:\\TEMP" "max-depth=2" "filter=filename='`date +%d%m%Y`'" "critical=count<1" "empty-state=CRITICAL" "empty-syntax=CRITICAL - Cannot find folder `date +%d%m%Y`"
User avatar
lmiltchev
Former Nagios Staff
Posts: 13587
Joined: Mon May 23, 2011 12:15 pm

Re: Check Directory for Sub-Directories (Check_Files)

Post by lmiltchev »

I am glad we could help! :)
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked