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

Trying to setup plugin check_numoffiles.sh

Post by joshtate2001 »

I have downloaded the check_numoffile.sh plugin to warn me if the number of files in a directory exceeds a particular number.
I have tried to follow their usage example but cannot get it to pass the pre-check.

At first the issue was the command was not defined any where. So, I started looking at \nagios\etc\objects\command.cfg
I cannot figure out the proper syntax in my command.cfg. Below is the line I have in mine now:

#'check_numoffiles' command definition
define command{
command_name check_numoffiles
command_line $USER1$/check_numoffiles -d $PATH$ -w $WARN$ -c $CRIT$
}


This is the service definition below from my server object config file:

define service{
use doceserve-services
host_name doc-e-serve
service_description Active Folder Check
check_command check_numoffiles -d C:\DoceServe\Active -w 2 -c 4
}

Also, I placed the plugin "check_numoffiles.ssh" in my /nagios/libexec folder.

I am running Nagios Core Version 4.0.8 with the plugins package.
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Trying to setup plugin check_numoffiles.sh

Post by mcapra »

Could you share the guide you followed?

I assume you are referring to this plugin?
https://exchange.nagios.org/directory/P ... nt/details

Couple of things:

Code: Select all

define command{
command_name check_numoffiles
command_line $USER1$/check_numoffiles -d $PATH$ -w $WARN$ -c $CRIT$
}
Your command definition uses the $PATH$, $WARN$, and $CRIT$ macros. Are these macros defined anywhere? Info about macros:
https://assets.nagios.com/downloads/nag ... acros.html

Code: Select all

define service{
use	doceserve-services
host_name	doc-e-serve
service_description	Active Folder Check
check_command	check_numoffiles -d C:\DoceServe\Active -w 2 -c 4
}
This Service definition is not properly formatted for passing arguments. Also, on the receiving end with your Command definition accepting arguments generally uses the built-in macros $ARG1$, $ARG2$, $ARG3$, $ARGn$. See the above macros document for further information on this.

Is your Nagios Core installation running on a Windows machine? That looks like a Windows file path, where as the check_numoffiles.sh plugin is written as a shell script. Shell scripts will not run on Windows typically without the introduction of something like cygwin.
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 »

The part here I was guessing.

define command{
command_name check_numoffiles
command_line $USER1$/check_numoffiles -d $PATH$ -w $WARN$ -c $CRIT$
}
joshtate2001
Posts: 29
Joined: Wed Apr 08, 2015 1:55 pm

Re: Trying to setup plugin check_numoffiles.sh

Post by joshtate2001 »

Nagios COre itself is running on Ubunto Linux. The folder it is checking is a windows host though.
They did not really have a guide to follow for this plugin. I found the plugin itself off the Nagios site.
joshtate2001
Posts: 29
Joined: Wed Apr 08, 2015 1:55 pm

Re: Trying to setup plugin check_numoffiles.sh

Post by joshtate2001 »

I change the code in command.cfg to the following based on the replies:

Code: Select all

#'check_numoffiles' command definition
define command{
        command_name    check_numoffiles
        command_line    $USER1$/check_numoffiles -d $ARG1$ -w $ARG2$ -c $ARG3$$
}
I am still running into the following error when I run the pre-check.
-------------------------------------------------------------------------------------------------------------------------
Error: Service check command 'check_numofffiles -d C:\DoceServe\Active -w 2 -c 4' specified in service 'Active Folder Check' for host 'doc-e-serve' not defined anywhere.
-------------------------------------------------------------------------------------------------------------------------

Below is the code for the service from the host object cfg file.

Code: Select all

define service{
	use			doceserve-services
	host_name		doc-e-serve
	service_description	Active Folder Check
	check_command		check_numoffiles -d C:\DoceServe\Active -w 2 -c 4
	}
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Trying to setup plugin check_numoffiles.sh

Post by mcapra »

Your command definition has an extra $ on the 3rd argument. Your Service definition is pretty close! Example 2 in the docs I linked shows how to pass arguments in a Service definition:

Your Service definition should look like this:

Code: Select all

define service{
   use         doceserve-services
   host_name      doc-e-serve
   service_description   Active Folder Check
   check_command      check_numoffiles!C:\DoceServe\Active!2!4
   }
It's also worth mentioning that Nagios Core by itself has virtually no way to talk to a remote Windows machine (except ping/telnet) unless that Windows machine has an agent installed. Here's a document that briefly describes the process of setting up an agent on a Windows machine and monitoring that machine:
https://assets.nagios.com/downloads/nag ... ndows.html

Looking at the source, the check_numoffiles plugin doesn't have a way to request information from a remote machine; Everything is local. Also since it is written as a shell script, it is not an ideal candidate for monitoring a Windows environment.
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 »

I have an agent both the old nsclient agent and the NRPE agent runningon the host windows machine.
I will fix my extra $ and the command line for the service and let you know. Thanks!!
joshtate2001
Posts: 29
Joined: Wed Apr 08, 2015 1:55 pm

Re: Trying to setup plugin check_numoffiles.sh

Post by joshtate2001 »

So, I am real close.

I was able to get things to pass the verification. However, I get the following warning from Nagios.
It is complaining about the path.

-----------------------
(No output on stdout) stderr: execvp(/usr/local/nagios/libexec/check_numoffiles, ...) failed. errno is 2: No such file or directory
-----------------------

Command Code:

Code: Select all

#'check_numoffiles' command definition
define command{
        command_name    check_numoffiles
        command_line    $USER1$/check_numoffiles -d $ARG1$ -w $ARG2$ -c $ARG3$
}
Service Code:

Code: Select all

define service{
	use			doceserve-services
	host_name		doc-e-serve
	service_description	Active Folder Check
	check_command		check_numoffiles!C:\DoceServe\Active!2!4
	}
I think the issue now is the path or how I am passing it. Not sure if I need quotes, etc...
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Trying to setup plugin check_numoffiles.sh

Post by mcapra »

Are you certain the file /usr/local/nagios/libexec/check_numoffiles exists? The plugin I referenced is originally named check_nomoffiles.sh. If this is the plugin you are using, I would verify it's path. I would also make sure the nagios command group and user has permission to execute the script.

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
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 »

I have corrected the command syntax.

I now get (Return code of 13 is out of bounds) in the Nagios reported error.

Command Definition Code:

Code: Select all

#'check_numoffiles' command definition
define command{
        command_name    check_numoffiles.sh
        command_line    $USER1$/check_numoffiles.sh -d $ARG1$ -w $ARG2$ -c $ARG3$
}
Service Definition Code:

Code: Select all

define service{
	use			doceserve-services
	host_name		doc-e-serve
	service_description	Active Folder Check
	check_command		check_numoffiles.sh!C:\DoceServe\Active\!2!4
	}
Locked