Trying to setup plugin check_numoffiles.sh

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.
joshtate2001
Posts: 29
Joined: Wed Apr 08, 2015 1:55 pm

Re: Trying to setup plugin check_numoffiles.sh

Post by joshtate2001 »

The final nail ended up being a permission issue with the plugin. I did a chmod 755 on check_numoffiles.sh and restarted the nagios. It seems to be now reporting correctly.
joshtate2001
Posts: 29
Joined: Wed Apr 08, 2015 1:55 pm

Re: Trying to setup plugin check_numoffiles.sh

Post by joshtate2001 »

Well, I was able to solve the error regarding the (Return code 13 being out of bounds).
This was a permission issue on the plugin it self.

The service is showing green and reporting 0 files.
I dropped three files in the folder, which should have generated a warning.

The service is still green and reporting 0 files. Not sure what I am missing.
I restarted the nagios processes and did a re-check of the service, but still showing the same.
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Trying to setup plugin check_numoffiles.sh

Post by rkennedy »

Code: Select all

   check_command      check_numoffiles.sh!C:\DoceServe\Active\!2!4
It looks like you're trying to execute a bash script, with a windows path. Just to clarify - Are you dropping files in that folder above?

See what @mcapra mentioned above -
Also, if your intention is to use this plugin to check the number of files on a remote machine, you would need to put that script on the remote machine and execute it via check_nt, check_nrpe, or check_by_ssh.
Former Nagios Employee
joshtate2001
Posts: 29
Joined: Wed Apr 08, 2015 1:55 pm

Re: Trying to setup plugin check_numoffiles.sh

Post by joshtate2001 »

The intention is to use the plugin to check the number of files in folder specified in my code above. This is a folder on a remote windows machine.
The remote machine (host) is running the NSClient++ agent on the remote windows host.

I saw some examples of how to use the nsclient cfg file to basically call the script from the agent somehow. It was very unclear.

So, I am trying to figure out what I need to do on the host side with the script itself (check_numoffiles.sh) and/or the ncclient cfg file.
Then I guess I would need to do something different with the service command for the object cfg file.
joshtate2001
Posts: 29
Joined: Wed Apr 08, 2015 1:55 pm

Re: Trying to setup plugin check_numoffiles.sh

Post by joshtate2001 »

How do I check the number of files in a folder using check_nt?
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Trying to setup plugin check_numoffiles.sh

Post by Box293 »

joshtate2001 wrote:The intention is to use the plugin to check the number of files in folder
There's no need to create any special scripts, NSClient++ has this functionality built in using check_nrpe (can't be done with check_nt).

Example
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.

Command:

Code: Select all

check_nrpe -H 192.168.142.1 -t 30 -c CheckFiles -a path='C:\\NO BACKUP' pattern=*.* 'master-syntax={%total% Files Found}' MaxWarn=500 MaxCrit=1000

Output:
{12347 Files Found}, found files: 12347 > critical|'found files'=12347;500;1000
There's more examples here:
http://sites.box293.com/nagios/guides/c ... es-folders
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
joshtate2001
Posts: 29
Joined: Wed Apr 08, 2015 1:55 pm

Re: Trying to setup plugin check_numoffiles.sh

Post by joshtate2001 »

Thanks for your help! I have done this code for my service, but I am getting a error on verifying the config in nagios.

Service Code:

Code: Select all

define service{
	use			doceserve-services
	host_name		doc-e-serve
	service_description	Fileage Verification of C:\Doceserve\Active
	check_command		check_nrpe -c CheckFiles -a path='C:\\WJTNagiosTest' pattern=*.* 'master-syntax={%total% Files Found}' MaxWarn=500 MaxCrit=1000
	}	
I do not specify hostname or port because that is dfned in the Command Difinition:

Code: Select all

# 'check_nrpe' command definition
define command{
        command_name    check_nrpe
        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ -a $ARG2$
}
joshtate2001
Posts: 29
Joined: Wed Apr 08, 2015 1:55 pm

Re: Trying to setup plugin check_numoffiles.sh

Post by joshtate2001 »

So, based on my code in my command definition:

Code: Select all

# 'check_nrpe' command definition
define command{
        command_name    check_nrpe
        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ -a $ARG2$
}
I changed my service code to this:

Code: Select all

define service{
	use			doceserve-services
	host_name		doc-e-serve
	service_description	Fileage Verification of C:\Doceserve\Active
	check_command		check_nrpe!CheckFiles!-a path='C:\\WJTNagiosTest' pattern=*.* 'master-syntax={%total% Files Found}' MaxWarn=500 MaxCrit=1000
	}
The config passes verification in Nagios. However, I am now getting this error in nagios UI.
Exception processing request: Request command contained illegal metachars!
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Trying to setup plugin check_numoffiles.sh

Post by mcapra »

There's a specific setting in NSClient to account for this:

Code: Select all

[/settings/NRPE/server]
allow nasty characters=true

[/settings/external scripts]
allow nasty characters=true
From:
http://docs.nsclient.org/faq/#nasty-metacharacters
Former Nagios employee
https://www.mcapra.com/
joshtate2001
Posts: 29
Joined: Wed Apr 08, 2015 1:55 pm

Re: Trying to setup plugin check_numoffiles.sh

Post by joshtate2001 »

That got rid of the meta character issue. Now getting.
Unknown argument: -a
Service Code:

Code: Select all

define service{
	use			doceserve-services
	host_name		doc-e-serve
	service_description	Fileage Verification of C:\Doceserve\Active
	check_command		check_nrpe!CheckFiles!-a path='C:\\WJTNagiosTest' pattern=*.* 'master-syntax={%total% Files Found}' MaxWarn=500 MaxCrit=1000
	}
Command Code:

Code: Select all

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