Page 1 of 2

File check goes to unknown

Posted: Mon Oct 26, 2020 4:04 am
by RebeccaIlene
Hi Team,

We have a custom powershell script which we are using to check for files within a folder.
If the file exists then the output should be OK otherwise the output should be critical.

When I run the check from powershell it shows the correct output but when this is called using NRPE it is returning the following error.

UNKNOWN: '\\folder.lan\CALIBRE\UNITPRICE\calibre.txt' is not a folder or cannot be accessed. Access is denied

PS C:\Program Files\NSClient\scripts> .\check_file.ps1 -Path "\\folder.lan\CALIBRE\UNITPRICE\calibre.txt" -Time 1 -crit 0
Critical: 0 files found - .|found_files=0;0;0;

Attached is the script used.

The command defined is as follows:

check_file_CALIBRE_UNITPRICE=check_file.ps1 -Path "\\folder.lan\CALIBRE\UNITPRICE\calibre.txt" -Time 1 -crit 0

When I add a * to "calibre.txt" as "calibre*.txt" then the output does not go to unknown.

However, the file name won't vary and does not need a wildcard in its name.

Can you please suggest how this can be fixed?

Re: File check goes to unknown

Posted: Mon Oct 26, 2020 5:00 pm
by ssax
Please attach your nsclient.ini file.

Do you see any error messages in your nsclient.log file?

Try changing this plugin code (which works on directories only):

Code: Select all

Test-Path $Path -pathType container | Out-Null
To this (which works on files):

Code: Select all

Test-Path $Path -pathType leaf | Out-Null

Re: File check goes to unknown

Posted: Wed Oct 28, 2020 4:45 am
by RebeccaIlene
Thanks Sean.

Have tried updating the script but that did not help. It throws the same error.

Please find attached the ini file we are using for this.

Also, where can I find the nsclient.log file?

Re: File check goes to unknown

Posted: Wed Oct 28, 2020 5:30 pm
by ssax
Does \\folder.lan\CALIBRE require a user/password to connect to it or does it allow anonymous access? The local system account that nsclient++ runs as may not have access to it. If it requires a domain user you could technically run the service as a domain user and it should work.

Re: File check goes to unknown

Posted: Mon Nov 02, 2020 9:37 pm
by RebeccaIlene
No the folder does not require a password to open.
The setup is same for all file checks but the issue is observed only with this file check as it does not have a wildcard name.

Re: File check goes to unknown

Posted: Tue Nov 03, 2020 2:14 pm
by ssax
I'm struggling to get this to work on mine as well, must be something in nsclient++ that doesn't like it running like that. It runs fine from powershell directly as you found.

What version of NSClient++ are you using? You should be able to do this with the built-in check_files:

Code: Select all

/usr/local/nagios/libexec/check_nrpe -2 -H X.X.X.X -c check_files -a path='\\folder.lan\CALIBRE\UNITPRICE\' 'pattern=calibre.txt' 'filter=age gt -1h' 'critical=count=0' 'empty-state=critical' "empty-syntax=CRITICAL - No files found"
Or:

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H X.X.X.X -c check_files -a path='\\folder.lan\CALIBRE\UNITPRICE\' 'pattern=calibre.txt' 'filter=age gt -1h' 'critical=count=0' 'empty-state=critical' "empty-syntax=CRITICAL - No files found"

Re: File check goes to unknown

Posted: Tue Nov 24, 2020 10:46 pm
by RebeccaIlene
The check_files command does not work for these shares are hosted by an application and not on a VM or physical server.

There was another problem that we came across with this, the powershell gives the correct output when the file exist in the path but when I call this from Nagios it throws critical.

Output on powershell:

PS C:\Program Files\NSClient++\scripts> .\check_file.ps1 -Path "\\folder.lan\Apps\Uat\*.CSV" -Time 6000 -crit 0
Ok: 2 files found - 8172_1_20201124104257.CSV 8170_1_20201124093016.CSV.|found_files=2;0;0;
PS C:\Program Files\NSClient++\scripts>

Output on Nagios command line:

[root@hostname libexec]# ./check_nrpe -H $hostname$ -t 120 -c check_file_Apps_UAT
Critical: 0 files found - .|found_files=0;0;0;

command defined in nsc file:

nsc_custom file command definition:

check_file_Apps_UAT=check_file.ps1 -Path "\\folder.lan\Apps\Uat\*.CSV" -Time 6000 -crit 0

What could be causing this?

The version of NRPE we are using is 0.3.8.76.

Re: File check goes to unknown

Posted: Wed Nov 25, 2020 6:06 pm
by tgriep
First thing is to update to a newer version of NSClient++ as that one is very old and it may be a bug.

How does the application mount the shares on the Windows server?
Does some one need to be logged in to the Windows server for the shares to be mounted or doe the application run at boot time and then mount them?

The NSClient++ agent runs as a service account, see about having it run as an admin account to see if that fixes the issue.
The first post it looks like it is a permission problem.

Re: File check goes to unknown

Posted: Thu Nov 26, 2020 11:58 am
by RebeccaIlene
The shares are mounted by DFS.

Have tried with the latest version of Nsclient as suggested but the output is still the same.

Re: File check goes to unknown

Posted: Mon Nov 30, 2020 10:44 am
by tgriep
It could be that NSClient++ is escaping the * in the file name causing the path to not work.

Try using single quotes around the path like the following.

Code: Select all

check_file_CALIBRE_UNITPRICE=check_file.ps1 -Path '\\folder.lan\CALIBRE\UNITPRICE\calibre*.txt' -Time 1 -crit 0
check_file_CASHFLOW=check_file.ps1 -Path '\\folder.lan\SONATA\CASHFLOW\gl47*.dat' -Time 1 -warn 3 -crit 5
check_file_BNPP_CASHFLOW=check_file.ps1 -Path '\\folder.lan\BNPP\CASHFLOW\*_CASHFLOW_*.CSV' -Time 15 -crit 0
check_file_BNPP_UNITPRICE=check_file.ps1 -Path '\\folder.lan\BNPP\UNITPRICE\*_UnitsOnIssue_*.txt.REJECTED' -Time 30 -crit 1
check_file_BNPP_UNITSONISSUE=check_file.ps1 -Path '\\folder.lan\BNPP\UNITSONISSUE\*_UNITSONISSUE_*.CSV' -Time 15 -crit 0
Other than that, it may be a permission problem. NSClient++ runs as a service account and cannot read the files or folders.