BigMemory 4.4.0 | Product Documentation | Terracotta Management Console User Guide | Integrating with Nagios | Example of a Shell Script Plugin
 
Example of a Shell Script Plugin
The following is an example of a plugin using a shell script. This particular plugin reports an event in Nagios XI when a node.left event occurs. A node.left event occurs whenever a node leaves the cluster.
For a list of other kinds of events that occur in a Terracotta cluster, see "Monitoring Cluster Events" in the BigMemory Max Administrator Guide.
#!/bin/bash
# Parameters
# ----------
SERVER=$1 # The IP address or resolvable hostname of a Terracotta server.
PORT=$2 # The Terracotta server's management-port (9540 by default).
INTERVAL=$3 # How far back in time, in minutes, to search for the event.
RESTURL="http://${SERVER}:${PORT}/tc-management-api/agents/
operatorEvents?sinceWhen=${INTERVAL}m"
GET_INFO=`curl "$RESTURL" -s | grep left`
NB_LINES=`echo $GET_INFO | wc -l`
if [[ $NB_LINES -gt 0 ]]; then
SERVER_LIST=''
for i in `echo $GET_INFO | sed 's/.*Node\(.*\)left the cluster.*/\1/g'`;
do SERVER_LIST="$SERVER_LIST $i"; done
echo $SERVER_LIST
CHECK="NODE_LEFT"
else
CHECK="NO_EVENT"
fi
if [[ "$CHECK" == "NODE_LEFT" ]]; then
echo "NODE LEFT EVENT: $SERVER_LIST"
exit 2
elif [[ "$CHECK" == "NO_EVENT" ]]; then
echo "No NODE LEFT Event: ${SERVER}"
exit 0
else
echo "Check failed"
exit 3
fi
Note that the script's exit codes follow the standard required for Nagios plugins:
Value
Status
Description
0
OK
The plugin was able to check the service and it appeared to be functioning properly.
1
Warning
The plugin was able to check the service, but it appeared to be above some "warning" threshold or did not working properly.
2
Critical
The plugin detected that either the service was not running or it was above some "critical" threshold.
3
Unknown
Invalid command line arguments were supplied to the plugin or low-level failures internal to the plugin occurred (such as unable to fork or open a tcp socket) that prevent it from performing the specified operation. Higher-level errors (such as name resolution errors or socket timeouts) are outside of the control of plugins and should generally NOT be reported as UNKNOWN states.
After you create the script, install it in Nagios. A number of tutorials on installing Nagios XI plugins are available on the Internet, like the one here: http://www.youtube.com/watch?v=jG1lVnire4E.
You can generalize the script to find other events by editing the REGEX pattern. Or edit the RESTURL to return other types of information.