Using G2 custom monitors, you can build and manage independent monitoring solutions without relying on the platform. Remote Script Executor executes shell, PowerShell, and Python scripts on Linux and Windows workstations.

Key features include:

  • User-defined external arguments support the script through custom attributes.
  • Monitor level script execution: Ability to pull more metrics in a single script execution.
  • Ability to execute different types of scripts through custom script options apart from default options.
  • Ability to use credentials attached to the device in the script using the dynamic macro support.

Constraint:

  • Windows workstation monitoring using a Linux Gateway is not supported.

  • If the end device language is other than English, ensure that the resulting JSON output from the script contains valid English characters, converting any invalid characters as necessary.

    Example:

    For the Monitor ‘Agent G2 - Microsoft AD Global Catalog Search Time’, the resulting output is:

        {'microsoft_AD_global_catalog_searchTime" :{"Components":
    
        {121.0.0.1":"13,64"}        
        }}
        

    In this example, we received ‘13,64’ instead of ‘13.64’ due to the end device language being Finnish. To convert this to English, we made the following change in the script:

    $formattedTime = "{0:N2}" -f $bindTimeMilliseconds.ToString("N2",[System.Globalization.CultureInfo]::InvariantCulture)

    After this change, we obtained the valid JSON output:

        {'microsoft_AD_global_catalog_searchTime" :{"Components":
    
        {121.0.0.1":"13.64"}
        }}"
        

Step 1: Create Metrics

Define metrics metadata that correlates with your script output and matches the monitor you define in the next step.

  1. Select a client from the All Clients list.
  2. Go to Setup > Monitoring > Metrics.
  3. From METRICS, click + Add.
  4. From Create Metric, enter the values for the fields described in the following tables and click Save.

Metric specification

FieldDescription
Metric Scope(required) Partner- or client-specific metric specification:
  • Partner Metric Metric has partner scope.
  • Client Specific Metric Metric has client scope.
Adaptor Type(required) Application. Select from the supported agent or gateway adapters.
Name(required) Unique metric name. The recommended naming convention is: ___. For example, apache_tomcat_webapps_count.
Tag NameUser-defined tags for filtering.
Display Name(required) Name to display, such as **System Drive Free Space**.
DescriptionDescription of the metric.
Data Point type(required) Type of data point specification:
  • Counter Delta - It calculates delta on top of metric value. If the result is less than zero then it returns zero

    Counter Delta = (Current poll value - Prev poll value)
  • Counter Rate - It calculates rate on top of metric value. If the result is less than zero then it returns zero.

    Counter Rate = (Current poll value - Prev poll value) / (Current poll time - Prev poll time)
  • Derive Delta - Not related to RSE. No support in both agent and gateway.
  • Derive Rate - Not related to RSE. No support in both agent and gateway
  • Gauge - It returns a direct metric value, which is returning from the script.
  • Rate - It calculates rate on top of metric value. If the result is less than zero then it returns a negative value.

    Rate = (Current poll value - Prev poll value) / (Current poll time - Prev poll time)
  • Delta - It calculates delta on top of metric value. If the result is less than zero then it returns a negative value.

    Delta = (Current poll value - Prev poll value)
  • None - Same as Gauge
UnitsMetric unit specification associated with the data point type. Click the drop-down menu to select from the available units.
Unit Multiplication FactorFactor to multiply the data point value by.
Datapoint value conversionDatapoint value conversion specification:
  • Value Populate metric using datapoint value.
  • Enumerated Map Map the datapoint to a state-description pair:
    • State Descriptions
      Click the plus icon to add state-description pairs for each datapoint value:
      • State State represented by the value.
      • Description Description associated with the state.
    • Use formatted value in: Render the value in an Alert or Graph.
