NCPA Return Codes (Ok, Warning, Critical)
Posted: Wed Dec 05, 2018 12:30 pm
Hello,
I recently transitioned from NSClient to NCPA for a custom plugin check. I have a custom powershell plugin that checks a text file for certain errors. The check works but I'm having trouble passing the ARGs to let Nagios XI know what the service state status is when ok, warning, critical. Below is the argument we're passing using check_xi_ncpa and the powershell script:
ARG:
-t 'mytoken' -P 5693 -M 'agent/plugin/check_log_file.ps1' -a 'E:\web\production\cache\scripterrorlog.txt'
Powershell Plugin
param(
[Parameter(Mandatory=$true)][string]$logfile
)
$ok = 0
$warning = 1
$critical = 2
$content = "Out of memory"
$content1 = "Out of string space"
$content2 = "Not enough storage"
$logresult = get-childitem $logfile | select-string $content -quiet
$logresult1 = get-childitem $logfile | select-string $content1 -quiet
$logresult2 = get-childitem $logfile | select-string $content2 -quiet
if (($logresult) -or ($logresult1) -or ($logresult2)){
Clear-Content $logfile
Write-Host "Critical: Content match within the log file"
exit $critical
}
Else {
Write-Host "OK: No content matches"
exit $ok
}
I recently transitioned from NSClient to NCPA for a custom plugin check. I have a custom powershell plugin that checks a text file for certain errors. The check works but I'm having trouble passing the ARGs to let Nagios XI know what the service state status is when ok, warning, critical. Below is the argument we're passing using check_xi_ncpa and the powershell script:
ARG:
-t 'mytoken' -P 5693 -M 'agent/plugin/check_log_file.ps1' -a 'E:\web\production\cache\scripterrorlog.txt'
Powershell Plugin
param(
[Parameter(Mandatory=$true)][string]$logfile
)
$ok = 0
$warning = 1
$critical = 2
$content = "Out of memory"
$content1 = "Out of string space"
$content2 = "Not enough storage"
$logresult = get-childitem $logfile | select-string $content -quiet
$logresult1 = get-childitem $logfile | select-string $content1 -quiet
$logresult2 = get-childitem $logfile | select-string $content2 -quiet
if (($logresult) -or ($logresult1) -or ($logresult2)){
Clear-Content $logfile
Write-Host "Critical: Content match within the log file"
exit $critical
}
Else {
Write-Host "OK: No content matches"
exit $ok
}