Page 1 of 1

NCPA Return Codes (Ok, Warning, Critical)

Posted: Wed Dec 05, 2018 12:30 pm
by FrontlineIT
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
}

Re: NCPA Passing Service state ARGs

Posted: Wed Dec 05, 2018 12:35 pm
by FrontlineIT
Attached is an example of the issue.

Re: NCPA Return Codes (Ok, Warning, Critical)

Posted: Wed Dec 05, 2018 1:31 pm
by npolovenko
@FrontlineIT, Please manually execute the PowerShell script from the PowerShell terminal and then run the following command to check the exit code:
echo %errorlevel%
Next, run the remote ncpa command from the Nagios terminal and then the following:
echo $?