Metric ProcessingMetric processing specification:
  • Graph
  • Notification
  • Graph and Notification
  • None
  1. Graph
  2. Choose this option when user only needs a Graph for the metric without an alert.
  3. Notification
  4. Choose this option when user only needs an Alert for the metric without a graph.
    When selecting this option, a dynamic UI will appear to configure alert thresholds, as shown in the screenshot below:
    Remote Script Executor Create Metric
    Configuring Alert Thresholds:
    When setting up notifications, the following options are available for configuring alert thresholds:
    Case 1: Enumerated Map
    • If "Datapoint Value Conversion" is set to "Enumerated Map," users need to specify the oState column values for Warning and Critical thresholds.
      • Warning Threshold: State [Specify State column Value]
      • Critical Threshold: State [Specify State column Value]

    Setting Alert thresholds for Enumerated Map conversion from strings to integers:
    Remote Script Executor Create Metric
    Setting Alert thresholds for Enumerated Map conversion from integers to strings:
    Remote Script Executor Create Metric
    Case 2: Value
    • If "Datapoint Value Conversion" is set to "Value" (the default setting), users need to specify the metric values for Warning and Critical thresholds.
      • Warning Threshold: Value [Specify Warning-level Threshold Value for the metric]
      • Critical Threshold: Value [Specify Critical-level Threshold Value for the metric]
    Additional Fields:
    • Subject: The metric subject is populated by default but can be customized.
    • Description: The metric description is populated by default but can be customized.
  5. Graph and Notification:
  6. Choose this option when user needs both Alert and Graph for the metric.
    When selecting this option, a dynamic UI will appear to configure alert thresholds, as shown in the screenshot below:
    Remote Script Executor Create Metric
    Configuring Alert Thresholds:
    The alert threshold configuration options are the same as the Notification option.
  7. None: Select this option when both alert and graph are not needed for the metric.

See the Metric token reference for a list of the tokens that is used in the Subject and Description fields.

Step 2: Create a Monitor

A custom Remote Script Executor monitor is a collection of Remote Script Executor metrics. You can create a template based on the Remote Script Executor monitor.

Macros are used to pass dynamic arguments to scripts. Use the static and dynamic macros listed in the following tables to make native and custom attributes available to the monitor.

You must create metrics in Step 1: Create metrics before creating a monitor.

  1. Select a client from the All Clients list.
  2. Go to Setup > Monitoring > Monitors
  3. Click + Create New.
  4. On the CREATE A MONITOR page, enter the fields listed in the following table and click Save. The newly created monitor is added to the list of monitors.

Monitor specification

MethodDescription
Monitor Scope(required) Partner- or client-specific monitor specification:
  • Partner Monitor Monitor has partner scope.
  • Client Specific Monitor Monitor has client scope.
Adapter Type(required) Application. Select from the supported agent or gateway adapters.
Name(required) Unique monitor name.
Description(required) Description of the monitor
Metrics(required) Click +Add to add metrics. Search for the previously defined metrics and click Add Metrics.
Configuration ParametersClick +Add to add configuration parameters. Search for the parameter and click Add to add it to the monitor:
  • Using available configuration parameters, you can specify the scripting language type and the platform to execute the script.
  • If you select the **Custom** value in configuration parameters, add the parameter: `custom.script.execution.path`.

Static macros

Use static macros to override the resource values. See the Static macro reference for a list of static macros.

Dynamic macros

MacroDescription
${customattributes.serviceName}Get custom attributes of the device - If you want to use an argument in any script, apply the custom attributes on the device.

For an example, you have a custom attribute on the device with `Key: serviceName` and `Value: oracledb`. During runtime, the Value: oracledb replaces the macro: `${customattributes.serviceName}` in the script.
${credentials.CredentialName.credentialField}Get the credentials added to the device - You can use (macros) credentials in the script to avoid storing the original username and password in plain text. When you run the script, the macros replace the original credentials.

For an example, if you define a credential set with a name JMXCred and added it to a device. You can use the macro ${credentials.JMXCred.username} in your script and macro will replace the original credentials in your script at runtime.
${credential.type.all}Use this macro to get all credential sets (assigned on the device) into the script.
${credential.type.name}Use this MACRO( ${credential.type.name}) to get specific credentials in the script.

For an example, If the device has SSH, WMI and Database credentials and if user want to get only database credentails inside the script then need to use ${credential.type.Database} inside the script. Similarly user can get any type of credentails into the script by replacing .name with the credentails type.
Example: ${credential.type.SSH}, ${credential.type.SNMP}, ${credential.type.VMWARE} etc.

Below are the supported credential types:

