File check goes to unknown
-
- Posts: 164
- Joined: Tue Apr 02, 2019 8:38 pm
File check goes to unknown
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?
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?
You do not have the required permissions to view the files attached to this post.
Re: File check goes to unknown
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):
To this (which works on files):
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
Code: Select all
Test-Path $Path -pathType leaf | Out-Null
-
- Posts: 164
- Joined: Tue Apr 02, 2019 8:38 pm
Re: File check goes to unknown
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?
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?
You do not have the required permissions to view the files attached to this post.
Re: File check goes to unknown
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.
-
- Posts: 164
- Joined: Tue Apr 02, 2019 8:38 pm
Re: File check goes to unknown
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.
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
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:
Or:
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"
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"
-
- Posts: 164
- Joined: Tue Apr 02, 2019 8:38 pm
Re: File check goes to unknown
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.
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
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.
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.
Be sure to check out our Knowledgebase for helpful articles and solutions!
-
- Posts: 164
- Joined: Tue Apr 02, 2019 8:38 pm
Re: File check goes to unknown
The shares are mounted by DFS.
Have tried with the latest version of Nsclient as suggested but the output is still the same.
Have tried with the latest version of Nsclient as suggested but the output is still the same.
Re: File check goes to unknown
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.
Other than that, it may be a permission problem. NSClient++ runs as a service account and cannot read the files or folders.
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
Be sure to check out our Knowledgebase for helpful articles and solutions!