Commit 524c0524 authored by Fulvio Galeazzi's avatar Fulvio Galeazzi
Browse files

2018-02-26: First try at script to discover and monitor DELL storage.

parent 1d0f88f3
#! /bin/bash
#
# Name: zbxDellStorageDeviceDiscover
#
# Get Dell MD38XX storage server metrics and send to Zabbix using zabbix_sender
#
# Author: Fulvio Galeazzi
#
# Heavily based on:
# zbxApacheStatusCheck: written by Rodrigo Luis Silva
# zapache: https://github.com/lorf/zapache
# ApacheStatsForZabbix: https://github.com/gpmidi/zabbix-apache-stats
#
name="zbxDellStorageStatusCheck"
version="0.1"
# Test if your getopt(1) is this enhanced version or an old version
getopt --test > /dev/null
if [[ $? != 4 ]]; then
echo "`getopt --test` failed in this environment."
exit 1
fi
# Help function
function usage()
{
echo "
$0 $version
Usage: $0 [Options]
This script collect statistics from Apache status page, write to a temporary file
and send using zabbix_sender, the script will do only one request per execution.
License: GPL
Options:
--version show version and exit
-h, --help show this help page and exit
-e, --check Skip syntax checking: useful for crontab
once functionality has been ascertained
-p PATHBIN, --path=PATHBIN
Full path of SMcli executable
-m, --match=String Filter Storage Array name according to String
-w, --want String1[,String2[,String3]]
List of words identifying storage objects
to query information for. Defaults to
Storage,RAID,Disk
(note that Disk matches both Group and Pool)
--timeout=seconds Connection timeout
[default: 30]
-d, --debug Run using Debug mode
-t, --test Do not send data, simply test, use with --debug
"
}
# Define some default values
HOST=localhost
DEBUG=0
TEST=1
MONINTERVAL=1
PATHBIN="`which SMcli > /dev/null`"
TIMEOUT=30
WANTOBJECTS="Storage,RAID,Disk"
# Use getopt(1) program to parse command line options
SHORT=vhep:m:w:dt
LONG=version,help,check,path:,match:,want:,timeout:,debug,test
PARSED=`getopt --options $SHORT --longoptions $LONG --name "$0" -- "$@"`
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
eval set -- "$PARSED"
while true; do
case "$1" in
-v|--version)
echo "$name $version"
exit 0
;;
-h|--help)
usage
exit 0
;;
-e|--check)
CHECKSYNTAX="-e"
shift
;;
-p|--path)
PATHBIN="$2"
shift 2
;;
-m|--match)
MATCHSTR="$2"
shift 2
;;
-w|--want)
WANTOBJECTS="$2"
shift 2
;;
--timeout)
TIMEOUT="$2"
shift 2
;;
-d|--debug)
DEBUG=1
shift
;;
-t|--test)
TEST=1
shift
;;
--)
shift
break
;;
*)
usage
exit 3
;;
esac
done
# Temporary files
STATUSFILE=`mktemp`
SENDERFILE=`mktemp`
if [[ -z $CONFIGFILE ]]; then
CONFIGFILE=`mktemp`
tmpCONFIGFILE=1
echo "$DEFAULTCONFIG" > $CONFIGFILE
fi
KNOWNARRAYS=`mktemp`
GET_CMD="$PATHBIN -d -i > $KNOWNARRAYS"
eval $GET_CMD
RET_VAL=$?
if [[ $RET_VAL = 0 ]]; then
cat $KNOWNARRAYS
index=0
# 1 is with ','
raidCtrlArray1=()
# 2 is with ' '
raidCtrlArray2=()
devNameArray=()
while read aLine ; do
# Strip leading and trailing space, replace blanks with comma
aNiceLine=`echo $aLine | sed -e 's/^\s\+//' -e 's/\s\+$//' -e 's/\s\+/,/g'`
firstWord=${aNiceLine%%,*}
if [[ -z "$firstWord" || ${firstWord} == *"SMcli"* ]]; then
continue
fi
echo "First: -->${firstWord}<--"
if [[ ! -z "$MATCHSTR" && ! "$aLine" == *"$MATCHSTR"* ]]; then
continue
fi
echo "Line: ${aNiceLine}"
devNameArray[$index]="$firstWord"
tmpString="${aNiceLine#*,}"
raidCtrlArray1[$index]="$tmpString"
raidCtrlArray2[$index]="${tmpString//,/ }"
index=$(($index+1))
done < $KNOWNARRAYS
echo "Dev: ${devNameArray[@]}"
echo "Raid1: ${raidCtrlArray1[@]}"
echo "Raid2: ${raidCtrlArray2[@]}"
IFS=',' read -a wantObjArr <<< "$WANTOBJECTS"
for (( idx=0; idx<${#devNameArray[@]}; idx++)); do
raidList="${raidCtrlArray2[$idx]}"
STATUSFILE=`mktemp`
GET_CMD="$PATHBIN $raidList -c 'set session performanceMonitorInterval=3 performanceMonitorIterations=1 ; save storageArray performanceStats file=\"$STATUSFILE\";' > /dev/null"
echo "Execute: $GET_CMD"
# get data from server
eval $GET_CMD
RET_VAL=$?
if [[ $RET_VAL = 0 ]]; then
while read STATUSLINE
do
# read the status file to get all relevant statistics
# Replaces all occurrences of " character
aLine=`echo ${STATUSLINE//\"}`
# Split line into fields
IFS=',' read -a arrayLine <<< "$aLine"
# Skip not-so-interesting lines
firstField="${arrayLine[0]}"
firstWord=`echo ${arrayLine[0]} | awk '{print $1}'`
if [[ -z "$firstWord" || ! "${wantObjArr[@]}" =~ "$firstWord" ]]; then
continue
fi
tmpString=`echo $firstField | awk '{print $1" "$2}'`
deviceType=${tmpString// /_}
deviceName=${firstField:${#tmpString}+1}
deviceName=${deviceName// /_}
echo "RAID: ${raidCtrlArray1[$idx]} Want: $WANTOBJECTS Type: $deviceType Name: $deviceName"
done < $STATUSFILE
fi
rm $STATUSFILE
done
fi
# DEBUG
if [[ $DEBUG = 1 ]]; then
echo -e "\n########################################\n"
echo -e "Statistics available on your server:\n"
cat $STATUSFILE | awk -F: '{print $1}'
echo -e "\n########################################\n"
echo -e "Statistics that I am collecting:\n"
cat $CONFIGFILE
echo -e "\n########################################\n"
echo -e "Metrics to be sent\n"
SENDERFILEDEBUG=`mktemp`
echo '"SERVER" "METRIC" VALUE' >> $SENDERFILEDEBUG
cat $SENDERFILE >> $SENDERFILEDEBUG
column -t -s'\"' $SENDERFILEDEBUG
rm -f $SENDERFILEDEBUG
echo -e "\n########################################\n"
echo -e "Parameters\n"
echo "--check=$CHECKSYNTAX"
echo "--path=$PATHBIN"
echo "--raid=$raidList"
echo "--interval=$MONINTERVAL"
echo "--zabbixserver=$ZABBIXSERVER"
echo "--sender=$SENDER"
echo "--zabbixport=$ZABBIXPORT"
echo "--zabbixsource=$ZABBIXSOURCE"
echo "--timeout=$TIMEOUT"
echo -e "\n wantObjects=${wantObjArr[@]}\n"
echo -e "\n########################################\n"
echo -e "Command line to collect data\n"
echo -e "$GET_CMD\n"
echo -e "Command line to send data to Zabbix\n"
echo -e "$SENDER_CMD\n"
if [[ $TEST = 0 ]]; then
echo -e "\n########################################\n"
echo -e "zabbix_sender output\n"
eval $SENDER_CMD
echo -e "\n"
fi
else
[[ $TEST = 0 ]] && eval $SENDER_CMD > /dev/null
fi
# Housekeeping
rm -f $STATUSFILE
# rm -f $SENDERFILE
if [[ -n $tmpCONFIGFILE ]]; then
rm -f $CONFIGFILE
fi
#! /bin/bash
#
# Name: zbxDellStorageStatusCheck
#
# Get Dell MD3X60 storage server metrics and send to Zabbix using zabbix_sender
#
# Author: Fulvio Galeazzi
#
# Heavily based on:
# zbxApacheStatusCheck: written by Rodrigo Luis Silva
# zapache: https://github.com/lorf/zapache
# ApacheStatsForZabbix: https://github.com/gpmidi/zabbix-apache-stats
#
name="zbxDellStorageStatusCheck"
version="0.1"
# Test if your getopt(1) is this enhanced version or an old version
getopt --test > /dev/null
if [[ $? != 4 ]]; then
echo "`getopt --test` failed in this environment."
exit 1
fi
# Help function
function usage()
{
echo "
$0 $version
Usage: $0 [Options]
This script collect statistics from Apache status page, write to a temporary file
and send using zabbix_sender, the script will do only one request per execution.
License: GPL
Options:
--version show version and exit
-h, --help show this help page and exit
-e, --check Skip syntax checking: useful for crontab
once functionality has been ascertained
-p PATHBIN, --path=PATHBIN
Full path of SMcli executable
-r, --raid IP1[,IP2] List of IPs or DNS names: all addresses
should belong to the same controller
-w, --want String1[,String2[,String3]]
List of words identifying storage objects
to query information for. Defaults to
Storage,RAID,Disk
(note that Disk matches both Group and Pool)
-i TIME, --interval=ITIME
Number of seconds to accumulate data for,
default is 3
-z ZABBIXSERVER, --zabbixserver=ZABBIXSERVER
Hostname or IP address of Zabbix server
[default: localhost]
-s SENDERLOC, --sender=SENDERLOC
Path of zabbix_sender binary
[default: /usr/bin/zabbix_sender]
-q ZABBIXPORT, --zabbixport=ZABBIXPORT
Specify port number of Zabbix server
trapper running on the server
[default: 10051]
-c ZABBIXSOURCE, --zabbixsource=ZABBIXSOURCE
Specify host name the item belongs to
(as registered in Zabbix frontend)
[default: localhost]
--TIMEOUT=seconds Connection timeout
[default: 30]
-k CONFIGFILE, --config=CONFIGFILE
Specify the file with the list of statistics to collect
File format is a list of lines with the same order as the
fields in SMcli output, of the form: <variableName> <0|1>
<variableName> should match Zabbix item key
<0|1> the relevant statistics shouldn't/should be collected
[default: run $0 --dumpconfig]
--dumpconfig Show the actual config
-d, --debug Run using Debug mode
-t, --test Do not send data, simply test, use with --debug
"
}
# Define some default values
HOST=localhost
PORT=80
PROTO=http
ZABBIXSERVER=localhost
SENDER=/usr/bin/zabbix_sender
DEBUG=0
TEST=1
ZABBIXPORT=10051
ZABBIXSOURCE=localhost
MONINTERVAL=3
PATHBIN="`which SMcli > /dev/null`"
TIMEOUT=30
DEFAULTCONFIG="name,1
iotot,1
readfrac,1
ctrlcachehitr,1
ctrlcachehitw,1
ssdcachehitr,1
curMBs,0
maxMBs,1
curIOs,0
maxIOs,1
minIOs,0
avgIOs,0
minMBs,0
avgMBs,0
curIOlat,0
maxIOlat,0
minIOlat,0
avgIOlat,1"
WANTOBJECTS="Storage,RAID,Disk"
# Use getopt(1) program to parse command line options
SHORT=vhep:r:w:i:z:s:q:c:k:dt
LONG=version,help,check,path:,raid:,want:,interval:,zabbixserver:,sender:,zabbixport:,zabbixsource:,timeout:,config:,debug,dumpconfig,test
PARSED=`getopt --options $SHORT --longoptions $LONG --name "$0" -- "$@"`
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
eval set -- "$PARSED"
while true; do
case "$1" in
-v|--version)
echo "$name $version"
exit 0
;;
-h|--help)
usage
exit 0
;;
-e|--check)
CHECKSYNTAX="-e"
shift
;;
-p|--path)
PATHBIN="$2"
shift 2
;;
-r|--raid)
RAIDCTRL="$2"
shift 2
;;
-w|--want)
WANTOBJECTS="$2"
shift 2
;;
-i|--interval)
MONINTERVAL="$2"
shift 2
;;
-z|--zabbixserver)
ZABBIXSERVER="$2"
shift 2
;;
-s|--sender)
SENDER="$2"
shift 2
;;
-q|--zabbixport)
ZABBIXPORT="$2"
shift 2
;;
-c|--zabbixsource)
ZABBIXSOURCE="$2"
shift 2
;;
--timeout)
TIMEOUT="$2"
shift 2
;;
-k|--config)
CONFIGFILE="$2"
shift 2
;;
-d|--debug)
DEBUG=1
shift
;;
--dumpconfig)
echo "$DEFAULTCONFIG"
exit 0
;;
-t|--test)
TEST=1
shift
;;
--)
shift
break
;;
*)
usage
exit 3
;;
esac
done
# Temporary files
STATUSFILE=`mktemp`
SENDERFILE=`mktemp`
if [[ -z $CONFIGFILE ]]; then
CONFIGFILE=`mktemp`
tmpCONFIGFILE=1
echo "$DEFAULTCONFIG" > $CONFIGFILE
fi
raidList=`echo $RAIDCTRL | sed -e 's/,/ /'`
IFS=',' read -a wantObjArr <<< "$WANTOBJECTS"
GET_CMD="$PATHBIN $raidList $CHECKSYNTAX -c 'set session performanceMonitorInterval=$MONINTERVAL performanceMonitorIterations=1 ; save storageArray performanceStats file=\"$STATUSFILE\";' > /dev/null"
# get data from server
eval $GET_CMD
RET_VAL=$?
# in case of error, just send [failed] = 1
# otherwise send all collected data
if [[ $RET_VAL = 0 ]]; then
echo "\"$ZABBIXSOURCE\" \"custom.dellmd38xx[failed]\" 0" >> $SENDERFILE
index=0
zbxKey=()
zbxWant=()
while IFS=',' read -a aItem ; do
if [[ ${aItem[0]} ]]; then
zbxKey[$index]="${aItem[0]}"
zbxWant[$index]="${aItem[1]}"
index=$(($index+1))
fi
done < $CONFIGFILE
# read the status file to get all relevant statistics
while read STATUSLINE
do
# Replaces all occurrences of " character
aLine=`echo ${STATUSLINE//\"}`
# Split line into fields
IFS=',' read -a arrayLine <<< "$aLine"
# Skip not-so-interesting lines
firstField="${arrayLine[0]}"
firstWord=`echo ${arrayLine[0]} | awk '{print $1}'`
if [[ -z "$firstWord" || ! "${wantObjArr[@]}" =~ "$firstWord" ]]; then
continue
fi
tmpString=`echo $firstField | awk '{print $1" "$2}'`
deviceType=${tmpString// /_}
deviceName=${firstField:${#tmpString}+1}
deviceName=${deviceName// /_}
for (( idx=1; idx<${#zbxKey[@]}; idx++)); do
if [ ! "$zbxWant[$idx]" ]; then
continue
fi
echo -n "\"$ZABBIXSOURCE\" \"custom.dellmd38xx.${zbxKey[$idx]}[${deviceType},${deviceName}]\" " >> $SENDERFILE
echo ${arrayLine[$idx]} >> $SENDERFILE
done
done < $STATUSFILE
else
echo "\"$ZABBIXSOURCE\" \"custom.dellmd38xx[failed]\" 1" >> $SENDERFILE
fi
# Send all information to Zabbix using zbbix_sender
SENDER_CMD="$SENDER -v --zabbix-server $ZABBIXSERVER --port $ZABBIXPORT --input-file $SENDERFILE"
# DEBUG
if [[ $DEBUG = 1 ]]; then
echo -e "\n########################################\n"
echo -e "Statistics available on your server:\n"
cat $STATUSFILE | awk -F: '{print $1}'
echo -e "\n########################################\n"
echo -e "Statistics that I am collecting:\n"
cat $CONFIGFILE
echo -e "\n########################################\n"
echo -e "Metrics to be sent\n"
SENDERFILEDEBUG=`mktemp`
echo '"SERVER" "METRIC" VALUE' >> $SENDERFILEDEBUG
cat $SENDERFILE >> $SENDERFILEDEBUG
column -t -s'\"' $SENDERFILEDEBUG
rm -f $SENDERFILEDEBUG
echo -e "\n########################################\n"
echo -e "Parameters\n"
echo "--check=$CHECKSYNTAX"
echo "--path=$PATHBIN"
echo "--raid=$raidList"
echo "--interval=$MONINTERVAL"
echo "--zabbixserver=$ZABBIXSERVER"
echo "--sender=$SENDER"
echo "--zabbixport=$ZABBIXPORT"
echo "--zabbixsource=$ZABBIXSOURCE"
echo "--timeout=$TIMEOUT"
echo -e "\n wantObjects=${wantObjArr[@]}\n"
echo -e "\n########################################\n"
echo -e "Command line to collect data\n"
echo -e "$GET_CMD\n"
echo -e "Command line to send data to Zabbix\n"
echo -e "$SENDER_CMD\n"
if [[ $TEST = 0 ]]; then
echo -e "\n########################################\n"
echo -e "zabbix_sender output\n"
eval $SENDER_CMD
echo -e "\n"
fi
else
[[ $TEST = 0 ]] && eval $SENDER_CMD > /dev/null
fi
# Housekeeping
rm -f $STATUSFILE
# rm -f $SENDERFILE
if [[ -n $tmpCONFIGFILE ]]; then
rm -f $CONFIGFILE
fi
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment