Nagios XI - Using Scripts / Plugins With NSClient++ Article Number: 58 Rating: Unrated Last Updated: Wed, Jul 19, 017 at 11:59 PM O ve r vie w This KB article explains how to use external scripts / plugins with NSClient++. NSClient++ has a lot of built in functionality however you will likely run into a situation where you need to use a script to provide additional monitoring capabilities. NSClient++ is capable of executing scripts such as: Batch Script =.bat Visual Basic Script =.vbs PowerShell Script =.ps1 This KB article will provide examples for these three types of scripts as each method is slightly different. Re quir e me nt s This KB article uses NSClient++ version 0.4.x (and future versions) which requires the NRPE module to be enabled (scripts are not possible with check_nt). Please ensure NSClient has been configured correctly as per these KB articles: Documentation - Configuring NSClient++ In addition to these settings, execute the follow commands on your windows server (in a command prompt) to ensure the External Scripts module is correctly loaded: cd "\Program Files\NSClient++\" nscp settings --activate-module CheckExternalScripts --add-defaults nscp settings --path "/settings/external scripts" --key "allow arguments" --set true Ba t c h S c r ipt This example demonstrates how to add a batch script to NSClient++. For this example you are going to create a basic script that takes two arguments. Argument 1 = A number (0, 1,, 3) that will be used as the exit code the script will exit with (this is how Nagios determines the status) Argument = A message that the script will display C re at e Bat c h Sc ript @echo off if [%1] == [] echo No exit code was supplied, aborting! & exit /B 3 if [%] == [] echo No dummy message was supplied, aborting! & exit /B 3 echo %~ exit /B %1% Save the file into C:\Program Files\NSClient++\scripts with the name check_dummy.bat Open a command prompt on your Windows machine and execute the following commands: check_dummy.bat "Something is CRITCAL" C:\Program Files\NSClient++\scripts>check_dummy.bat ""
C:\Program Files\NSClient++\scripts> The output from the second command, the number, is how Nagios will determine that this plugin is reporting a CRITICAL state. check_dummy_bat = scripts\\check_dummy.bat $ARG1$ "$ARG$" Te s t Sc ript Fro m Nagio s /usr/local/nagios/libexec/check_nrpe -H your_windows_server_ip_address -c check_dummy_bat -a "" /usr/local/nagios/libexec/check_nrpe -H your_windows_server_ip_address -c check_dummy_bat -a "" The output from the second command, the number, is how Nagios will determine that this plugin is reporting a CRITICAL state. This completes the example of configuring NSClient++ to use a batch script. You will now need to go and create a service in Nagios XI (this falls outside the scope of this KB article). Vis ua l Ba s ic S c r ipt This example demonstrates how to add a visual basic script (vbs) to NSClient++. For this example you are going to create a script that takes two arguments. Argument 1 = A number (0, 1,, 3) that will be used as the exit code the script will exit with (this is how Nagios determines the status) Argument = A message that the script will display C re at e Vis ual Bas ic Sc ript on error resume next If wscript.arguments.count < 1 Then wscript.echo "No exit code was supplied, aborting!" wscript.quit(3) ElseIf Wscript.Arguments.Count < Then wscript.echo "No dummy message was supplied, aborting!"
wscript.quit(3) End If wscript.echo wscript.arguments.item(1) wscript.quit(wscript.arguments.item(0)) Save the file into C:\Program Files\NSClient++\scripts with the name check_dummy.vbs Open a command prompt on your Windows machine and execute the following commands: cscript.exe //T:30 //NoLogo check_dummy.vbs "Something is CRITCAL" C:\Program Files\NSClient++\scripts>cscript.exe //T:30 //NoLogo check_dummy.vbs "Something is CRITCAL" C:\Program Files\NSClient++\scripts> The output from the second command, the number, is how Nagios will determine that this plugin is reporting a CRITICAL state. You need to execute the check_dummy.vbs script using cscript.exe as if forces the command to run in a command prompt and all output is passed to the command prompt. //T:30 is a timeout of 30 seconds //NoLogo suppresses the Microsoft banner from being displayed check_dummy_vbs = cscript.exe //T:30 //NoLogo scripts\\check_dummy.vbs $ARG1$ "$ARG$" Te s t Sc ript Fro m Nagio s /usr/local/nagios/libexec/check_nrpe -H your_windows_server_ip_address -c check_dummy_vbs -a "" /usr/local/nagios/libexec/check_nrpe -H your_windows_server_ip_address -c check_dummy_vbs -a ""
The output from the second command, the number, is how Nagios will determine that this plugin is reporting a CRITICAL state. This completes the example of configuring NSClient++ to use a visual basic script. You will now need to go and create a service in Nagios XI (this falls outside the scope of this KB article). Po we r S he ll S c r ipt This example demonstrates how to add a PowerShell script to NSClient++. For this example you are going to create a basic script that takes two arguments. Argument 1 = A number (0, 1,, 3) that will be used as the exit code the script will exit with (this is how Nagios determines the status) Argument = A message that the script will display C re at e Powe rshe ll Sc ript if ($args.count -lt 1) { write-host "No exit code was supplied, aborting!"; exit 3 } if ($args.count -lt ) { write-host "No dummy message was supplied, aborting!"; exit 3 } write-host $args[1] exit $args[0] Save the file into C:\Program Files\NSClient++\scripts with the name check_dummy.ps1 Open a command prompt as an a d minis tra to r on your Windows machine and execute the following command: powershell.exe Set-ExecutionPolicy Bypass That command configured PowerShell to run scripts and is re q uire d. Now execute the following commands: powershell.exe -File check_dummy.ps1 "" C:\Program Files\NSClient++\scripts>powershell.exe -File check_dummy.ps1 "" C:\Program Files\NSClient++\scripts> The output from the second command, the number, is how Nagios will determine that this plugin is reporting a CRITICAL state. check_dummy_ps1 = cmd /c echo scripts\\check_dummy.ps1 $ARG1$ "$ARG$"; exit($lastexitcode) powershell.exe -command -
check_dummy_ps1 = cmd /c echo scripts\\check_dummy.ps1 $ARG1$ "$ARG$"; exit($lastexitcode) powershell.exe -command - Te s t Powe rshe ll Sc ript Fro m Nagio s /usr/local/nagios/libexec/check_nrpe -H your_windows_server_ip_address -c check_dummy_ps1 -a "" /usr/local/nagios/libexec/check_nrpe -H your_windows_server_ip_address -c check_dummy_ps1 -a "" The output from the second command, the number, is how Nagios will determine that this plugin is reporting a CRITICAL state. This completes the example of configuring NSClient++ to use a PowerShell script. You will now need to go and create a service in Nagios XI (this falls outside the scope of this KB article). Fina l Tho ught s For any support related questions please visit the Nagios Support Forums at: http://support.nagios.com/forum/ Posted by: tle a - Wed, Jul 7, 016 at 11:15 PM. This article has been viewed 6998 times. Online URL: https://support.nagios.com/kb/article/nagios-xi-using-scripts-plugins-with-nsclient-58.html