HBA monitor script for Solaris
OK, here's a starting point. (Or a finishing point.)
I was a little bored.
:-)
Code reviews and testing feedback appreciated.
(I have limited capability to test all possibilities)
The hobbit/xymon user will need sudo access to run fcinfo. See line 8.
Regards
Vernon
$BBHOME/etc/clientlaunch.cfg
[hba]
ENVFILE $HOBBITCLIENTHOME/etc/hobbitclient.cfg
CMD $HOBBITCLIENTHOME/ext/hba.ksh
LOGFILE $HOBBITCLIENTHOME/logs/hba.log
INTERVAL 5m
(hba.ksh attached - but they sometimes get stripped)
$BBHOME/ext/hba.ksh
#!/bin/ksh
if [ -x /usr/bin/zonename ]
then
[ $(/usr/bin/zonename) == "global" ] || exit 0 # I only run on global
zones
fi
TEMPFILE=$BBTMP/hba.$$
FCINFO="/opt/csw/bin/sudo /usr/sbin/fcinfo"
COLOUR=green
CHECKSPEED=true
CHECKONLINE=true
CHECKERRS=true
date > $TEMPFILE.out
$FCINFO hba-port | grep "No Adapters Found" > /dev/null
if [ $? -eq 0 ]
then
# There are no adapters to work with.
echo "No Adapters Found" >> $TEMPFILE.out
# Let's skip the rest of the crap
else
$FCINFO hba-port | grep "HBA Port WWN:" \
| cut -d":" -f2 \
| while read WWN
do
$FCINFO hba-port -l $WWN
done >> $TEMPFILE
if [ "$CHECKONLINE" = "true" ]
then
cat $TEMPFILE | while read LINE
do
ONLINE=$(echo "$LINE" | grep "State:" | cut -d":"
-f2 | sed 's/^[ ]*//;s/[ ]*$//' )
if [ -n "$ONLINE" ]
then
if [ "$ONLINE" = "online" ]
then
echo "&green $LINE" >> $TEMPFILE.online
else
echo "&red $LINE" >> $TEMPFILE.online
COLOUR=red
fi
else
echo "$LINE" >> $TEMPFILE.online
fi
done
[ "$COLOUR" = "red" ] && echo "&red HBA not online" >>
$TEMPFILE.out
mv $TEMPFILE.online $TEMPFILE
fi
if [ "$CHECKSPEED" = "true" ]
then
cat $TEMPFILE | while read LINE
do
echo "$LINE" | grep "^HBA" > /dev/null &&
MAXSPEED="" && CURRSPEED="" && SPEEDS=""
SPEEDS=$(echo "$LINE" | grep "Supported Speeds:")
[ -n "$SPEEDS" ] && MAXSPEED=$(echo "$SPEEDS" | awk
'{ print $NF }')
CURRSPEED=$(echo "$LINE" | grep "Current Speed:" |
awk '{ print $NF }')
if [ -n "$CURRSPEED" -a "$CURRSPEED" != "$MAXSPEED"
]
then
[ "$COLOUR" != "red" ] && COLOUR="yellow"
echo "&yellow Some HBAs not at optimal speed" >>
$TEMPFILE.out
echo "$LINE" | sed "s/Current/\&yellow
Current/g" >> $TEMPFILE.speed
MAXSPEED=""
SPEEDS=""
CURRSPEED=""
else
echo "$LINE" | sed "s/Current/\&green Current/g"$TEMPFILE.speed fi done mv $TEMPFILE.speed $TEMPFILE fi
TCOLOUR=$COLOUR
COLOUR=green
if [ "$CHECKERRS" = "true" ]
then
cat $TEMPFILE | while read LINE
do
LCOL=green
ERRLINE=$(echo "$LINE" | grep "Count:")
if [ -n "$ERRLINE" ]
then
ERRCOUNT=$(echo "$ERRLINE" | cut -d":" -f2)
[ $ERRCOUNT -le 2 ] && LCOL=green && echo "&$LCOL $LINE" >>
$TEMPFILE.err
[ $ERRCOUNT -gt 2 -a $ERRCOUNT -le 100 ] && LCOL=yellow && echo
"&$LCOL $LINE" >> $TEMPFILE.err
[ $ERRCOUNT -gt 100 ] && LCOL=red && echo "&$LCOL $LINE" >>
$TEMPFILE.err
else
echo "$LINE" >> $TEMPFILE.err
fi
[ "$LCOL" = "red" ]&& COLOUR=red
[ "$LCOL" = "yellow" -a "$COLOUR" != "red" ] && COLOUR=yellow
done
[ "$COLOUR" = "red" ] && echo "&red Critical error count detected" >>
$TEMPFILE.out
[ "$COLOUR" = "yellow" ] && echo "&yellow High error count detected"$TEMPFILE.out mv $TEMPFILE.err $TEMPFILE fi
[ "$TCOLOUR" = "red" ] && COLOUR="red"
[ "$TCOLOUR" = "yellow" -a "$COLOUR" != "red" ] && COLOUR= "yellow"
cat $TEMPFILE | while read LINE
do
echo "$LINE" | grep "HBA Port" > /dev/null
if [ $? -eq 0 ]
then
echo "<b>" >> $TEMPFILE.out
echo "$LINE</b>" >> $TEMPFILE.out
else
echo "$LINE" >> $TEMPFILE.out
fi
done
fi
$BB $BBDISP "status $MACHINE.hba $COLOUR $(cat $TEMPFILE.out)"
rm $TEMPFILE $TEMPFILE.out 2> /dev/null
On Tue, Aug 10, 2010 at 11:17 AM, Vernon Everett
<user-b3f8dacb72c8@xymon.invalid>wrote:
Wrote a script a long time ago, in a contract far far away...... Went looking for it after my last posting, and I can't find it. :-( From memory, it was very rough, and didn't really do much, besides provide visibility, and check state and error counts. I think the key information gathering command was something like this fcinfo hba-port | grep "HBA Port WWN:" \ | cut -d":" -f2 \ | while read WWN; do fcinfo hba-port -l $WWN; done I bunged that into a temp file, and then did a little creative grepping for stuff like "State:" and "Current Speed:" YMMV If you want to collaborate on this one, I have a few spare cycles in my current contract. If you are really busy, it looks interesting enough that I might just run with it :-) (It may also be useful in my environment) Cheers V On Tue, Aug 10, 2010 at 10:04 AM, Vernon Everett <user-b3f8dacb72c8@xymon.invalidwrote:What are you looking to know? On Mon, Aug 9, 2010 at 10:14 PM, Kevin Kelly <user-46671a9fcf56@xymon.invalid>wrote:Does anyone know of a script that monitors HBA in a Solaris environment? Just thought I would check before I spend time on creating one. Thanks in Advanced! -Kevin This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email
Attachments (1)