Page 1 of 1

monitor file count of a folder

Posted: Thu Jan 09, 2020 4:48 pm
by rnjie
Can Nagios monitor the file count of a particular folder? as in when it reaches a certain amount then an alert should be sent out

Re: monitor file count of a folder

Posted: Thu Jan 09, 2020 5:01 pm
by lmiltchev
Is this folder located on a Windows system, Linux, etc.? You could search for a suitable plugin on the Nagios Exchange:

https://exchange.nagios.org/

Once you find a plugin that works for you, you could add a command and a service to Nagios XI by following the document below:

https://assets.nagios.com/downloads/nag ... ios-XI.pdf

Re: monitor file count of a folder

Posted: Mon Jan 13, 2020 10:54 am
by rnjie
i found a plugin (count_file.pl) that can work for me and i tested it on the command line and it worked for the nagios server, but how do i get it to monitor client servers? there is no option or arguement that lets you specify a client host to monitor like -H for host name of -C for community, am not sure how to monitor client remote hosts.. see command below for nagios servers it self

libexec]# ./count_file.pl /tmp 100 120
OK: Filecount of '/tmp' 10.

Re: monitor file count of a folder

Posted: Mon Jan 13, 2020 11:35 am
by lmiltchev
The plugin is designed to monitor file count locally, so you will have to copy the plugin to the client (remote machine). If you only have a few clients that you would like to monitor, you could copy the plugin via scp, e.g.

Code: Select all

scp /usr/local/nagios/libexec/count_file.pl [email protected]:/usr/local/nagios/libexec/
where you substitute x.x.x.x with the actual IP address of the remote machine.

If you had many clients, you could transfer the file in bulk to all of the machines via something like Ansible.

Once you have your plugin installed on the remote machine, you could call it from your Nagios XI server, via some kind of agent, e.g. NRPE, NCPA, etc.

Example with NRPE:

1. You will need to have NRPE agent installed. If you haven't installed it yet, you could follow this guide:
https://assets.nagios.com/downloads/nag ... _Agent.pdf

2. You add a new command definition to nrpe.cfg or common.cfg file on the remote machine (client), e.g.

Code: Select all

command[check_count]=/usr/local/nagios/libexec/count_file.pl $ARG1$ $ARG2$ $ARG3$
and restart nrpe or xinet, depending on how you installed the agent:

Code: Select all

service nrpe restart
or

Code: Select all

service xinetd restart
3. Next you test it by running the following command from the command line on the Nagios XI server:

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H <client ip> -c check_count -a /tmp 100 120
Actual example from my main test XI server:

Code: Select all

[root@main-nagios-xi ~]# /usr/local/nagios/libexec/check_nrpe -H x.x.x.x -c check_count -a /tmp 100 120
Critical: Filecount of '/tmp' too large 950 > 100.

Re: monitor file count of a folder

Posted: Mon Jan 13, 2020 12:12 pm
by rnjie
i am using ncpa, can i get the steps for that instead of nrpe?

Re: monitor file count of a folder

Posted: Mon Jan 13, 2020 1:51 pm
by lmiltchev
Sure. Copy the "count_file.pl" plugin to the "/usr/local/ncpa/plugins" directory on the remote machine, then run the following command on the Nagios XI server to test it:

Code: Select all

/usr/local/nagios/libexec/check_ncpa.py -H <client ip> -t '<token>' -M 'plugins/count_file.pl' -q 'args=/tmp,args=100,args=120'
where you substitute <client ip> and '<token> with the actual values.

Hope this helps.

Re: monitor file count of a folder

Posted: Mon Jan 13, 2020 2:10 pm
by rnjie
it worked, thanks

Re: monitor file count of a folder

Posted: Mon Jan 13, 2020 2:29 pm
by scottwilkerson
rnjie wrote:it worked, thanks
Great!

Locking