Submit a ticketCall us

Systems Monitoring for Dummies
Our new eBook will teach you the fundamentals and help you create monitors and alerts that are effective, meaningful, and actionable. Monitoring is more than a checkbox on your to-do list. This free eBook will give you practical advice to help you succeed in all aspects of monitoring – discovery, alerting, remediation, and troubleshooting. Don’t miss out on this indispensable resource for newbies, experienced IT pros, and everyone in between. Register Now.

Home > Success Center > Server & Application Monitor (SAM) > SAM 6.5 Administrator Guide > Manage application monitor templates and component monitors > Creating a Nagios Script monitor

Creating a Nagios Script monitor

doc-icon.png For the ultimate custom template guide, see  SAM Custom Template Guide.  

Updated: 3-9-2017

This component uses SSH to upload a Nagios script to a Linux/Unix server, runs the Nagios script on the server and then processes the script's exit code and text output. This monitor has the ability to return multiple values.

Statistic

The statistic for this component monitor is the value returned by the script. This component monitor has the ability to return multiple results and has the ability to process Nagios resulting output. For more information, see http://nagios.sourceforge.net/docs/3_0/pluginapi.html.

A maximum of 10 output pairs can be returned. If you exceed the maximum allowed, remove the excess output pairs or they are ignored.

Prerequisites for Orion agent for Linux

You need to include credentials that can run scripts on the monitored Linux-based computer. Agentless monitoring does not require these credentials.

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
STAT_PAIRS_COUNT = 10
 
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)))

Field Descriptions

Description

This field provides a default description of the monitor. You have the ability to override the default description by adding to or replacing the text, which is automatically saved. The variable to access this field is ${UserDescription}.

Component Type

This describes the type of monitor you are using.

Enable Component

This option determines whether or not the component is enabled. Disabling this component leaves it in the application as deactivated and does not influence 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 Windows credential that is both a user who can log on to the SolarWinds SAM server, and has sufficient rights on the target node to do whatever the script needs to do. For example, if the script does something with WMI, the credentials also need WMI rights on the target node. If the credential you need is not already present in the credentials list, use the Quick Credentials section to add a new credential.

Port Number

This field allows you to specify the port number used for the SSH connection. The default value is 22.

Script Working Directory

This field allows you to specify the working directory of the script process.

Check Type

This determines how the return code is evaluated.

Return Code Service State Host State

0

OK

Up

1

Warning

Up or Down/Unreachable

2

Critical

Down/Unreachable

3

Unknown

Down/Unreachable

_______________________
If the Use Aggressive Host Checking option is enabled, return codes of 1 result in a host state of DOWN, otherwise return codes of 1 will result in a host state of UP.

Count Statistic as Difference

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

Command Line

This field is in the script editing window and allows you to specify the script you want to run on the target node followed by the arguments. To enter your script, click the Edit button that reveals the script editing window. For more information, see http://nagios.sourceforge.net/docs/3_0/pluginapi.html.

The length of the Command Line field is limited to 266 characters for Solaris systems, minus the length of the ${SCRIPT} variable after being resolved to a file name such as the following: APM_937467589.pl. Since the length of the file name will typically be around 16 characters, this means that the actual user Command Line input cannot be longer than 266 - 16, or 250 characters (not including the length of the 9 characters for the “${SCRIPT}" variable itself). If you need to pass a longer command line to the target node, you can 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

This field is in the script editing window and allows you to enter your script via typing or pasting. You can test the script to receive output definitions. You can save these definitions to the component monitor for further configurations. Every saved definition is listed as Script Output with an assigned number and name. See Test script output for details.

Status Roll-Up

This option allows you to choose how you would like the monitor to report based on the output provided by the script. The default selection is “Show worst status.”

User Notes

This field allows you to add notes for easy reference. You can access this field by using the variable, ${UserNotes}.

Scripts must report status through return codes

Nagios determines the status of a host or service by evaluating the return code. The following table shows a list of valid return codes, along with their corresponding service or host states.

To correctly create this component monitor, you must first return an exit code which results in an Up (0), Warning (2), or Critical (3) status. When one of these exit codes is received the appropriate dynamic evidence table structure is created and all further exit codes are handled correctly. If the component only returns Down (1) or Unknown (4) on first use, the appropriate dynamic evidence table structure is not created appropriately.

Return Code Service State Host State

0

OK

Up

1

Warning

Up or Down/Unreachable

2

Critical

Down/Unreachable

3

Unknown

Down/Unreachable

___________________
If the Use Aggressive Host Checking option is enabled, return codes of 1 will result in a host state of Down, otherwise return codes of 1 will result in a host state of Up.

Nagios scripts must exit with a valid return code and a line of text output. The exit code determines the status of the component. If the exit code is 0 (OK), the component status may be further modified by thresholds from the optional statistics. To return up to ten optional statistics, separate the statistics from the status message with the pipe (|) symbol using the following syntax:

statusMessage [|'statisticName'=value]

Below is an example of valid output with a status message and two statistics:

The script ran. | 'CPU%'=75.2 'MemoryRemainingInKB'=600784

Test script output

You should test the script output while editing the script prior to testing the script in the template or application component pages. If the output formatting or values are not correctly defined or missing, you may receive an error: "Script output values are not defined or improperly defined." This error displays if the named fields could not be located in the script output.

To test the script and save output definitions:

  1. Open the template or application monitor using the Nagios Script monitor. To open, click Settings > All Settings > SAM Settings > Manage Application Monitors. Locate and edit the application monitor or template with the Nagios Script monitor.
  2. Locate and expand the component using the Nagios Script monitor type in the template.
  3. Locate the Script Body field and click Edit Script.
  4. On the Edit Script dialog, click Get Script Output. You may be prompted to specify a test node and credentials.
  5. Wait for the Output Result. The results should populate with values returned by the script. Review the results to ensure all formatting is correct and fields properly load.

    If you receive an error, you may have an issue in the script. For more information on formatting and outputs, see http://nagios.sourceforge.net/docs/3_0/pluginapi.html.

  6. You can store the output definitions returned by the script test as Script Output in the component monitor. Click Save to add the output definitions. The component monitor will display the definitions with a unique ID, display name, and additional configuration options.
  7. To save changes to the template or application monitor, click Submit.
 
Last modified

Tags

Classifications

Public