Page 1 of 2

File Monitoring via nrpe (windows)

Posted: Fri Jan 18, 2019 8:24 am
by nms
Hi all,

I have a folder in which files are placed on a daily basis, usually early morning.

I am trying to monitor if the last file has been placed in the past 24 hrs, i.e. if older then 24 hrs I raise an alert.
I am using the check_nrpe for this using the check_files script.

The format I'm trying to use is:

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H am1-sha-app01-p_w-billing -t 30 -c check_files -a path="D:\\WS06\\CdrProcessing\\Reports\\VFI\\BalanceReportsFrom_eServ\\POSTFONE\\Sent\\" 'filter= written > -24h' 'warn= count > 0' 'empty-state=warning' 'empty-syntax=${status}: Last MVNOAccountBalance File is older then 24Hrs'
But if a file is not placed (or I remove the last file for testing) I still get an ok.

Am I using the correct format for monitoring a file? The files placed are in CSV format as per attached.

Rgds

Re: File Monitoring via nrpe (windows)

Posted: Fri Jan 18, 2019 8:40 am
by Francesco
Ciao,
can you show us the nrpe.cfg of the windows server?

Di you try to execute the plugin locally on the remote server, in a dos window?

Ciao,

Re: File Monitoring via nrpe (windows)

Posted: Fri Jan 18, 2019 11:27 am
by lmiltchev
Trying using 'filter= creation', and changing 'warn= count > 0' to 'warn= count = 0'.

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H am1-sha-app01-p_w-billing -t 30 -c check_files -a path="D:\\WS06\\CdrProcessing\\Reports\\VFI\\BalanceReportsFrom_eServ\\POSTFONE\\Sent\\" 'filter= creation > -24h' 'warn= count = 0' 'empty-state=warning' 'empty-syntax=${status}: Last MVNOAccountBalance File is older then 24Hrs'
Now, you should get "OK" state if there is a newer than 24 hours file in the folder. If there is no new file, you would get a "WARNING".

Re: File Monitoring via nrpe (windows)

Posted: Mon Jan 21, 2019 3:45 am
by nms
Hi,

I tried to the filter from written to creation.

Code: Select all

[nagios@am1nms-nagiosxi ~]$ /usr/local/nagios/libexec/check_nrpe -H am1-sha-app01-p_w-billing -t 30 -c check_files -a path="D:\\WS06\\CdrProcessing\\Reports\\VFI\\BalanceReportsFrom_eServ\\POSTFONE\\Sent\\" 'filter= creation > -24h' 'warn= count = 0' 'empty-state=warning' 'empty-syntax=${status}: Last MVNOAccountBalance File is older then 24Hrs' 
WARNING: Last MVNOAccountBalance File is older then 24Hrs|'count'=0;0;0
However, I still encounter the same problem. For this case, I think the count = 0 will make sense since that there were no files > 24hrs. so in that case hat should be count =0 -> OK.
But in any case when I removed a file to test the count was still 0.

Rgds,

Re: File Monitoring via nrpe (windows)

Posted: Mon Jan 21, 2019 12:05 pm
by scottwilkerson
What this is doing is counting the files that were create within the last 24 hours, and then warns if there are not any files that have been created in the last 24 hours.

Is this not what you were trying to achieve?
nms wrote:I am trying to monitor if the last file has been placed in the past 24 hrs, i.e. if older then 24 hrs I raise an alert.
I am using the check_nrpe for this using the check_files script.

Re: File Monitoring via nrpe (windows)

Posted: Mon Jan 21, 2019 1:02 pm
by nms
Hi,

May I'm not getting it right. Assume we have these files (see attached) which are being created daily. As you can see the last is created which means less than 24 hrs. So this means that there should be no alarm and the count should be 1, not 0.

If I run the command with those files in place I get:

Code: Select all

[nagios@am1nms-nagiosxi ~]$ /usr/local/nagios/libexec/check_nrpe -H am1-sha-app01-p_w-billing -t 30 -c check_files -a path="D:\\WS06\\CdrProcessing\\Reports\\VFI\\BalanceReportsFrom_eServ\\POSTFONE\\Sent\\" 'filter= creation > -24h' 'warn= count =0' 'empty-state=warning' 'empty-syntax=${status}: Last MVNOAccountBalance File is older then 24Hrs' 
WARNING: Last MVNOAccountBalance File is older then 24Hrs|'count'=0;0;0
I am getting a warning, of course since the count is 0. However, that should not be the case since the last file is created less than 24 hours ago?

What I am trying to achieve is to raise an alert if this particular last file time is older then 24hrs.

Rgds

Re: File Monitoring via nrpe (windows)

Posted: Mon Jan 21, 2019 1:48 pm
by scottwilkerson
Hmm, we may need to change creation to written, lets try the following:

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H am1-sha-app01-p_w-billing -t 30 -c check_files -a path="D:\\WS06\\CdrProcessing\\Reports\\VFI\\BalanceReportsFrom_eServ\\POSTFONE\\Sent\\" 'filter= written > -24h' 'warn= count =0' 'empty-state=warning' 'empty-syntax=${status}: Last MVNOAccountBalance File is older then 24Hrs'

Re: File Monitoring via nrpe (windows)

Posted: Tue Jan 22, 2019 10:06 am
by nms
Hi Scott,

I have changed the filter to written and tried out 2 tests.

in the first test, the last file placed in the directory was less than 24 hrs, so when we run

Code: Select all