Credential TypesMarcosSample Output
VMWARE${credential.type.VMWARE}
[{
"uuid":"xB35mBgN354UGM3zQFZBQSaJ",
"type":"VMWARE",
"name":"sample-vmware",
"timeoutMs":10000,
"transportType":"HTTPS",
"appName":null,
"domain":null,
"username":"testuser",
"password":"xxxxxx",
"port":443
}]
SSH${credential.type.SSH}
[{
"uuid": "NwKGzg6qqSF29Sdy5hRJrAyH",
"type": "SSH",
"name": "sample-ssh",
"timeoutMs": 10000,
"transportType": "HTTP",
"appName": null,
"userName": "testuser",
"password": "xxxxxx",
"port": 22,
"privkey": null,
"passPhrasePasswd": null,
"privKeyFileName": null,
"sshAuthType": "PASSWORD"
    }]

The following are the remaining credential types:
SNMP, XEN, WINDOWS, JMX, HTTP, Database, CIM, NETAPP, NETAPPCLUSTER, HYPERFLEX, PURESTORAGE, FTP, CISCOUCS, EMCCLARIION, EMCVNX, EMCVNXE, EMCVMAX, IBM, HPEVA, REMOTE_CLI, TELNET, XTREMIO, VIPTELA, EMCVPLEX, EMCRPA, NUTANIX, HITACHIVSP, AZURESTACK, APPLICATION, and CITRIX_CVDA.

Script execution path for configuration parameters in Linux and Windows

The following runtime executables should be available in your Path variable for the corresponding operating system.

Script TypeLinuxWindows
BashbashNot Applicable
ShellshNot Applicable
PowershellNot Applicablepowershell.exe
Pythonpythonpython.exe
PerlPerlNot Applicable

If your runtime is not set as an environment variable, provide the runtime absolute path in custom.script.execution.path. For example, if python is not set, set custom.script.execution.path to /usr/lib/python.

Step 3: Create a Template

A template is an instance of a monitor and is applied to devices.

  1. Select a client from the All Clients list.
  2. Go to Setup > Monitoring >Templates.
  3. From Templates, click + Add.
  4. From MONITOR TEMPLATE, provide details for the following parameters and click Save.
MethodDescription
Select Template Scope(required) Partner- or client-specific monitor specification:
  • Partner Monitor Monitor has partner scope.
  • Client Specific Monitor Monitor has client scope.
Collector TypeSelect Agent
Monitor TypeSelect G2 Monitors
Applicable forSelect Device
Template NameName of the template
DescriptionSummary of the template
GenerationGeneration that the template belongs to
TagsUser-defined tags for filtering
PrerequisitesEssential things to consider when using this template
StatusActive or end-of-life template
NotesInformation that you want to add to the template
Template Family NameCategory that applies to the application, such as Windows Server, Storage Server, or Network Server
Deployment TypeOne of the following methods to use to apply the template to the resource:
  • Custom
  • Optional
  • Standard

After adding the template, add component thresholds and component filters by editing metric values. For more information, see Add Filter, Component Filters and Define Threshold

Step 4: Assign a Template

  1. From the left pane, click Infrastructure. The Infrastructure screen of the selected client is displayed.
  2. From the Resources tab, select the required resource from the list of resources. Or, use the search option to find the resource.
  3. Click the resource name to view details.
  4. From the left pane, click Monitors.
  5. From the Templates tab, click +Assign Templates.
  6. From Apply Templates, select the templates.
    The selected Templates section displays the chosen templates.
  7. Click Assign. The template gets assigned to the selected device.

After assigning the template to a resource for monitoring, click Get Latest Metric Values to view the latest metric information.

Step 5: View Graphs

The Agent monitors the system using the assigned templates and displays the results in a graphical format.

  1. From the left pane, click Infrastructure.
  2. From the Resources tab, select the required resource from the list of resources. Or, use the search option to find the resource.
  3. Click the resource name to view details.
  4. From the left pane, click Metrics. The Metrics page displays graphs generated by all monitoring templates assigned to a device.
  5. Search with the template name to filter the graphs.

Scripts Folder and Permissions

By default, all the Remote Script Executor (RSE) custom monitor scripts are downloaded to a predefined location in your system. The system user (Windows) and Root/Non-Root User (Linux) hold all the required permissions (Read, Write, and Execute) in the downloaded folders.

