Hello,
We're getting an error/Warning message in Nagios XI when executing a custom plugin within NCPA. The plugin/powershell script works fine. We were using it on nsclient with no issues. We recently changed the check over to NCPA. When testing the check, we're getting the warning - C:\Program Files (x86)\Nagios\NCPA\plugins\check_file_age.ps1 : Cannot process
argument transformation on parameter 'minutes'. Cannot convert value "120$" to
type "System.Int32". Error: "Input string was not in a correct format."
+ CategoryInfo : InvalidData: (:) [check_file_age.ps1], ParentCon
tainsErrorRecordException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,check_file_
age.ps1
When using the run check command, we getting the
[[email protected] ~]$ /usr/local/nagios/libexec/check_ncpa.py -H ******* -t '*******' -M 'plugins/check_file_age.ps1' -q 'args=\\******\Backup_K\ABSPRD\*********$*********\******\LOG\,args=120'
OK - Most recent file was touched 10/4/2021 1:40:15 PM
It's working, but but Still is showing up as Warning
NCPA Receiving error Plugin
-
FrontlineIT
- Posts: 94
- Joined: Tue Jul 26, 2016 8:46 am
NCPA Receiving error Plugin
You do not have the required permissions to view the files attached to this post.
Re: NCPA Receiving error Plugin
Hi,
Can you try changing from this:
/usr/local/nagios/libexec/check_ncpa.py -H ******* -t '*******' -M 'plugins/check_file_age.ps1' -q 'args=\\******\Backup_K\ABSPRD\*********$*********\******\LOG\,args=120'
to
/usr/local/nagios/libexec/check_ncpa.py -H ******* -t '*******' -M 'plugins/check_file_age.ps1' -q 'args=\\******\Backup_K\ABSPRD\*********$*********\******\LOG\,120'
If that doesn't work please send me the check_file_age.ps1 script.
Thanks
Can you try changing from this:
/usr/local/nagios/libexec/check_ncpa.py -H ******* -t '*******' -M 'plugins/check_file_age.ps1' -q 'args=\\******\Backup_K\ABSPRD\*********$*********\******\LOG\,args=120'
to
/usr/local/nagios/libexec/check_ncpa.py -H ******* -t '*******' -M 'plugins/check_file_age.ps1' -q 'args=\\******\Backup_K\ABSPRD\*********$*********\******\LOG\,120'
If that doesn't work please send me the check_file_age.ps1 script.
Thanks
-
FrontlineIT
- Posts: 94
- Joined: Tue Jul 26, 2016 8:46 am
Re: NCPA Receiving error Plugin
Hello, this time, we got an unknown message when we took out the args=
[********** ~]$ /usr/local/nagios/libexec/check_ncpa.py -H ***** -t '******' -M 'plugins/check_file_age.ps1' -q 'args=\\********\Backup_K\ABSPRD\********$*********\AesopStats\LOG\,120'
UNKNOWN: Error occurred while running the plugin. Use the verbose flag for more details.
This is the check_file_age.ps1 script
param(
[Parameter(Mandatory=$true)][string]$directory,
[Parameter(Mandatory=$true)][int]$minutes
)
$ok = 0
$warning = 1
$critical = 2
$latest = Get-ChildItem -Path $directory | Sort-Object LastWriteTime -Descending | Select-Object -First 1
$timespan = New-TimeSpan -Days 0 -Hours 0 -Minutes $minutes
if (((Get-Date) - $latest.LastWriteTime) -gt $timespan) {
# older
Write-Host Critical - Most recent file was touched $latest.LastWriteTime
exit $critical
} else {
# newer
Write-Host OK - Most recent file was touched $latest.LastWriteTime
exit $ok
}
[********** ~]$ /usr/local/nagios/libexec/check_ncpa.py -H ***** -t '******' -M 'plugins/check_file_age.ps1' -q 'args=\\********\Backup_K\ABSPRD\********$*********\AesopStats\LOG\,120'
UNKNOWN: Error occurred while running the plugin. Use the verbose flag for more details.
This is the check_file_age.ps1 script
param(
[Parameter(Mandatory=$true)][string]$directory,
[Parameter(Mandatory=$true)][int]$minutes
)
$ok = 0
$warning = 1
$critical = 2
$latest = Get-ChildItem -Path $directory | Sort-Object LastWriteTime -Descending | Select-Object -First 1
$timespan = New-TimeSpan -Days 0 -Hours 0 -Minutes $minutes
if (((Get-Date) - $latest.LastWriteTime) -gt $timespan) {
# older
Write-Host Critical - Most recent file was touched $latest.LastWriteTime
exit $critical
} else {
# newer
Write-Host OK - Most recent file was touched $latest.LastWriteTime
exit $ok
}
You do not have the required permissions to view the files attached to this post.
Re: NCPA Receiving error Plugin
Hi
OK, the args=120 is correct.
What is happening is the powershell script returns an exitcode of 2 if the file is older than 120 minutes,
and an exitcode of 0 if the file is younger than 20 minutes:
The return codes Nagios recognizes are:
0 for OK
1 for Warning
2 for Critical
3 for Unknown
Does that help?
Thanks
OK, the args=120 is correct.
What is happening is the powershell script returns an exitcode of 2 if the file is older than 120 minutes,
and an exitcode of 0 if the file is younger than 20 minutes:
Code: Select all
[root@gs-cent7-23-94 ~]# /usr/local/nagios/libexec/check_ncpa.py -H 192.168.23.87 -t gjstoken -M 'plugins/check_file_age.ps1' -q 'args=c:\temp,args=120'
Critical - Most recent file was touched 8/16/2021 2:22:20 PM
[root@gs-cent7-23-94 ~]# /usr/local/nagios/libexec/check_ncpa.py -H 192.168.23.87 -t gjstoken -M 'plugins/check_file_age.ps1' -q 'args=c:\temp,args=120'
OK - Most recent file was touched 10/7/2021 2:54:41 PM0 for OK
1 for Warning
2 for Critical
3 for Unknown
Does that help?
Thanks