This document explains the configuration of Python script to define a Custom Monitor.

Python script configuration

The script executes for the metrics at a regular interval. The interval set in OpsRamp.

python sample.py 
    "
    /metricName::metricName1|metricName2 
    /metric::displayName1|displayName2 
    /warn::warn1|warn2 
    /critical::crit1|crit2 
    /alert::do_alert1|do_alert2 
    /params::args_string1|args_string2
    "

Parsing arguments

Use the following block of code in all the custom monitor scripts to parse arguments.

 api = None
 try:
	sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
	from ScriptMonitorPythonApi import ScriptMonitorPythonApi
	api = ScriptMonitorPythonApi(sys.argv)
 except Exception, emsg:
	sys.exit()
 arrayLen = len(api.metricNames)
 metrics = api.metrics
 warning_thres = api.warnings
 critical_thres = api.criticals
 do_alerts = api.doAlerts
 userParams = api.userParams
VariablesDescription
arrayLenNumber of metrics to be monitored
metricsArray contains all metrics display names
warning_thresArray contains all metrics warning threshold values
critical_thresArray contains all metrics critical threshold values
do_alertsArray contains all metrics alerts flag values
userParamsArray contains all metrics respective user parameters
  • You need metric display names for graphical data in JSON payload. Example: “metric” : “displayName1”
  • Warning and critical thresholds help to calculate the alert state of metric.

Displaying graphs

For graphing the metric values and for alerting, the script must write the output to the console in the following JSON format.

[
	{
		"metric" : "displayName1",
		"component" : "instance1",
		"value" : "value1",
		"state" : "alert state1",
		"alert_desc" : "alert description1",
		"hostname/address/id" : "host1"
	},
	{
		"metric" : "displayName2",
		"component" : "instance2",
		"value" : "value2",
		"state" : "alert state2",
		"alert_desc" : "alert description2",
		"hostname/address/id" : "host2"
	}
]
ValuesDescription
metric (required)Metric name
componentInstance name of Metric (only when you have multiple instances)
value (required)Value of metric or instance
stateAlert state of the metric (only if you need Agent to handle alerts)
alert_descAlert Description (only if you need Agent to handle alerts)
hostnameHostname of remote host (only for posting metrics to other hosts)
addressIP address of remote host (only for posting metrics to other hosts)
idResource ID of remote host (only for posting metrics to other hosts)

Provide one of the following values: hostname, address, or id (only when metrics need to post on remote hosts).

  • If a user wants to send metric data to a remote host named XYZ, JSON object should be represented as “hostname”: XYZ.
  • If a user wants to send metric data to a remote host with IP address x.x.x.x, JSON object should be represented as “address”: x.x.x.x.

Possible values for state are:

  • OK
  • Warning
  • Critical

Viewing graphical representations

To view the graphical representation of the monitoring:

  1. From All Clients, select a client.
  2. Go to Infrastructure > Resources, select a resource type.
  3. Click the desired resource name. Overview page appears.
  4. From the left pane, click Metrics. The graph appears with display names: displayName1, displayName2.
    • The graph of displayName1 consists of 3 values val1, val2, val3 that are plotted against key1, key2 and key3 respectively.
    • The graph of displayName2 consists of 2 values val1, val2 that were plotted against key1 and key2 respectively.