The following table provides the default folder locations and users for Windows and Linux:

Operating SystemDefault Folder LocationDefault User
Windows
  • 32 bit – %programfiles%\OpsRamp\Agent\plugins\rse
  • 64 bit – %programfiles(x86)%\OpsRamp\Agent\plugins\rse
System User
Linux/opt/opsramp/agent/plugins/rseRoot/Non-Root User
  • Default permission set for all executable files in this folder is 744.
  • Default permission set for other files in this folder is 644.

Script File Integrity Check

OpsRamp will verify for the custom script for file integrity and ensure that the file checksum remains the same before performing the monitor script execution. If the G2 based custom monitor script on the resource is changed, OpsRamp will redownload the original monitor script from the source for security reasons and continue the monitoring.

During this process, a critical alert about the “File checksum mismatch” will be generated on the resource, and users will be notified about the script modification on the resource.

Remote Script Executor example

Script

#!/bin/bash

CPU=$(top -bn1 | grep load | awk ‘{printf "%.2f\t\t\n", $(NF-2)}’)
MEMORY=$(free -m | awk ‘NR==2{printf "%.2f\t\t", $3*100/$2 }’)
DISK=`df -h | awk ‘$NF=="/"{ print $5}’ | sed ‘s/%//g’`

printf "{\"disk.utilization\" : %s , \"memory.utilization\" : %s , \"cpu.usage\" : %s}" "$DISK" "$MEMORY" "$CPU"

Output :

{"disk.utilization" : 23 , "memory.utilization" : 24.28 , "cpu.usage" : 0.64 }

Standard JSON output format

We recommend to adjust the script output to match one of the following JSON formats:

Include the scriptExceptions payload in the final JSON output is optional and should only be done if the script returns any exceptions. If no exceptions occur, the scriptExceptions payload should not be included in the final JSON output. The scriptExceptions payload can be used with any of the following formats. Below, we provide examples for a few of these formats. For more details on how to use scriptExceptions in RSE scripts, refer to the documentation.

Format 1:

Description:

This format is used when the metric does not have any dynamic components or instances. In such cases, construct the JSON by using the metric name as the key and mapping that key to the appropriate value.

Format for the JSON output when there are no exceptions:

{
  "Metric1": 98,
  "Metric2": 70,
  "Metric3": 80
}

Or

Format for the JSON output when exceptions occur:

{

  "Metric1": 98,
  "Metric2": 70,
  "Metric3": 80,
  "scriptExceptions": {
    "subject": "No monitoring data / Unable to fetch monitoring data / Incomplete script execution",
    "description": "Failed to collect data for following metrics. \n metricName: <Metric Name 1>, FailureReason: Failure Reason 1 \n metricName: <Metric Name 2>, FailureReason: Failure Reason 2",
    "raiseAlert": true,
    "logRequired": true,
    "alertState": "warning"
  }
}

Example:

{
  "system_windows_uptime_inMinutes": 120,
  "system_windows_overallCPU_utilization": 50,
}

Format 2:

Description: This format is used, when one metric returns a string and another metric returns a number. In such cases, a JSON output is prepared by mapping those strings or metrics to their appropriate values.

{
"Metric1": 98,
"Metric2": "STATE",
"Metric3": 80
}

Example:

{

   "system_windows_memory_usage": 35.75,
   "system_windows_winrm_status": "running"
}

Note: We recommend using numerical representation for String outputs by utilising Enumerated Map option of RSE.

Format 3:

Description: This format may be used, when the metric contains multiple components. In the below example, the data is fetched for multiple components of disks.

Format for the JSON output when there are no exceptions:

{
  "MetricName1": {
    "components": {
      "component1": 70,
      "component2": 98
    }
  },
  "MetricName2": {
    "components": {
      "component1": 77,
      "component2": 98
    }
  }
}

Or

Format for the JSON output when exceptions occur:

