Check Number Files in a directory

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.
cocoyanouck
Posts: 96
Joined: Fri Apr 08, 2016 3:17 am

Re: Check Number Files in a directory

Post by cocoyanouck »

Hum, I'm working on Nagios 4.1.1 on a Debian Jessie, i think it's different to Nagios XI server no ??

So, today, i've in command.cfg :

Code: Select all

define command{
       command_name        check_nrpe
       command_line          $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ -a $ARG2$
}

define command{
        command_name      CheckNumberFiles
        command_line         $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ -a $ARG2$
}
In windows.cfg, I've tested 2 services, the first like my colleague used it on our old Nagios Windows, the second like this is written on check_files.vbs in the directory script to NSCLIENT++ 0.4.4 :

Code: Select all

define service{
     use                              generic-service
     host_name                   NAME OF MY SERVER
     notification_interval     20
     service_description      Number of files on Request
     check_command          CheckNumberFiles!check_files!/path:"c:\\GESTION\\REQUEST" /searchdepth:1 /selage:ignore /warning:5 /critical:10
}

define service{
     use                              generic-service
     host_name                   NAME OF MY SERVER
     notification_interval     20
     service_description      Number of files on Request 2
     check_command          check_nrpe!check_files!/path:"c:\\GESTION\\REQUEST" /searchdepth:1 /selage:ignore /warning:5 /critical:10
}
====> When i restart nagios and test it : I've on the both services,
Number of files on Request
UNKNOWN 12-04-2016 09:27:19 0d 0h 17m 15s 3/3 Invalid command line: unrecognised option '/path:c:GESTIONREQUEST'
Number of files on Request 2
UNKNOWN 12-04-2016 09:22:12 0d 0h 12m 22s 3/3 Invalid command line: unrecognised option '/path:c:GESTIONREQUEST'

So, when i run the command in /usr/local/nagios/libexec : ./check_nrpe -H @IPofmyserver -c check_files -a path=c:/GESTION/REQUEST
for the FIRST TIME, it works !!! and the output is :
OK: All 2 files are ok.

But i still not understand what I need to wrote on path in the descriptions of the service :(
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Check Number Files in a directory

Post by Box293 »

cocoyanouck wrote:In windows.cfg, I've tested 2 services, the first like my colleague used it on our old Nagios Windows, the second like this is written on check_files.vbs in the directory script to NSCLIENT++ 0.4.4 :
You don't need any special scripts to check files, NSClient++ has a module built in.

Check the amount of files in a folder (and sub-folders). Generate a warning if more that 500 files exist, critical if more than 1000 files exist.

Code: Select all

Command:
check_nrpe -H 192.168.142.1 -t 30 -c check_files -a path='C:\\NO BACKUP' pattern=*.* 'warning=count>500' 'critical=count>1000' top-syntax='${status}: ${problem_count}/${count} files' 'empty-state=ok'

Output:
CRITICAL: 21778/22278 files|'count'=22278;500;1000
Lots of examples here:
http://sites.box293.com/nagios/guides/c ... es-folders

:!: Tip: before trying to make it working in a nagios config, make sure it works from the command line first. It'll make troubleshooting much easier.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
cocoyanouck
Posts: 96
Joined: Fri Apr 08, 2016 3:17 am

Re: Check Number Files in a directory

Post by cocoyanouck »

Thank you. I've ever seen this website and used this example.
check_nrpe -H 192.168.142.1 -t 30 -c check_files -a path='C:\\NO BACKUP' pattern=*.* 'warning=count>500' 'critical=count>1000' top-syntax='${status}: ${problem_count}/${count} files' 'empty-state=ok'

So, when i test this command, it's perfect ! :
check_nrpe -H @IPmyserver -t 30 -c check_files -a path='C:\\GESTION\\REQUEST' pattern=*.* 'warning=count>5' 'critical=count>10' top-syntax='${status}: ${problem_count}/${count} files' 'empty-state=ok'
I also can modify the path like this, and it's works too :
check_nrpe -H @IPmyserver -t 30 -c check_files -a path='C:/GESTION/REQUEST' pattern=*.* 'warning=count>5' 'critical=count>10' top-syntax='${status}: ${problem_count}/${count} files' 'empty-state=ok'

But when i modify windows.cfg to inser this command like a service :

Code: Select all

define service{
     use                              generic-service
     host_name                   NAME OF MY SERVER
     notification_interval     20
     service_description      Number of files on Request
     check_command          check_nrpe!check_files!/path='c:\\GESTION\\REQUEST' pattern=*.* 'warning=count>5' 'critical=count>10' top-syntax='${status}: ${problem_count}/${count} files' 'empty-state=ok'
}
I see in my web nagios interface this return : Number of files on Request
UNKNOWN 12-04-2016 11:47:19 0d 2h 40m 37s 3/3 Invalid command line: unrecognised option '/path=c:\GESTION\REQUEST'


It's awesome, I'm block since 1 week :/ arglllllll
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Check Number Files in a directory

Post by Box293 »

Simple argument mistake

Code: Select all

/path='c:\\GESTION\\REQUEST
This should be

Code: Select all

path='c:\\GESTION\\REQUEST
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
cocoyanouck
Posts: 96
Joined: Fri Apr 08, 2016 3:17 am

Re: Check Number Files in a directory

Post by cocoyanouck »

Eureka !

Problem solved, thanks a lot !!!!!
jolson
Attack Rabbit
Posts: 2560
Joined: Thu Feb 12, 2015 12:40 pm

Re: Check Number Files in a directory

Post by jolson »

That's excellent to hear, I'll close it up!
Twits Blog
Show me a man who lives alone and has a perpetually clean kitchen, and 8 times out of 9 I'll show you a man with detestable spiritual qualities.
Locked