#!/bin/bash
#
#==============================================================
#
#  Abs:  retrieve OpenManagement info
#
#  Name: omSrvSts [node] 
#
#  Will get status updates for:
#	Main System Chassis
#	Storage Controller
#
# Output values:
#            	0 = Good status
#      		1 = Non-Critical
#		2 = Error
#
# Output value: 1st number Main system chassis
#               2nd number storage controller
#
# ex) 01   = Main system is good 
#            storage controller is Non-Critical
#
#
# Created: 29-Sep-2009; Brobeck
#--------------------------------------------------------------
#
if [ "$1" = "" ] 
  then
        NODE=`uname -n`
  else
	NODE=$1
fi
OMREPORT="/opt/dell/srvadmin/sbin/omreport"
#
# Get the Main system chassis status
#
REGEX="'Main System Chassis'"
SSH="ssh -x"
MSC=`$SSH $NODE "$OMREPORT system | grep -m1 $REGEX" | awk '{print $1}'`

# 
# Get the Storage controller status
#
REGEX="'Status'"
CS=`$SSH $NODE "$OMREPORT storage controller | grep -m1 $REGEX" | awk '{print$3}'`
#
# Set the values:
#            	0 = Good status
#      		1 = Non-Critical
#		2 = Error
#
# Output value: 1st number Main system chassis
#               2nd number storage controller
#
# ex) 01   = Main system is good - storage controller is Non-Critical
#

if [ "$MSC" = Ok ]
  then
	MSC=0
  else
    if [ "$MSC" = "Non-Critical" ]
      then
	 MSC=1
       else	
	 MSC=2
    fi
fi

if [ "$CS" = "Ok" ]
  then
	CS=0
  else
    if [ "$CS" = "Non-Critical" ]
       then
	  CS=1
       else
	  CS=2
    fi
fi
printf "$MSC$CS\n"