{
  "MetricName1": {
    "components": {
      "component1": 70,
      "component2": 98
    }
  },
  "MetricName2": {
    "components": {
      "component1": 77,
      "component2": 98
    }
  },

"scriptExceptions": {
    "subject": "No monitoring data / Unable to fetch monitoring data / Incomplete script execution",
    "description": "Failed to collect data for following metrics. \n metricName: <Metric Name 1>, FailureReason: Failure Reason 1 \n metricName: <Metric Name 2>, FailureReason: Failure Reason 2",
    "raiseAlert": true,
    "logRequired": true,
    "alertState": "warning"
  }
}

Example:

{
  "System_Windows_PhysicalDisk_WriteBytes_PerSec": {
    "components": {
      "physicaldisk_1": 0,
      "physicaldisk_2": 0
    }
  },
  "System_Windows_PhysicalDisk_AvgDisk_SecPerWrite": {
    "components": {
      "physicaldisk_1": 0,
      "physicaldisk_2": 0
    }
  }
}

Explanation:

In this example, System_Windows_PhysicalDisk_WriteBytes_PerSec is a metric name that has two components, physicaldisk_1 and physicaldisk_2, with their values mapped inside the components key.

Similarly, System_Windows_PhysicalDisk_AvgDisk_SecPerWrite is another metric name organized in the same way.

Format 4:

Description: This format is used when user needs metric-level alertTokens for all metrics of the script. Alert tokens are used to specify more information about the metrics in alert subject or in alert description or in both.

Format for the JSON output when there are no exceptions:

{
  "MetricName1": {
    "components": {
      "component1": "STATE",
      "component2": 98
    },
    "alertTokens": {
      "token1": "value",
      "token2": "value2"
    }
  },
  "MetricName2": {
    "components": {
      "component1": 77,
      "component2": 98
    },
    "alertTokens": {
      "token1": "value",
      "token2": "value2"
    }
  }
}

Or

Format for the JSON output when exceptions occur:

{
  "MetricName1": {
    "components": {
      "component1": "STATE",
      "component2": 98
    },
    "alertTokens": {
      "token1": "value",
      "token2": "value2"
    }
  },
  "MetricName2": {
    "components": {
      "component1": 77,
      "component2": 98
    },
    "alertTokens": {
      "token1": "value",
      "token2": "value2"
    }
  },
  "scriptExceptions": {
    "subject": "No monitoring data / Unable to fetch monitoring data / Incomplete script execution",
    "description": "Failed to collect data for following metrics. \n metricName: <Metric Name 1>, FailureReason: Failure Reason 1 \n metricName: <Metric Name 2>, FailureReason: Failure Reason 2",
    "raiseAlert": true,
    "logRequired": true,
    "alertState": "warning"
  }
}

Example:

{
  "system_linux_memory_utilization": {
    "components": {
      "real_memory_utilization": 50
    },
    "alertTokens": {
      "memory.usage": "Total memory: 16 GB, Used memory: 8 GB"
    }
  }
}

Explanation:

In this example, the system_linux_memory_utilization metric includes a component real_memory_utilization with a value of 50. The alert tokens offer a summary at the metric level, indicating “Total memory: 16 GB, Used memory: 8 GB”. This information is included in the alert description, the alert subject, or both for the system_linux_memory_utilization metric.

Format 5:

Description: This format is used, when user needs alert tokens at metric-level, for only few of the metrics of the script.

Format:

{
    "MetricName1": 254,
    "MetricName2": {
        "components": {
            "comp1": 90,
            "comp2": 60
        }
    },
    "MetricName3": {
        "components": {
            "component1": "STATE",
            "component2": 98
        },
        "alertTokens": {
            "token1": "value",
            "token2": "value2"
        }
    }
}

Example:

{
  "system_linux_services_status": {
    "components": {
      "iptables": "inactive",
      "irqbalance": "active",
      "kdump": "active",
      "ypxfrd": "inactive"
    },
    "alertTokens": {
      "services.active.counts": " 2 services are active",

      "services.inactive.counts": "2 services are inactive"
    }
  },
  "system_linux_totalServices_count": "4"
}

Explanation:

The system_linux_services_status metric includes two alert tokens at the metric-level.

  • Token 1, denoted as services.active.counts, provides the count of active services.
  • Token 2, identified as services.inactive.counts, offers the count of inactive services.

These tokens provide valuable insights into the status of the services monitored under this metric.

On the other hand, the metric system_linux_services_count does not have any associated alert tokens. So, alerts for this metric will not include any additional descriptive information.

