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.
Note
Bourne shell (sh) does not support arrays.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 |
---|---|
arrayLen | Number of metrics to be monitored |
metrics | Array contains all metrics display names |
warning | Array contains all metrics warning threshold values |
critical | Array contains all metrics critical threshold values |
doAlerts | Array contains all metrics alerts flag values |
userParams | Array contains all metrics respective user parameters |
Note
- 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 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 |
---|---|
metric (required) | Metric name |
component | Instance name of Metric (only when you have multiple instances) |
*value | Value of metric or instance |
state | Alert state of the metric(Only if they need Agent to handle alerts) |
alert_desc | Alert description (Only if they need Agent to handle alerts) |
hostname | Hostname of remote host (only for posting metrics to other hosts) |
address | IPAddress of remote host (only for posting metrics to other hosts) |
id | Resource ID of the remote host (only for posting metrics to other hosts) |
Note
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:
- From All Clients, select a client.
- Go to Infrastructure > Resources, select a resource type.
- Click the desired resource name. Overview page appears.
- 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.