Submit a ticketCall us

Training ClassThe Orion® Platform Instructor-led Classes

Provided by SolarWinds® Academy, these trainings will introduce users to the Orion Platform and its features, management, and navigation. These courses are suitable for users looking to discover new tips, tricks, and ways to adapt their Orion products to better suit their monitoring needs:
Deploying the Orion Platform
Configuring Orion views, maps, and accounts
Configuring Orion alerts and reports

Reserve your seat.

Home > Success Center > Server & Application Monitor (SAM) > SAM Documentation > SAM Custom Template Guide > Nagios scripting in SAM custom templates

Nagios scripting in SAM custom templates

The SAM Nagios Script monitor supports custom Nagios scripting on Linux-based systems. You can create multiple instances of this component monitor per template to run custom Nagios scripts.

This information details the format and usage of Nagios scripts for SAM, including script arguments and output formats. This information does not provide information on coding in Nagios. For resources to learn or use the Nagios programming language, see Nagios resources. SAM does support using Nagios plugins.

After configuring Nagios and reviewing the components of a script, create Nagios scripts using the component monitor per template.

Nagios support in SAM

SAM supports using Nagios scripting with Nagios installed and configured on target servers.

To locate a list of out-of-the-box Nagios script supporting templates, navigate to the Manage Templates page. Click Settings > All Settings > SAM Settings and click Manage Templates. In the search field, enter Nagios to filter the list. These templates use customized instances of the Nagios Script Monitor.



To process scripts, you must include credentials with permissions to run scripts on the monitored Linux-based computer.

Nagios polled by Orion agent for Linux

If you are using this component monitor with Nagios and polled by Orion agent for Linux, you need to enter a script as follows. The argument would be python $(SCRIPT) with a body of:

from random import randint
for stat_id in range(STAT_PAIRS_COUNT):
	print 'Statistic.random%d: %d\nMessage.random%d: %s' % (stat_id, randint(1,100), stat_id, 'random number: ' + str(randint(1,100)))

How the Nagios script works

The Nagios script monitor executes the script remotely using the target server you provide then reports the metrics:

  1. Connects to the target server using SSH.
  2. Executes the script using the command line value.

    The script executes on the target system, not the Orion server. You may need to enter additional parameters to satisfy the hostname and credentials needed to execute.

  3. Captures metrics and returns the data to the monitor.
  4. Closes the SSH connection.
  5. SAM parses the text output, saves data, and reports the values using the output formats from the component monitor.

Components of a Nagios script

SolarWinds recommends writing scripts in the Nagios Script monitor to verify correct access between the main polling engine, SAM, and the target server(s). You can write and test Nagios scripts in your preferred ISE, connecting and testing against the target server to verify if the code functions. You must test the script through the Nagios Script monitor to ensure entered credentials and target server access, and to generate metrics output.

The script in the monitor should include:

  • Nagios parameters to run the script in the Command Line field
  • Nagios script code added in the Script Body field with credentials
  • Exit codes to report status in the script
  • Formatted output after running the script

You must test the component monitor and script before assigning and using the component monitor within a template as is. Testing the script generates the required database tables for metrics output and verifies output processes.

Script Fields

Script Working Directory field

Enter a working directory where the script processes when executed. This is a directory located on the target system. A popular directory is /tmp.

If using a compiled binary file (ELF) script, leave this field blank.

Script Body field

Use the Script Body field to enter your Nagios script code. You can write and compile the script in a language you prefer then copy and paste the code into this field. For example, customers have used Perl, Python, and compiled binary file (ELF). Depending on the language, you may need to take additional steps for the script and command line to execute.

If you used compiled Nagios plugins, leave this field empty.

If using a compiled binary file (ELF) script, enter a character in the field. It will not be used when executed.

Scripts must report their status by exiting with the appropriate exit code. The exit code is used to report the status of the monitor, displayed in the Orion Web Console.

Command Line field

Enter your Nagios parameters used to run the script.

The data you enter may also require additional information depending on the code compiler:

  • For Perl and Python, enter the command line required to run the script including all parameters. Start the command with perl for Perl and bash for Python.
  • For compiled binary file (ELF), enter the full path to the script and all parameters.

Use Nagios plugins and compiled binary files

SAM supports using compiled Nagios Plugins found through the Nagios site and compiled binary files (ELF) used on Linux-based computers.

For Nagios plugins:

  • The plugin needs to be installed on the target system. SAM does not transfer the plugins to the server.
  • When configuring the Nagios Script monitor, leave the script body field empty.
  • For the Command Line field, enter a path location on the remote file system for the plugin location and any required parameters.
  • Nagios plugins typically require the hostname. You may need to enter a parameter -H with the hostname. You can assign and use a variable to provide the hostname by using ${IP} or %{Node.DNS} in the script.

For compiled binary files:

  • Transfer the script to the target system.
  • Leave the Script Working Directory blank.
  • Enter any character in the Script Body. The field cannot be empty but is not used when executing the script.
  • For the Command Line field, enter the full path to the script located on the target system and all Nagios parameters.
Last modified