Page 1 of 1
Powershell on GUI return out of bounds, cli works OK
Posted: Tue Apr 22, 2025 11:14 am
by sgomeztd
Hi
I'm trying to run a ps1 script on multiple Windows VM. The check is working OK on almost all the VMs but there is a few W2k12 where I'm getting the error "Return code of 5 for service 'Pending Win Updates' on host 'xxxxxxxxxxxx' was out of bounds" when letting the check to run on the schedule or if I press the "force check" but If execute it from the CCM with the button "Run check command" it does work OK.
All these W2k12 have the old 2.4 agent as they cannot run the new v3 agent and this checks is running OK 70% of them. I tried adding some try / catch to the script to ensure it always return a 3 in case of failure but still I'm getting a return code of 5 so I guess that return code must be from the /usr/local/nagios/libexec/check_ncpa.py itself
Re: Powershell on GUI return out of bounds, cli works OK
Posted: Wed Apr 23, 2025 12:23 pm
by gwesterman
Hi @sgomeztd,
Try these and let me know what you get:
1. Run the command from the NCPA server
- Go to https://<server address>:5693 and generate the command through the API
- Run the command directly on the CLI
2. Run the command from the remote server (your XI) directly on the CLI.
Thank you!
Re: Powershell on GUI return out of bounds, cli works OK
Posted: Thu Apr 24, 2025 9:36 am
by sgomeztd
Hi,
I think you didn't get my point. The command is working OK both from the bash shell and with the "Run check command" button on my Nagios XI server but is failing to be executed by the scheduler or if I press the "Force an immediate check" button. On the Nagios XI website as well as on the log /usr/local/nagios/var/nagios.log I see the error "Return code of 5 for service 'Pending Win Updates' on host 'xxxxxxxxxxxx' was out of bounds".
Checking on the vm itself trough the Administrative portal of the NCPA I realized on the API that when executed the powershell it provides there the return code 5
{
"returncode": 5,
"stdout": "OK - pending security updates found: 2"
}
the strange part is that if I execute the script on a powershell windows and then execute $LastExitCode it returns a 0 not a 5. It's how the agent is executing that PowerShell what is giving problems
Re: Powershell on GUI return out of bounds, cli works OK
Posted: Fri Apr 25, 2025 10:48 am
by bbahn
Hello @sgomeztd,
Test the plugin not in your XI instance, but on your NCPA's webpage. https://<your-NCPA-server-ip:5693/api and then choose the desired command and see if you can get it to execute properly. Once you get it right, you can select the Run as Nagios check checkbox and use the button that appears on the bottom left to get the exact command to run on your XI server to get it working. This will ensure that NCPA can run your plugin properly and that the command you're using is formatted correctly for NCPA to interpret.
It's possible that you have some special characters that aren't being handled properly, which could make this still not work. If that's the case, please specify any such characters and what check you're trying to run so that we can file a bug report. If you'd like to file one yourself, you can file one at github.com/nagiosenterprises/ncpa.
Re: Powershell on GUI return out of bounds, cli works OK
Posted: Tue Apr 29, 2025 9:41 am
by sgomeztd
bbahn wrote: ↑Fri Apr 25, 2025 10:48 am
Hello @sgomeztd,
Test the plugin not in your XI instance, but on your NCPA's webpage. https://<your-NCPA-server-ip:5693/api and then choose the desired command and see if you can get it to execute properly. Once you get it right, you can select the
Run as Nagios check checkbox and use the button that appears on the bottom left to get the exact command to run on your XI server to get it working. This will ensure that NCPA can run your plugin properly and that the command you're using is formatted correctly for NCPA to interpret.
It's possible that you have some special characters that aren't being handled properly, which could make this still not work. If that's the case, please specify any such characters and what check you're trying to run so that we can file a bug report. If you'd like to file one yourself, you can file one at github.com/nagiosenterprises/ncpa.