[nagios@am1nms-nagiosxi ~]$ /usr/local/nagios/libexec/check_nrpe -H am1-sha-app01-p_w-billing -t 30 -c check_files -a path="D:\\WS06\\CdrProcessing\\Reports\\VFI\\BalanceReportsFrom_eServ\\POSTFONE\\Sent\\" 'filter= written > -24h' 'warn= count =0' 'empty-state=warning' 'empty-syntax=${status}: Last MVNOAccountBalance File is older then 24Hrs' 
WARNING: Last MVNOAccountBalance File is older then 24Hrs|'count'=0;0;0
The answer is correct since we have a count =0, The warning, of course, is there since the empty-state=warning .. I think!

For the second test, I removed the last file, which means the last file which I have is now older than 24hrs.
Running the same command produces the same result, the count remains 0.
if I'm getting it right, the count should have been greater than 0 now.

maybe the folder "path="D:\\WS06\\CdrProcessing\\Reports\\VFI\\BalanceReportsFrom_eServ\\POSTFONE\\Sent\\" " should be changes to specify the filenames? Maybe it's looking for the modification time of the directory, and hence that's why the 2nmd test fails?

can you specify a file name or regex in the filter?

Rgds,

Re: File Monitoring via nrpe (windows)

Posted: Tue Jan 22, 2019 4:21 pm
by ssax
Works on mine with NSClient++ v 0.5.2035:

One new file:

Code: Select all

[root@xid nagiosxi]# /usr/local/nagios/libexec/check_nrpe -H 192.168.5.232 -t 30 -c check_files -a path="C:\\WS06\\CdrProcessing\\Reports\\VFI\\BalanceReportsFrom_eServ\\POSTFONE\\Sent\\" 'filter= written > -24h' 'warn= count =0' 'empty-state=warning' 'empty-syntax=${status}: Last MVNOAccountBalance File is older then 24Hrs'
OK: All 1 files are ok|'count'=1;0;0
No files:

Code: Select all

[root@xid nagiosxi]# /usr/local/nagios/libexec/check_nrpe -H 192.168.5.232 -t 30 -c check_files -a path="C:\\WS06\\CdrProcessing\\Reports\\VFI\\BalanceReportsFrom_eServ\\POSTFONE\\Sent\\" 'filter= written > -24h' 'warn= count =0' 'empty-state=warning' 'empty-syntax=${status}: Last MVNOAccountBalance File is older then 24Hrs'
WARNING: Last MVNOAccountBalance File is older then 24Hrs|'count'=0;0;0
Old file:

Code: Select all

[root@xid nagiosxi]# /usr/local/nagios/libexec/check_nrpe -H 192.168.5.232 -t 30 -c check_files -a path="C:\\WS06\\CdrProcessing\\Reports\\VFI\\BalanceReportsFrom_eServ\\POSTFONE\\Sent\\" 'filter= written > -24h' 'warn= count =0' 'empty-state=warning' 'empty-syntax=${status}: Last MVNOAccountBalance File is older then 24Hrs'
WARNING: Last MVNOAccountBalance File is older then 24Hrs|'count'=0;0;0

Re: File Monitoring via nrpe (windows)

Posted: Tue Jan 22, 2019 4:32 pm
by lmiltchev
We tried a similar setup in house, and everything seems to be working as expected. Here's what I did:

1. I had two CSV files in C:\TEMP directory
example01.PNG
2. Here's the output of the command I ran from the CLI:

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H x.x.x.x -c check_files -a path="C:\\TEMP\\" 'filter= written > -24h' 'warn= count = 0' 'empty-state=warning' 'empty-syntax=${status}: My CSV File is older then 24Hrs'
WARNING: My CSV File is older then 24Hrs|'count'=0;0;0
I got a WARNING as both files were older than 24 hours.

3. I modified one of the files, and made sure the timestamp changed.
example02.PNG
4. I reran my command:

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H x.x.x.x -c check_files -a path="C:\\TEMP\\" 'filter= written > -24h' 'warn= count = 0' 'empty-state=warning' 'empty-syntax=${status}: My CSV File is older then 24Hrs'
OK: All 1 files are ok|'count'=1;0;0
I got an OK as one for the files were newer than 24 hours.

5. I copied a few new files to the C:\TEMP folder, and ran the check again:
example03.PNG
/usr/local/nagios/libexec/check_nrpe -H x.x.x.x -c check_files -a path="C:\\TEMP\\" 'filter= written > -24h' 'warn= count = 0' 'empty-state=warning' 'empty-syntax=${status}: My CSV File is older then 24Hrs'
OK: All 4 files are ok|'count'=4;0;0
The output was OK as there were files in the TEMP folder, newer than 24 hours. It said: "4 files" as there was one "modified" file, and 3 "new" files in the folder.

6. I removed the 4 "new" files, and the output changed to WARNING again (as the only file that was left was older than 24 hours).

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H x.x.x.x -c check_files -a path="C:\\TEMP\\" 'filter= written > -24h' 'warn= count = 0' 'empty-state=warning' 'empty-syntax=${status}: My CSV File is older then 24Hrs'
WARNING: My CSV File is older then 24Hrs|'count'=0;0;0
I am not sure if you are doing something else. It would help us if you actually showed screenshots of the timestamps of your files at the time you test your command from the CLI.
can you specify a file name or regex in the filter?
You could use something like this:

Code: Select all

pattern=*.txt
https://docs.nsclient.org/0.5.0/referen ... heck_files