Linux/Unix scripting in SAM component monitors

The predefined Linux/Unix Script Monitor included in SAM supports custom scripts on Linux-based systems. You can create multiple instances of this component monitor per template to run custom scripts.

For a list of templates that use customized instances of the Linux/Unix Script Monitor, navigate to the Manage Templates page. Click Settings > All Settings > SAM Settings and click Manage Templates. In the search field, enter Linux or Unix to filter the list.

SAM supports using Linux/Unix scripting with Nagios installed and configured on target servers. After configuring Nagios and reviewing the components of a script, create Linux/Unix scripts using the component monitor per template.

This topic details the format and usage of Linux or Unix scripts for SAM, including arguments and output formats. It does not provide information on coding in programming languages such as Perl or Python.

Related topics include:

The SAM forum in the SolarWinds online IT community, THWACK, also provides content about Linux/Unix scripting.

SAM includes sample scripts that you can use to create Linux/Unix script component monitors, as provided in this folder on the Orion server: C:\Program Files (x86)\SolarWinds\Orion\APM\SampleScriptMonitors\LinuxScripts

Linux/Unix script support in SAM


Nagios is installed and configured on target servers.


You need to include credentials that can run scripts on the monitored Linux-based computer.

Python installation

You need to verify your installation of python and python-xml. Depending on your Linux distribution, you may have need to install these libraries. You can verify your Python installed libraries with the following command:

python -c "import sys; from xml.dom.minidom import parseString; print sys.version"

See the Python site for documentation and install commands. The following command typically updates and installs the required Python libraries: apt-get install python

Depending on your Linux distribution, you may need to verify install and configure specific applications and services to use the Linux/Unix Script monitor. For example, to use the Linux/Unix Script monitor with Apache services (as with the Apache template), you need to configure Apache access. For full configuration details for all services, see Linux system configurations for Component Monitors.

How the Linux/Unix script works

The Linux/Unix 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.

    The file saves to the Script Working Directory on the remote server.

  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 Linux/Unix script

SolarWinds recommends writing scripts in the Linux/Unix Script monitor to verify correct access between the main polling engine, SAM, and the target server(s). You can write and test 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 Linux/Unix Script monitor to ensure entered credentials and target server access, and to generate metrics output.

The script in the monitor should include:

  • Parameters to run the script in the Command Line field
  • 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 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.

Script Body field

Use the Script Body field to enter your 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 Python. Depending on the language, you may need to take additional steps for the script and command line to execute.

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 command line parameters used to run the script. Use the format of <scripting language path> ${SCRIPT} such as perl, python, or bash. {SCRIPT} is replaced by the actual file name of the script after it is deployed to the target node. A temporary file is created in temp directory for the script.