Service returns OK status even when failing to run

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
jhesington
Posts: 2
Joined: Tue Sep 18, 2018 1:21 pm

Service returns OK status even when failing to run

Post by jhesington »

We have a service that runs a Powershell script on the Windows server it is assigned to. The service runs fine and it checks if a server is pending a reboot for windows updates. Nagios can trigger the script fine and gets a correct return if there is a pending reboot or not. If there is then the status is a warning and if not then it is ok.
The issue is if the service cannot trigger the script for some reason then it still returns ok. So if the script is not in the servers scripts folder the service will return with an error like it cannot find the script but the status is OK. Or if powershell execution policy is not set to remotesigned then it will give an error but again the status is OK. This is an issue because we may not catch right away that this service is not running properly.

This is not an issue with the script since these two error examples occur without even running the script. What in the nagios service or strategy for running do we need to adjust?

The service has the command set to: $USER1$/check_nrpe -H $HOSTADDRESS$ -t 30 -c pending_reboot -a $ARG1$ $ARG2$
and $ARG1$ is set to "2 1" but I dont know what that is for.
In our servers nsclient.ini file we have the line: pending_reboot = cmd /c echo scripts\pending_reboot.ps1 $ARG1$ $ARG2$; exit $LastExitCode | powershell.exe -command -

I did not originally set this up but we have been using this for a while and would be nice to clean up this issue. if you have any suggestions i would appreciate it.
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: Service returns OK status even when failing to run

Post by benjaminsmith »

Hi,

Take a look a the following thread to create a wrapper script to exit with a different condition as PowerShell will default to the ok status.

Powershell exiting OK even with errors?

Let me know if you're able to get it working or if you have any questions.

Benjamin
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
jhesington
Posts: 2
Joined: Tue Sep 18, 2018 1:21 pm

Re: Service returns OK status even when failing to run

Post by jhesington »

Thank you very much. I did some quick testing and adding the try and catch to the nsclient.ini line did allow it to kick back an error. Ill have to deploy an updated ini to all my clients after I do some more testing.
Here is the line i used:
pending_reboot = cmd /c echo Try {scripts\test\pending_reboot.ps1 $ARG1$ $ARG2$; exit ($lastexitcode)} Catch {echo "Error Running Script"; exit 3} | powershell.exe -command -

Thank you very much for the help!
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: Service returns OK status even when failing to run

Post by benjaminsmith »

Hi @jhesington,

Great! Glad to hear that is working for you.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked