Documentation forServer & Application Monitor
Monitoring your applications and environment is a key capability of SolarWinds Observability Self-Hosted (formerly Hybrid Cloud Observability) and is available in the Essentials edition. Server & Application Monitor (SAM) is also available in a standalone module.

Linux/Unix Script Monitor

This SAM component monitor uses SSH to upload a script to a target Linux/Unix system, run the script, process the return values and text output, and then displays results in the SolarWinds Platform Web Console.

You can use the Linux/Unix Script Monitor to run custom scripts on Linux/Unix systems by either using it in an existing, out-of-the-box application monitor template, or adding it to a custom template. When the template is ready, test it, and then assign it to target nodes to begin monitoring.

This topic includes the following sections:

To learn more, see:

Sample scripts are located on the SolarWinds Platform server, at
C:\Program Files (x86)\SolarWinds\Orion\APM\SampleScriptMonitors\LinuxScripts

(Recommended) For scripts with Nagios formats, use the Nagios Script Monitor instead.

Statistic

The statistic for this component monitor is the value returned by the script. This component monitor can return multiple results and process the output.

A maximum of 10 output pairs can be returned. If you exceed the maximum allowed, remove the excess output pairs or they will be ignored. See Write scripts for SAM script monitors.

Prerequisites

Verify your python and python-xml installation. Depending on the Linux distribution, you may need to install additional libraries.

  • To check installed libraries, run the following command:
    python -c "import sys; from xml.dom.minidom import parseString; print sys.version"
  • To update required Python libraries, run:
    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 it with the Apache template, you need to configure Apache access. For details, see Configure Linux/Unix systems for monitoring by the SolarWinds Platform agent.

Credentials

Include credentials that can run scripts on the monitored Linux-based computer.

Field descriptions

Description

A default description of the monitor. To override the default description, add to or replace existing text. Changes are automatically saved. The variable to access this field is ${UserDescription}.

Customize descriptions to specify what will be monitored so related alerts and notifications are more meaningful later.

Enable Component

Determines if the component is enabled. Disabling the component leaves it in the application in a deactivated state not influencing either SolarWinds SAM application availability or status.

Authentication Type

Choose either User name and Password, or User name and Private Key. The second option allows you to use certificates for authentication.

Credential for Monitoring

Select a credential from the list provided or use the <Inherit credential from node> option. If the credential you need is not in the credentials list, add it in the SAM Credentials Library.

When providing credentials, make sure that the account:

  • Can access the target Linux/Unix system over SSH.
  • Has sufficient rights to run scripts.
  • Exists on the system receiving the executed script.

If you do not enter credentials or use the Inherit option, the monitor uses using SolarWinds Platform agent credentials (SWIAgent) to execute the script and those may not have the necessary elevated permissions. For details, see Credentials and privileges used on Linux/Unix-based computers.

Port Number

Specify the port number used for the SSH connection. The default value is 22.

Script Working Directory

Enter a working directory on the target system where the script processes when executed. The default directory is /tmp.

Count Statistic as Difference

Set the statistic to be the difference in query values between polling cycles.

Command Line

Specify the shell command run after the SSH connection is established. The default command line value perl ${SCRIPT} arg1 arg2 attempts to run in a Perl interpreter the script defined in the Script Body field using the parameters arg1 arg2.

The Command Line field is limited to 266 characters, minus the length of the ${SCRIPT} variable after being resolved to a file name such as APM_937467589.pl. The typical length of the file name is around 16 characters, so the actual user Command Line input should be less than 266 – 16, or about 250 characters (not including the length of the 9 characters for the “${SCRIPT}” variable itself).

To pass a longer command line to a target node (for example, a Solaris system), create a shell script on the target node (for example, myscript.sh) that contains the long command line, and place the call to this script in the Command Line field (for example, /opt/sw/myscript.sh).

Script Body

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, some customer use Python. Depending on the language, you may need add 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, as displayed in the SolarWinds Platform Web Console. For details, see Report status through exit codes in SAM script monitors.

Script Output

Specify how to display returned output in the SolarWinds Platform Web Console. You can also define Warning and thresholds.

Status Roll-Up

Specify how you want the monitor to report status, based on script output. The default is “Show worst status.”

User Notes

Add notes for easy reference. To access this field, use the ${UserNotes} variable.

Linux/Unix Script Monitor example

The following example shows how to adapt an existing Perl script for use as a Linux/Unix Script component monitor in a new template.

New to Linux/Unix scripts? Review Linux/Unix scripting in SAM component monitors.

To adapt an existing Perl script for use in SAM:

  1. Click Settings > All Settings > SAM Settings > Create a new template, and then name the template
  2. Click Add Component Monitor, expand the Custom Component Monitors group, and then select Linux/Unix Script Monitor.
  3. Click Submit then select credentials with SSH permissions in the Credential for Monitoring field.
  4. Provide a valid working directory in the Script Working Directory field
  5. Click Edit to open the script dialog and enter your script into the Script Body field.
  6. Type the Linux command that runs the script in the Command Line field. It should be similar to the following: perl ${SCRIPT} arg1 arg2.

    {SCRIPT} is replaced by the actual file name of the script after it’s deployed to the target node. A temporary file is created in temp directory for the script.

  7. Click Get Script Output. SAM then tests the script by executing it and parse its output, then return the values.
  8. Click Save, then specify the critical and warning thresholds and click Submit.

This sample Perl script uses the Linux/Unix component monitor and returns two output pairs:

#!/usr/bin/perl
if (@ARGV[0] =~ /\bhelp\b/)
 {

	print "MemoryUsage.pl SNMPver community hostname\n";
	print "SNMPver - version of SNMP protocol\n";
	print "community - community name of SNMP protocol\n";
	print "hostname - Target host\n";
	exit 1;

}
# Get hostname and trim newline
$localhost = `hostname`;
$localhost =~ s/\s*$//g;
$hostname  = shift ||
$localhost;$community = shift || "public";
$version = shift || "v1";
$results =  "";
$MIB_TotalMemory = "UCD-SNMP-MIB::memTotalReal.0";
#$MIB_TotalMemory = "UCD-SNMP-MIB::memTotalReal.0";
$outres = "snmpget -$version -c $community $hostname $MIB_TotalMemory |";
open(OUTMEM,$outres) || die "Unable read pipe\n";
while ($line = &lt;OUTMEM&gt;) {	
	if ($line =~ /\bINTEGER\b/) {
		$indval = index($line,"="); 
		$indval=inde($line,":",$indval);
		$val = substr($line,$indval+1,length($line) - $indval);
		$val =~ s/[a-zA-Z\/\n ]//
		print "Message.1: Available memory at host \"$hostname\": $val in kB\n";
		print "Statistic.1: $val\n";
		print "Message.2: Again, the available memory at host \"$hostname\": $val in kB\n";
		print "Statistic.2: $val \n";
		exit 0;
	}
}
print "Statistic: 0\n";
exit 1;

Below is the output from this script:

Troubleshoot high CPU usage

The Linux/Unix Script Monitor and Nagios Script Monitor both use SSH to connect to target systems. If key exchange algorithms cause high CPU usage due to the number of active Job Engine Workers processes, you may notice gaps in polling data and slow responses from the SolarWinds Platform Web Console. If that occurs, try adjusting algorithms, as described next. Contact Technical Support for assistance, if necessary.

Changing algorithms can have security implications in some environments.

  1. On the SolarWinds Platform server, navigate to this default folder: c:\Program Files (x86)\SolarWinds\Orion\APM.
  2. Create a backup copy of the SolarWinds.APM.Probes.dll.config file.
  3. In a text editor, open SolarWinds.APM.Probes.dll.config and locate the following section:
    <LinuxScriptSettings PromptWait="2" ColumnCount="200" TemporaryScriptFileNamePrefix="APM_" />.
  4. Modify algorithms in that section, as necessary.
    • Reorder example:
      <LinuxScriptSettings PromptWait="2" ColumnCount="200" TemporaryScriptFileNamePrefix="APM_" KeyExchangeList="diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha256" />

    • Removal example:
      <LinuxScriptSettings PromptWait="2" ColumnCount="200" TemporaryScriptFileNamePrefix="APM_" KeyExchangeList="diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1" />

  5. Save your changes.
  6. Use the SolarWinds Platform Service Manager to restart all services.