Introduction

This document explains the configuration of SHELL scripts in defining a custom monitor.

SHELL script configuration

Only Bourne Again SHell (bash), Korn shell (ksh) support arrays. As we need to parse the parameters and assign to arrays, only bash, ksh shell scripts must be used for writing custom monitor plugins.

The shebang lines #!/bin/bash, #!/bin/sh are mandatory for the scripts. For example:

./sample.sh 
    "/metricName::metricName1|metricName2" 
    "/metric::displayName1|displayName2" 
    "/warn::warn1|warn2" "/critical::crit1|crit2" 
    "/alert::do_alert1|do_alert2" 
    "/params::'args_string1|args_string2'"
#!/bin/bash 
LANG=C`

Parsing arguments

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

 script_dir=$(dirname $0)
 params=`echo $@ | tr " " "\n"`
 for param in $params
 do
 	case "$param" in
		/metricName::*)
			IFS="|" read -ra metricNames<<<"${param#*::}"
		;;
		/metric::*)
			IFS="|" read -ra metrics<<<"${param#*::}"
		;;
		/warn::*) 
			IFS="|" read -ra warnings<<<"${param#*::}"
		;;
		/critical::*)
			IFS="|" read -ra criticals<<<"${param#*::}"
		;;
		/alert::*)
			IFS="|" read -ra doAlerts<<<"${param#*::}"
		;;
		/params::*)
			userParamsString=$(echo ${param#*::} | sed -e "s/'//g")
			IFS="|" read -ra userParams<<<"$userParamsString"
		;;
		*)
	esac
 done

Accessing variables

The following sample shows how to access the variables.

 arrayLen=${#metricNames[@]}
 for (( x=0; x<$arrayLen; x++ )); 
    echo ${metricNames[x]}
     echo ${metrics[x]}
     echo ${warnings[x]}
     echo ${criticals[x]}
     echo ${doAlerts[x]}
     echo ${userParams[x]}
     echo ""
 done
Variable Description
VariableDescription
arrayLenNumber of metrics to be monitored
metricsArray contains all metrics display names
warningArray contains all metrics warning threshold values
criticalArray contains all metrics critical threshold values
doAlertsArray contains all metrics alerts flag values
userParamsArray contains all metrics respective user parameters

Displaying graphs

For graphing the metric values and for alerting, the script must write the output to the console in the below 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"
}
Values Description
ValuesDescription
metric (required)Metric name
componentInstance name of Metric (only when you have multiple instances)
*valueValue of metric or instance
stateAlert state of the metric(Only if they need Agent to handle alerts)
alert_descAlert description (Only if they need Agent to handle alerts)
hostnameHostname of remote host (only for posting metrics to other hosts)
addressIPAddress of remote host (only for posting metrics to other hosts)
idResource ID of the remote host (only for posting metrics to other hosts)

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 on 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.