Configuring LINUX-UNIX shell scripts monitor type


You can configure script monitoring in Linux environments. The scripts run on target hosts where a PATROL Agent is running. According to policy configuration, the scripts run on targeted remote hosts and the execution output is consumed by the KM to set value to attributes. Remote hosts are connected by using SSH connections.runs.

You can also use the monitor type to run a script with multiple output instances on a local target host where a PATROL Agent is running. For such cases, you do not need to provide credentials. You can also configure the unit of the script outputs and configure if the output is a KPI. For more information, see Configuring-metadata-for-script-outputs.

To configure LINUX-UNIX shell scripts monitor type

  1. Perform one of the following actions:
    • In BMC Helix Operations Management, click Configuration > Monitoring Policies > Create Policy.
    • In TrueSight Operations Management, click Configuration > Infrastructure Policies > Create Policy.
  2. Click Add Monitoring Configuration.
  3. To configure the KM, set the following preferences in the Add Monitoring Configuration dialog box:

    Monitoring Solution

    Monitor Profile

    Monitor Type

    Scripting

    LINUX-UNIX

    LINUX-UNIX shell scripts

To configure the monitor type, you need to configure the devices where the script would run and the scripts that need to run on these devices. You can either configure each device and the scripts that run on it or configure a file containing the list of devices and scripts. In the monitor type, you can configure default and similar configurations to access devices and scripts in the Default Configurations section.

Device and script

Click the Add button and enter the remote device and details of the script running on the device. You can configure multiple scripts to run on a device.

Field

Description

Device name/IP

Enter a host name or an IP address. The name can be short or long. The KM uses this value when it sets up the SSH connection with the target device.

You can also enter an alias name. If you enter an alias name in the field, you must enter the device IP address in the Forced IP Address field. By using an alias and not a real direct name is useful when forcing access to the remote target device on a non-resolvable name and IP address (for example, when devices have multiple network adapters). The name must match the following regular expression pattern - ^[0-9a-zA-Z._%:-]+$.

Enter the name or IP address of the host where PATROL Agent and the KM are installed to run the script that generates multiple output instances and runs on a local host, 

Forced IP Address

