monitor file count of a folder

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
rnjie
Posts: 157
Joined: Wed Mar 20, 2019 4:59 pm

monitor file count of a folder

Post 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
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: monitor file count of a folder

Post 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
Be sure to check out our Knowledgebase for helpful articles and solutions!
rnjie
Posts: 157
Joined: Wed Mar 20, 2019 4:59 pm

Re: monitor file count of a folder

Post 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.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: monitor file count of a folder

Post 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.
Be sure to check out our Knowledgebase for helpful articles and solutions!
rnjie
Posts: 157
Joined: Wed Mar 20, 2019 4:59 pm

Re: monitor file count of a folder

Post by rnjie »

i am using ncpa, can i get the steps for that instead of nrpe?
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: monitor file count of a folder

Post 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.
Be sure to check out our Knowledgebase for helpful articles and solutions!
rnjie
Posts: 157
Joined: Wed Mar 20, 2019 4:59 pm

Re: monitor file count of a folder

Post by rnjie »

it worked, thanks
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: monitor file count of a folder

Post by scottwilkerson »

rnjie wrote:it worked, thanks
Great!

Locking
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked