Nagios command help


#1

Is there a plugin or command I can use to check the number of files in a specific directory? I want to monitor a directory form a cisco Unity server where files queue up. I want nagios to warn me if files go up over 100 and critical if its over 200. Any ideas?


#2

For Linux machine, a bash script could do that.

#!/bin/bash count=`ls -1 /path/to/directory | wc -l` if $count -ge 100 ]; then echo "There are more then 100 files" && exit 2 else echo "There are $count files" && exit 0 fi

That is if you plan to locate the files on Nagios server. If you want to run the script on remote server and send data back to Nagios server, you could do that with NRPE. I won’t go fully how to configure NRPE.

Other way to acomplish that is just make the file count script on the cisco Unity server:

#!/bin/bash count=`ls -1 /path/to/directory | wc -l` echo $count
configure snmpd.conf on remote cisco Unity server (again, if it is Linux) with an exec command, like this:

Don’t foget to reload snmpd daemon on the cisco Unity server.
The script must reside on your cisco Unity server on the path specified and be executable.

From Nagios server check if you get the right response from the snmp query on the remote server with the command run from the terminal:
snmpget -v2c -c community x.x.x.x .1.3.1.4.6.9999.9999.9999.9999.1

Then, in Nagios make the check_snmp check for that server with the OID specified (.1.3.1.4.6.9999.9999.9999.9999.1)
On Nagios server there should be a script that would handle the snmp output:

#!/bin/bash snmp=`snmpget -v2c -Oqv -c community x.x.x.x .1.3.1.4.6.9999.9999.9999.9999.1` if $snmp -ge 100 ]; then echo "There are more then 100 files" && exit 2 else echo "There are $count files" && exit 0 fi
where x.x.x.x is the IP address of you cisco Unity server