Enter the IP address of the device that you want to monitor. If you enter the real host name or IP address in the Device name/IP field, leave this field blank. The input in the field must match the following regular expression pattern: - [^(?:(^((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?):{1,2}((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)$)|(^(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}$))]]>

Category

Enter a category name to group the devices. A container is created with the category name.

Do not enter the following characters in the field: - <>\/|":*?]].

Port

Enter the SSH port number to connect to the device. The default port number is 22.

You can leave the field blank to run the script that generates multiple output instances and runs on a local host.

Timeout (sec)

Enter the connection timeout period in seconds. A target device might not be available or might be very slow to respond. In such scenarios, make sure that the KM does not wait for it and stop responding. You can define the maximum time to allow to establish a connection. If the time elapses, the KM understands that there is a failure to monitor by using the script. If the network or target host is slow, you can still get the KM to work properly by allowing a longer time out period. The minimum value is 1 second, and the maximum value is 3600 seconds. The default value is 5 seconds.

Poll interval (sec)

The PATROL Agent maintains a set of SSH connections with all target hosts. If a connection breaks, the PATROL Agent can reconnect smoothly. The KM checks the status of the SSH connection at the interval set in this field. By default, the KM checks the connection status every 300 seconds. The minimum value is 10 seconds, and the maximum value is 100,000 seconds.

Scripts

Click the Add to configure the script details.

Name

Enter a display name for the script. A container is created with the script display name. This container holds the attributes for the script instance.

Input in the field must match the following regular expression pattern - ^[0-9a-zA-Z._%:-]+$.

Example of the display name: cron-monitor.sh, ping3rdParty.sh.

Script

Enter the path from the remote computers where you want to run the script. The following inputs are supported in the field:

The absolute path of the script file: Enter the absolute path of the location on the target computer where the script would be copied before execution.
For example, the /tmp/myScript.sh path means that the myScript.sh file is located on the PATROL Agent host computer and would be moved to the /tmp folder on the target computer. The script file is run from this location. The file is uploaded every time when the source of the script changes on the PATROL Agent host.
In some cases, you might want to run a script file with other files (for example, data) that are bundled with the script. In such cases, the KM uploads these files along with the script file. To use this feature, add all the files along with the script file to a .zip or .tar file on the PATROL Agent file system. Enter the absolute path of the .zip or .tar file in this field. The archive must have the same name as the base script for the KM to upload the content of the .zip or .tar file to the target host. For example, if the policy is defined with /tmp/myScriptDir/myScript.sh value, the tar file name must be myScript.tar, on the PATROL Agent file system. Alternatively, to run a script file with other files, add all the files to a folder and add the following comment at the first line of the script file:
#requires <absolute path of the folder where all required files are located>
With the script file, the KM would copy the files mentioned in the folder and run them with the script.
To make sure that the most updated script runs on the target computers, save the script files in any of the following folders:

  • %PATROL_HOME%/TRO/Conf/Scripts/ScriptFileTransfer/Devices/DeviceName/
  • %PATROL_HOME%/TRO/Conf/Scripts/ScriptFileTransfer/
  • %PATROL_HOME%/TRO/Conf/Scripts/Samples/

The KM first checks if the script file mentioned is located in any of these folders. If it is, the script file is copied to the specified target computer location. If the script does not exist on the PATROL Agent file system in the accepted formats (simple file, .tar, or .zip), the Script Status attribute generates an alert with an annotation containing the problem details.

Important

If the script (for example /tmp/bmc/myScript.sh) does not exist on the remote device but is present on the monitoring system, the KM copies the script to the remote device. The KM creates the specified directory structure (/tmp/bmc/) on the remote device and then copies the script. 

One OS command line (also known as one-liner): The script used by the monitor can be a simple or complex command. Multiple tools can be used to write the command. Standard shell syntax rules apply.
For example, the following line can be used to monitor the file system utilization in percent on the targeted device.

df -lkh | grep -v Mounted | tr -s ' ' | for line in $(cut -d ' ' -f 6,5|sed -e 's/ /,/g' -e 's/%//
g' -e 's/\//_/g' );do printf "FileSystem=%s,UsagePct=%d\n" `echo $line | cut -f 2 -d ','
`echo $line | cut -f 1 -d ','`;done

To run a script file with an extension other than .sh, create an entry for the extension in the following file and restart PATROL Agent:

$PATROL_HOME/TRO/Conf/Properties/runtimeExtensions.properties

The following out-of-the-box entries are available in the file:

  • .pl=perl
  • .plx=perl
  • .py=python
  • .php=/usr/bin/php

In the runtimeExtensions.properties file, ensure that the ApplyRuntime variable is set to true.

Arguments

Enter the arguments that are passed during the script execution. Separate multiple arguments with a space.

For example, a script file that returns the log file size must include the log file name as an argument.

Content match

In addition to monitoring numeric values, the KM can monitor a specific text pattern returned by the script during execution. This is useful when you need to enable a certain value where the actual numeric value is the same. The KM scans for the value defined in this field. It returns an annotation text with the value and the text defined in this field. You can use a single regular expression or a list separated by semicolons.

The syntax of regular expression must be considered valid for using Oracle Java (java.util.regex).

Timeout (sec)

Enter the connection time out period in seconds. A target device might not be available or might be very slow to respond. In such scenarios, to make sure that the KM does not wait for it and stop responding, you can define the maximum time to allow to establish a connection. If the time elapses, the KM understands that there is a failure to monitor using the script. If the network or target host is slow, you can still get the KM to work properly by allowing a longer time out period. The minimum value is 1 second, and the maximum value is 3600 seconds. The default value is 5 seconds.

If the configured script does not provide a result in the specified time period, a timeout annotation message is displayed in the Status attribute of the configured script. If the configured script runs successfully, the values of Content match, Script response time, Exit Status, and Script value attributes are updated.

The minimum value is 1 second, and the maximum value is 3600 seconds. The default timeout value is 5 seconds.

Important

The script execution is terminated in case of a timeout alert.

Poll interval (sec)

The PATROL Agent maintains a set of SSH connections to all target hosts. If a connection breaks, the PATROL Agent can reconnect smoothly. The KM checks the status of the SSH connection at the interval set in this field. By default, the KM checks the connection status every 300 seconds. The minimum value is 10 seconds, and the maximum value is 100,000 seconds.

Independent monitor view

Select this check box to configure the Scripting KM to create a monitor showing independently within the associated device.

Enable events for single value script annotation

Select this check box to enable events for single-value script annotation.

For more details about single value, see Defining the script output (Linux).

Scheduling Script monitoring

Enable Scheduling for above Script

Select this checkbox to enable script scheduling. By default, this script will be monitored continuously at every poll time of the collector (5mins).

Important

To execute the script, you must match the date, day, and time.

Date of the month (regex supported)

Enter a date on which you want to execute the script.

You can specify multiple dates by using regex.

Example

To monitor the system only on the 1st, 2nd, and 3rd of each month, enter ^[1,2,3]$".

Day

Select the day or days on which you want to execute the script.

Start Time (HH:MM)

Enter the start time for monitoring.

The input must match the following regex pattern: ^([01]?[0-9]|2[0-3]):[0-5][0-9]$.

Example

Enter 18:30 to start monitoring after 18:30 hours. 

End Time (HH:MM)

Enter the end time for monitoring.

The input must match the following regex pattern: ^([01]?[0-9]|2[0-3]):[0-5][0-9]$.

Example

Enter 21:30 to stop monitoring after 21:30 hours. 

Credentials configuration

Enter the credentials to connect to the remote host. If this field is left blank, the PATROL Agent default account user name is used for the connection. If you can access all the devices that you are configuring by using one user's credentials, you can leave this section blank with the device and script details and enter it one time in the Default configurations > Default device configuration section.

You can leave the fields in this section blank to run the script that generates multiple output instances and runs on a local host.

User name

Enter the user name used to connect to the remote host.

Password based authentication

Password

Enter the password corresponding to the user name (enter $ character to modify the password and leave it blank).

Key based authentication

Public key file path

Enter the absolute path of the file that will hold the public key.

Private key file path

Enter the absolute path of the file that will hold the private key.

Passphrase

Enter the passphrase to access public and private keys (enter $ character if you want to modify the password and leave it blank).

File-based monitoring

Configure scripts and devices from a file.

Field

Description

Import devices from files

The KM enables you to import devices and the script file names that you want to run in a file. To import the device and script names in a file, select the check box.

To use the feature, copy all the script files at the following location on the PATROL Agent: $PATROL_HOME/TRO/Conf/ImportDevices. PATROL Agent reads the files and configures the devices and scripts within each file.

An instance name is created for the configured files. The instance name is similar to the file name. All devices and scripts in a file are grouped under the same instance.

A readme file with instructions about how to configure from file is located at the following location: $PATROL_HOME/TRO/Conf/ImportDevices.

Template for configuring from a file:

# Device Name/IP,Forced IP Address,Port,Connection timeout,Connection poll interval,Username,Password,Public Key Path,Private Key Path,Passphrase|Script name*Script path*Script arguments*Script timeout*Script poll Interval*Script RegEx to search|

Example 1:

Configure a device with three scripts that run RegEx 'ERR'. User name and password details are available.

clm-aus013799,172.22.177.167,22,2000,60,yossi,yossi123,,,|scriptInstaneName1*/root/yossi/apps/myAppsCPU.bash**60*300*ERR|
scriptInstaneName2*/root/yossi/apps/myAppsMEM.bash**60*300*ERR|scriptInstaneName3*/root/yossi/apps/myAppsSESSION.bash**60*300*ERR|

Example 2:

Configure a device with three scripts that run without a RegEx; Public, private key, and passphrase details are available.

clm-aus-013799,172.22.177.167,22,2000,60,yossi,,/root/.ssh/id_rsa.pub,/root/.ssh/id_rsa,yossi123|scriptInstaneName1*/root/yossi/apps/
myAppsCPU.bash**60*300*|scriptInstaneName2*/root/yossi/apps/myAppsMEM.bash**60*300*|scriptInstaneName3*/root/yossi/apps/
myAppsSESSION.bash**60*300*|

Default configuration

You can configure information about accessing devices and scripts in this section. For example, if all the devices that you are configuring can be accessed with one credentials (user name and password), you can enter those credentials in this section rather than entering them with all the devices. Also, if you forgot to enter any such information with a device or script, the information available in this section is used by the KM. 

Field

Description

Default device configuration

Port

Enter the SSH port number to connect to the configured device. The default port number is 22.

Timeout (sec)

Enter the connection timeout period in seconds. A target device might not be available or might be very slow to respond. In such scenarios, to ensure that the KM does not wait for it and stops responding, you can define the maximum time to allow to establish a connection. If the time elapses, the KM understands that there is a failure to monitor using the script. If the network or target host is slow, you can still get the KM to work properly by allowing a longer timeout period. The minimum value is 1 second and the maximum value is 3600 seconds. Default value is 5 seconds.

Poll interval (sec)

The PATROL Agent maintains a set of SSH connections to all target hosts. If a connection breaks, the PATROL Agent can reconnect smoothly. The KM checks the status of the SSH connection at the interval set in this field. By default, the KM checks the connection status every 300 seconds. The minimum value is 10 seconds and the maximum value is 100,000 seconds.

Credentials configuration

User name

Enter the user name to connect to the remote device.

Password based authentication

Password

Enter the password corresponding to the user name (enter $ character if you want to modify the password and leave it blank).

Key based authentication

Public key file path

Enter the absolute path of the file that will hold the public key.

Private key file path

Enter the absolute path of the file that will hold the private key.

Passphrase

Enter the passphrase to access public and private keys (enter $ character if you want to modify the password and leave it blank).

Default script configuration

Timeout (sec)

Enter the connection timeout period in seconds. A target device might not be available or might be very slow to respond. In such scenarios, to ensure that the KM does not wait for it and stops responding, you can define the maximum time to allow to establish a connection. If the time elapses, the KM understands that there is a failure to monitor using the script. If the network or target host is slow, you can still get the KM to work properly by allowing a longer timeout period. The minimum value is 1 second and the maximum value is 3600 seconds. Default value is 5 seconds.

Poll interval (sec)

The PATROL Agent maintains a set of SSH connections to all target hosts. If a connection breaks, the PATROL Agent can reconnect smoothly. The KM checks the status of the SSH connection at the interval set in this field. By default, the KM checks the connection status every 300 seconds. The minimum value is 10 seconds and the maximum value is 100,000 seconds.


Administration

Configure the section to use the KM efficiently.

Field

Description

Root display name

Enter the name of the main container that would store all the scripts. The name must not contain the following characters - < > \ / | " : * ?.

Device mapping

Select the device mapping mode:

  • FQDN - Monitors are created within a device according to the discovered FQDN of the monitored system.
  • User defined - Monitors are created within a monitored device using the name provided with the end user (alias).
  • Disable - Monitors are created within the device of the PATROL Agent(s).

Important: If the configured Device name/IP is set using the alias name and the force IP address, the device gets mapped to the console with the Device name/IP instead of the device FQDN although this option is enabled.

JAVA_HOME path

If you are not using JRE that is installed with the PATROL Agent, enter the complete path of the JAVA_HOME directory. The JAVA home environment variable or PATROL Agent JRE is used if this field is left blank.

Example:

  • Windows - If the JRE files reside at C:\Program Files (x86)\Java\jre8\bin\java.exe location, specify the path as C:\Program Files (x86)\Java\jre8.
  • UNIX/Linux - If the JRE files reside at the /usr/java/jdk1.8.0_65/bin/ location, specify the path as /usr/java/jdk1.8.0_65.

Custom monitor types cleanup

Enables you to choose to delete the old monitor types (known as knowledge modules) that were created based on the scripts output and are no longer in use.

  • Disable - Automatic cleanup is disabled.
  • Daily - Automatic cleanup is enabled. Monitor types that are not in use since last one day are deleted.
  • Weekly - Automatic cleanup is enabled. Monitor types that are not in use since last one week are deleted.
  • Monthly - Automatic cleanup is enabled. Monitor types that are not in use since last one month are deleted.

Enable logging

Select the check box to enable logging. The log files are located at $PATROL_HOME/TRO/logs, on the server where the PATROL Agent is running. By default, debug is disabled.

 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*