Pages

Bài đăng phổ biến

Showing posts with label Monitor hardisk on dell server with small bash script. Show all posts
Showing posts with label Monitor hardisk on dell server with small bash script. Show all posts

Thursday, October 18, 2012

Monitor hardisk on dell server with small bash script


This is a my small scirpt (run it as cron),it will send to zabbix status Ok or Fail of your physical disk on Dell server :

Dell.sh

#!/bin/bash
#Writed by nhanns[@]vng[dot]com[dot]vn -nhannguyen[@]0937686468[dot]com
#skype: nguyen_si_nhan
#Program'll send alert status to zabbix

#Check number controller
[ ! -f "/opt/dell/srvadmin/bin/omreport" ] && { echo "omreport:file not found-please install hardware monitor for Dell"; exit 1; }
Controller=0
/opt/dell/srvadmin/bin/omreport storage controller >/tmp/controller.tmp
_file1="/tmp/controller.tmp"
#check empty file
if [ ! -s "$_file1" ]
then
echo "Can not run on this server"
exit 2
fi
while read line; do
    Bool=0
    if [[ "$line" = ID* ]]; then
        Bool=1
        (( Controller++ ))
        # do something with  ?
    fi
done < /tmp/controller.tmp

#Export to file status of physical disk
i=0
rm -f /tmp/dellstatus.log;
while (( i < Controller )) ; do
/opt/dell/srvadmin/bin/omreport storage pdisk controller=$i >> /tmp/dellstatus.log
  (( ++i ))
done

_file2="/tmp/dellstatus.log"
if [ ! -s "$_file2" ]
then
echo "Can not run on this server"
exit 3
fi

Failstatus=0
statusOK=0
while read line; do
    BoolSt=0
BoolOk=0
   if [[ "$line" = Status* ]]; then
        BoolSt=1
       (( Failstatus++ ))
       # do something with ... ?
   fi
  if [[ "$line" = *Ok* ]]; then
        BoolOk=1
       (( statusOk++ ))
       # do something with  ...?
      fi
          if [[ "$line" = *Non-Critical* ]]; then
                BoolOk=1
                (( statusOk++ ))
                # do something with  ...?
           fi


done < /tmp/dellstatus.log
#echo "There were Failstatus $Failstatus Status ."

#echo "There were  statusOk $statusOk Ok ."

# Problem = ` $Failstatus - $statusOk `
#let Problem=$Failstatus - $statusOk
#echo 'There are'
#echo `expr  $Failstatus - $statusOk `
/opt/zabbix/bin/zabbix_sender -c /opt/check.conf -k hddstatus -o `expr  $Failstatus - $statusOk`