Format 6:

Description: This format is used, when user needs Component Level Alert Tokens. Alert token value for each metric component are specified separately, as mentioned below:

Format for the JSON output when there are no exceptions:

{
  "MetricName1": 254,
  "MetricName2": {
    "components": {
      "comp1": 90,
      "comp2": 60
    }
  },
  "MetricName3": {
    "components": {
      "component1": "STATE",
      "component2": 98
    },
    "alertTokens": {
      "token1": "value",
      "token2": "value2"
    }
  },
  "MetricName4": {
    "components": {
      "component1": 10,
      "component2": 20
    },
    "alertTokens": {
      "token1": {
        "component1": "token 1 value of component 1",
        "component2": "token 1 value of component 2"
      },
      "token2": {
        "component1": "token 2 value of component 1",
        "component2": "token 2 value of component 2"
      }
    }
  }
}

Or

Format for the JSON output when exceptions occur:

{
  "MetricName1": 254,
  "MetricName2": {
    "components": {
      "comp1": 90,
      "comp2": 60
    }
  },
  "MetricName3": {
    "components": {
      "component1": "STATE",
      "component2": 98
    },
    "alertTokens": {
      "token1": "value",
      "token2": "value2"
    }
  },
  "MetricName4": {
    "components": {
      "component1": 10,
      "component2": 20
    },
    "alertTokens": {
      "token1": {
        "component1": "token 1 value of component 1",
        "component2": "token 1 value of component 2"
      },
      "token2": {
        "component1": "token 2 value of component 1",
        "component2": "token 2 value of component 2"
      }
    }
  },
  "scriptExceptions": {
    "subject": "No monitoring data / Unable to fetch monitoring data / Incomplete script execution",
    "description": "Failed to collect data for following metrics. \n metricName: <Metric Name 1>, FailureReason: Failure Reason 1 \n metricName: <Metric Name 2>, FailureReason: Failure Reason 2",
    "raiseAlert": true,
    "logRequired": true,
    "alertState": "warning"
  }
}

Example:

{
  "system_linux_interfaces_count": {
    "components": {
      "system_linux_interfaces_count": 8
    },
    "alertTokens": {
      "interfaces_names": "interfaces names are cni0, ens160, flannel.1, veth05f2cc15,  veth10f0079d,  veth42a5dd4f,  vetha7efbaa5,  vethdc3c2d78"
    }
  },
  "system_linux_network_interface_trafficIn": {
    "components": {
      "cni0": 14329842632,
      "ens160": 13491465976
    },
    "alertTokens": {
      "mac.address": "cni0:42-a5-a4-fd-86-eb,ens160:00-0c-29-b7-be-c3"
    }
  },
  "system_linux_network_interface_trafficOut": {
    "components": {
      "cni0": "9148429744",
      "ens160": "12488937472"
    }
  },

"scriptExceptions": {
    "subject": "An exception has occurred. Unable to fetch the monitoring data",
    "alertState": "critical",
    "description": "Failed to collect data for following metrics. \n metricName: system_linux_network_interface_errorsIn, FailureReason: rx_errors attribute not available for interface cni0, metricName: system_linux_network_interface_errorsOut, FailureReason: tx_errors attribute not available for interface cni0",
    "raiseAlert": true,
    "logRequired": true
  }
}

Explanation:

In this example, the JSON structure demonstrates the use of scriptExceptions along with component-level and normal metric-level alert token.

The system_linux_interfaces_count metric includes a component that counts the number of interfaces and a metric-level alert token listing the names of these interfaces.

For system_linux_network_interface_trafficIn, the components show the inbound traffic for specific interfaces, while the component-level alert token provides the MAC addresses of these interfaces, offering more details on the interface.

system_linux_network_interface_trafficOut presents outbound traffic data for the interfaces but does not include additional alert tokens.

Multiple Custom Script Arguments in Macro

Refer the document Multiple Custom Script Arguments for more details.

Generate Alert Tokens in RSE

Refer the document Generate Alert Tokens in RSE for more details.

Exception Handling In RSE

Refer the document Exception Handling In RSE for more details.

Enumerated Mapping In RSE

Refer the document Exception Handling In RSE for more details.

Next Steps