ps1 plugin not returning proper exit code

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
User avatar
BanditBBS
Posts: 2474
Joined: Tue May 31, 2011 12:57 pm
Location: Scio, OH
Contact:

ps1 plugin not returning proper exit code

Post by BanditBBS »

So, I converted all my Windows servers over to NCPA, YAY!! I wrote a new plugin using powershell and this is the bottom of the code:

Code: Select all

if ( ( $days -ge $threshold ) ) {
    $returnString = "CRITICAL: " + $days + " since last update"
    $returnState = $returnStateCritical
} else {
	$returnString = "OK: " + $days + " since last update"
    $returnState = $returnStateOK
}

Write-Host $returnString
exit $returnState
No matter what happens though, NCPA is saying it is OK. Example here:
Screenshot 2021-09-21 130624.jpg
I even went on this host, modified the .ps1 to "exit 2" and NCPA still shows the above screenshot.

My Config for ps1 files in NCPA is the default settings. Any idea why this isn't returning the exit code as desired?
You do not have the required permissions to view the files attached to this post.
2 of XI5.6.14 Prod/DR/DEV - Nagios LogServer 2 Nodes
See my projects on the Exchange at BanditBBS - Also check out my Nagios stuff on my personal page at Bandit's Home and at github
User avatar
BanditBBS
Posts: 2474
Joined: Tue May 31, 2011 12:57 pm
Location: Scio, OH
Contact:

Re: ps1 plugin not returning proper exit code

Post by BanditBBS »

After further testing, I believe I narrowed it down to just the remaining 2008 and 2008 R2 hosts we have. 2012 and higher seem to be exiting with the correct exit code!
2 of XI5.6.14 Prod/DR/DEV - Nagios LogServer 2 Nodes
See my projects on the Exchange at BanditBBS - Also check out my Nagios stuff on my personal page at Bandit's Home and at github
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: ps1 plugin not returning proper exit code

Post by ssax »

I just labbed it up on 2008R2 with NCPA 2.3.1 and it's working properly (no service restarted needed when changing the plugin). What version of NCPA is the system running?
User avatar
BanditBBS
Posts: 2474
Joined: Tue May 31, 2011 12:57 pm
Location: Scio, OH
Contact:

Re: ps1 plugin not returning proper exit code

Post by BanditBBS »

2.3.1 on them all. Wonder what on earth could be making it only exit with 0 on my 2008 R2 boxes.
2 of XI5.6.14 Prod/DR/DEV - Nagios LogServer 2 Nodes
See my projects on the Exchange at BanditBBS - Also check out my Nagios stuff on my personal page at Bandit's Home and at github
User avatar
BanditBBS
Posts: 2474
Joined: Tue May 31, 2011 12:57 pm
Location: Scio, OH
Contact:

Re: ps1 plugin not returning proper exit code

Post by BanditBBS »

I found the issue. This script was one I found online, first line was this:

Code: Select all

[CmdletBinding()]
I commented it out and it now works fine on the 2008 hosts. Crazy, but thanks for making me look deeper!
2 of XI5.6.14 Prod/DR/DEV - Nagios LogServer 2 Nodes
See my projects on the Exchange at BanditBBS - Also check out my Nagios stuff on my personal page at Bandit's Home and at github
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: ps1 plugin not returning proper exit code

Post by ssax »

Interesting, thanks for posting the update! Really not sure why that would cause it to fail.
Locked