As part of the Nagios XI Infrastructure Monitoring solution there is the ability to compile external scripts outside of the monitoring wizard defaults.
In order to run the external scripts, there a number of changes required to be made to the configuration file (C:\Program Files\NSClient++\NSC.ini).
Firstly, we need to enable the NPRE Listener and Check External Scripts by uncommenting the below lines in the [modules] section;
[modules] NRPEListener.dll CheckExternalScripts.dll
Also, in order to invoke external scripts with arguments the allow_arguments parameter is required to be enabled in the [NPRE] section;
[NPRE] allow_arguments=1
In order for the host to query the client TCP service port 5666 is required to be open on the client in order to call the external script using the check_npre executable.
In order to return state information to Nagios the external script should always include a return code, so that Nagios can interpret the state of the service.
Below is a table of how Nagios interprets return codes:
Return Code | Service State |
0 | OK |
1 | Warning |
2 | Critical |
3 | Unknown |
Nagios does not require an actual return string, but this is required to return status information and when used expects a single line return.
In my instance my external scripts are compiled within Windows Powershell in order to return the exit code, the below is required;
exit $returnCode
In order to include the external script, you will be required to copy the file to the default scripts folder ‘C:\Program Files\NSClient++\scripts’.
Now we will need to modify the configuration file (C:\Program Files\NSClient++\NSC.ini) to include the command line to invoke the script add this to the [External Scripts] section;
Below is an example of an external script compiled in Windows Powershell;
<check name>= cmd /c echo scripts\<script filename> <arguments> $ARG1$; exit($lastexitcode) | powershell.exe -command -
As mentioned earlier, generating a return code is required for interpreting the service state, this is returned by using ‘exit($lastexitcode)’.
Below is an example of an external script where the check name is check_volumemountpoints and the script is ‘check_volumemountpoints.ps1’, where a mountpoint argument is required;
check_volumemountpoints= cmd /c echo scripts\check_volumemountpoints.ps1 -mountpoint $ARG1$; exit($lastexitcode) | powershell.exe -command -
Once, the configuration file has been modified and the external script has been included, the NSClient++ service on the client will be required to be restarted.
You can verify external scripts from the Nagios Host by running the following command to invoke the check command against the client;
/usr/local/nagios/libexec/check_nrpe -H <hostname or IP> -c <check name>
For external scripts which require arguments run the above with the -a switch;
/usr/local/nagios/libexec/check_nrpe -H <hostname or IP> -c <check name> -a <arguments>
Once the external script has been configured you will be required to add the check command to the service management in Nagios Core Config Manager.
After much searching this is exactly what I needed. Thanks for your help.
LikeLike
Not a problem, glad to have helped…
LikeLike