I am trying to monitor a directory on a server in which the amount of files can vary from day to day. This server itself is monitored fine on Nagios3.
However, if I want to count the number of files within a directory, for instance d:\david\
, which are all XML files.
Can nagios do this, and if so how would I do it? I am newish to Nagios and still finding my feet with it.
You need to write a script in any language you know/prefer to count the number of files in your directory. In this script, you can return specific exit status based on whether you want to consider the current state as OK, WARNING, or CRITICAL in nagios terms.
Then, you can use some tool like NSClient++ or Winrpe to call your script from nagios.
You can use the
nrpe
daemon (on the nagios server) to initiate a command on the remote host. In your Nagiosservices.cfg
you might add a stanza which looks like this (change theadmins
contact group to a real contact group on your system.. or leave commented out?):Then, on
my.windows.host
you would have to find thenrpe.cfg
file and add a line something like this (note: this is from a linux client but the configuration for windows is very similar)The file
check_david_files
would need to be some kind of executable (batch file works apparently) which prints either "OK', "WARNING", "CRITICAL" or "UNKNOWN" and then exits with the corresponding exit code:It is these exit coes which trigger the alert state in nagios to signal to the server somehting is amiss. It is in this batch file where you could do something like:
or for a warning:
To start out with, you may want to use only those two lines for testing your setup. Good luck.