CheckFiles format

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.
Locked
guizalan
Posts: 20
Joined: Mon Mar 16, 2015 3:53 pm

CheckFiles format

Post by guizalan »

Hi,

when using CheckFiles for monitoring file size:

root@nagios:/home/nagios# check_nrpe -H naud12 -c CheckFiles -a path=c:/Program\ Files/NSClient++/nsclient.log "filter=size > 100k" "syntax=%filename%: %size%" MaxWarn=1 MaxCrit=1
nsclient.log: 495263|'count'=1;1;1

root@nagios:/home/nagios# check_nrpe -H naud12 -c CheckFiles -a path=c:/Program\ Files/NSClient++/nsclient.log "filter=size > 1000k" "syntax=%filename%: %size%" MaxWarn=1 MaxCrit=1
No drives found|'count'=0;1;1

1- How do I change size from bytes to Megabytes or Gigabytes?
2- On this case, when the file size is smaller then what is configured, it shows: "No drives found!" I would like to change this to "OK" or just to output the file size. How do I do that?
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: CheckFiles format

Post by ssax »

What version of NSClient++ are you running?
guizalan
Posts: 20
Joined: Mon Mar 16, 2015 3:53 pm

Re: CheckFiles format

Post by guizalan »

Sorry,

NSClient++ 0.4.3.131 2015-02-15
and
Nagios Version 4.0.8
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: CheckFiles format

Post by ssax »

It's working properly on mine, can you try using NSClient++ 0.4.1.105 and let me know if that works for you? The later versions of NSClient++ have had issues.
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: CheckFiles format

Post by Box293 »

OK so there are a number of things I will talk about here. Sorry if it gets complicated :lol:

The commands in 0.4.3 have changed and the online manual isn't that great. I'm still learning them however I am providing you with some examples which should give you what you are after. The key thing is that you want the check called check_files NOT CheckFiles.

When targeting a specific file, instead of using:

Code: Select all

path="c:\\Program Files\\NSClient++" pattern="nsclient.log"
Use this instead:

Code: Select all

file="c:\\Program Files\\NSClient++\\nsclient.log"
When using a path and pattern, it iterates over all the files in that path to find the file.
When using file, it only looks for that specific file in that location.


guizalan wrote:1- How do I change size from bytes to Megabytes or Gigabytes?
I found there is an argument called perf-config however this documentation did not contain much information:
http://docs.nsclient.org/reference/wind ... heck-files

However the key information is here:
http://nsclient.org/nscp/ticket/684

Code: Select all

"perf-config=size(unit:M)"
"perf-config=size(unit:G)"
NOTE: The capital M or G is required, lower case does not work!

Now, this only appears to affect the performance data part of the string (everything to the RIGHT of the pipe | symbol).

Code: Select all

CRITICAL: 0/1 files (nsclient.log)|'nsclient.log size'=0.31999M;0;0.00009
You can display the file size in the status detail (everything to the LEFT of the pipe | symbol). This is done using the detail-syntax argument HOWEVER it is displayed as the original value.

Code: Select all

"detail-syntax=${status}%(file) = %(size)"

Code: Select all

CRITICAL: 0/1 files (nsclient.log = 339708)|'nsclient.log size'=0.32397M;0;0.00292
I have logged a feature request / bug report for this on GitHub:
https://github.com/mickem/nscp/issues/125



guizalan wrote:On this case, when the file size is smaller then what is configured, it shows: "No drives found!" I would like to change this to "OK" or just to output the file size. How do I do that?
Regardless of version, using a filter restricts what is returned. If the file size is smaller then what is configured in the filter, then is is not included in the matches and hence cannot be reported on when there is an OK state.

What you want is to use the critical argument to specify the size. NOTE: This also has changed, it is critical not MaxCrit and has a syntax.

Code: Select all

"critical=size>100k"

Code: Select all

CRITICAL: 0/1 files (nsclient.log)|'nsclient.log size'=0.3331M;0;0.00009
NOTE: the lower CASE k is important here, upper case K will not work.

Sooooo with all that in mind, here are the commands you should be using:

Code: Select all

Command:
check_nrpe -H naud12 -c check_files -a file="c:\\Program Files\\NSClient++\\nsclient.log" "critical=size>100k" "perf-config=size(unit:M)" "detail-syntax=${status}%(file) = %(size)"

Output:
CRITICAL: 0/1 files (nsclient.log = 357446)|'nsclient.log size'=0.34088M;0;0.09765

Code: Select all

Command:
check_nrpe -H naud12 -c check_files -a file="c:\\Program Files\\NSClient++\\nsclient.log" "critical=size>1000k" "perf-config=size(unit:M)" "detail-syntax=${status}%(file) = %(size)"

Output:
OK: All 1 files are ok|'nsclient.log size'=0.34167M;0;0.97656

So now that leaves us with a bug that I have just identified:

When the file matches the critical criteria, it is not reported correctly:

Code: Select all

CRITICAL: 0/1 files (nsclient.log = 357446)|'nsclient.log size'=0.34088M;0;0.09765
It should say 1/1 files.

Rest assured that the CRITICAL state is being correctly returned:

Code: Select all

echo $?
2
I have reported this as a bug on GitHub:
https://github.com/mickem/nscp/issues/124



Let us know if that all makes sense.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
guizalan
Posts: 20
Joined: Mon Mar 16, 2015 3:53 pm

Re: CheckFiles format

Post by guizalan »

Box293,

It was beautiful, worked like a charm. I was breaking my head with CheckFiles, and this worked in the first attempt.

Thanks a lot Box!
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: CheckFiles format

Post by tmcdonald »

I'll be closing this thread now, but feel free to open another if you need anything in the future!
Former Nagios employee
Locked