Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance, fix issues #5

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 33 additions & 36 deletions adaptec-raid.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,42 @@ action=$1
part=$2

LLDControllers() {
ctrl_count=$($cli GETCONFIG 1 AL | grep "Controllers found:" | cut -f2 -d":" | sed -e 's/^ //' )
ctrl_count=$($cli GETCONFIG | grep "Controllers found:" | cut -f2 -d":" | xargs )

i=1
ctrl_json=""
while [ $i -le $ctrl_count ]
do
ctrl_model=$($cli GETCONFIG $i AD | grep "Controller Model" | cut -f2 -d":" | sed -e 's/^ //' )
ctrl_sn=$($cli GETCONFIG $i AD | grep "Controller Serial Number" | cut -f2 -d":" | sed -e 's/^ //' )
ctrl_query=$($cli GETCONFIG $i AD)
ctrl_model=$(grep "Controller Model" <<< "$ctrl_query" | cut -f2 -d":" | xargs )
ctrl_sn=$(grep "Controller Serial Number" <<< "$ctrl_query" | cut -f2 -d":" | xargs )

ctrl_info="{\"{#CTRL.ID}\":\"$i\",\"{#CTRL.MODEL}\":\"$ctrl_model\",\"{#CTRL.SN}\":\"$ctrl_sn\"},"
ctrl_json=$ctrl_json$ctrl_info

i=$((i+1))
done

ctrl_json=$(echo $ctrl_json | sed -e 's/,$//')
lld_data="{\"data\":[$ctrl_json]}"
lld_data="{\"data\":[${ctrl_json::-1}]}"

echo $lld_data
}

LLDBattery() {
# No controllers with battery on Linux machine
# NEED SIMULATE
ctrl_count=$($cli GETCONFIG 1 AL | grep "Controllers found:" | cut -f2 -d":" | sed -e 's/^ //' )
ctrl_count=$($cli GETCONFIG | grep "Controllers found:" | cut -f2 -d":" | xargs )

i=1
bt_json=""
while [ $i -le $ctrl_count ]
do
#ctrl_bt=$($cli GETCONFIG $i AD | grep "Controller Battery Information" )
bt_query=$($cli GETCONFIG $i AD)
ctrl_bt=$(grep "Controller Battery Information" <<< "$bt_query")
len=${#ctrl_bt}
if [ $len -ne 0 ]
then
bt_status=$($cli GETCONFIG $ctrl_id AD | grep -E "^\s+Status\s+[:]" | cut -f2 -d":" | sed -e 's/^ //' )
bt_status=$(grep -E "^\s+Status\s+[:]" <<< "$bt_query" | cut -f2 -d":" | xargs )
len=${#bt_status}
if [ $len -ne 0 ]
then
Expand All @@ -66,30 +67,27 @@ LLDBattery() {
i=$((i+1))
done

bt_json=$(echo $bt_json | sed -e 's/,$//')
lld_data="{\"data\":[$bt_json]}"
lld_data="{\"data\":[${bt_json::-1}]}"

echo $lld_data

#echo "{\"data\":[]}"
echo $lld_data

}

LLDLogicalDrives() {
ctrl_count=$($cli GETCONFIG 1 AL | grep "Controllers found:" | cut -f2 -d":" | sed -e 's/^ //' )
ctrl_count=$($cli GETCONFIG | grep "Controllers found:" | cut -f2 -d":" | xargs )

i=1
ld_json=""
while [ $i -le $ctrl_count ]
do
ld_count=$($cli GETCONFIG $i AD | grep "Logical devices/Failed/Degraded" | cut -f2 -d":" | cut -f1 -d"/" | sed -e 's/^ //' )

ld_ids=$($cli GETCONFIG $i LD | grep "Logical device number " | cut -f4 -d" " | sed -e 's/^ //' )
ld_ids=$($cli GETCONFIG $i LD | grep "Logical Device number " | cut -f4 -d" " | xargs )

for ld_id in $ld_ids; do
ld_name=$($cli GETCONFIG $i LD $ld_id | grep "Logical device name" | cut -f2 -d":" | sed -e 's/^ //' )
ld_raid=$($cli GETCONFIG $i LD $ld_id | grep "RAID level" | cut -f2 -d":" | sed -e 's/^ //' )
ld_query=$($cli GETCONFIG $i LD $ld_id)
ld_name=$(grep "Logical Device name" <<< "$ld_query" | cut -f2 -d":" | xargs )
ld_raid=$(grep "RAID level" <<< "$ld_query" | cut -f2 -d":" | xargs )

if [ "$ld_name" = "" ]
if [[ "$ld_name" = "" ]]
then
ld_name=$ld_id
fi
Expand All @@ -101,21 +99,21 @@ LLDLogicalDrives() {
i=$((i+1))
done

ld_json=$(echo $ld_json | sed -e 's/,$//')
lld_data="{\"data\":[$ld_json]}"
lld_data="{\"data\":[${ld_json::-1}]}"

echo $lld_data
}

LLDPhysicalDrives() {
ctrl_count=$($cli GETCONFIG 1 AL | grep "Controllers found:" | cut -f2 -d":" | sed -e 's/^ //' )
ctrl_count=$($cli GETCONFIG | grep "Controllers found:" | cut -f2 -d":" | xargs )

i=1
pd_json=""
while [ $i -le $ctrl_count ]
do
pd_list=($($cli GETCONFIG $i PD | grep "Device #" | cut -f2 -d"#" ))
pd_list_type=($($cli GETCONFIG 1 PD | grep 'Device is a' | sed -e 's/ /_/g'))
pd_query=$($cli GETCONFIG $i PD)
pd_list=($(grep "Device #" <<< "$pd_query" | cut -f2 -d"#" ))
pd_list_type=($(grep 'Device is a' <<< "$pd_query" | sed -e 's/ /_/g'))

# ToDo: NEEED CHECK IS A HARD DRIVE OR SOMETHING ELSE
for pd_id in "${pd_list[@]}"; do
Expand All @@ -130,9 +128,8 @@ LLDPhysicalDrives() {

i=$((i+1))
done

pd_json=$(echo $pd_json | sed -e 's/,$//')
lld_data="{\"data\":[$pd_json]}"

lld_data="{\"data\":[${pd_json::-1}]}"

echo $lld_data
}
Expand Down Expand Up @@ -161,10 +158,10 @@ GetControllerStatus() {
ctrl_status=""
case "$ctrl_part" in
"main")
ctrl_status=$($cli GETCONFIG $ctrl_id AD | grep "Controller Status" | cut -f2 -d":" | sed -e 's/^ //' )
ctrl_status=$($cli GETCONFIG $ctrl_id AD | grep "Controller Status" | cut -f2 -d":" | xargs )
;;
"battery")
ctrl_status=$($cli GETCONFIG $ctrl_id AD | grep -E "^\s+Status\s+[:]" | cut -f2 -d":" | sed -e 's/^ //' )
ctrl_status=$($cli GETCONFIG $ctrl_id AD | grep -E "^\s+Status\s+[:]" | cut -f2 -d":" | xargs )
;;
"temperature")
ctrl_status=$($cli GETCONFIG $ctrl_id AD | grep -E "^\s+Temperature\s+[:]" | cut -f2 -d":" | awk '{print $1}' )
Expand All @@ -178,7 +175,7 @@ GetLogicalDriveStatus() {
ctrl_id=$1
ld_id=$2

ld_status=$($cli GETCONFIG $ctrl_id LD $ld_id | grep "Status of logical device" | cut -f2 -d":" | sed -e 's/^ //' )
ld_status=$($cli GETCONFIG $ctrl_id LD $ld_id | grep "Status of Logical Device" | cut -f2 -d":" | xargs )

echo $ld_status
}
Expand All @@ -195,28 +192,28 @@ GetPhysicalDriveStatus() {
GetSmartHealth() {
disk_dev=$1

disk_health=$($cli_smart -H $disk_dev | grep "SMART Health Status" | cut -f2 -d":" | sed -e 's/^ //' )
disk_health=$($cli_smart -H $disk_dev | grep "SMART Health Status" | cut -f2 -d":" | xargs )
echo $disk_health
}

GetSmartTemp() {
disk_dev=$1

disk_temp=$($cli_smart -A $disk_dev | grep "Current Drive Temperature" | cut -f2 -d":" | cut -f1 -d"C" | sed -e 's/^ //' )
disk_temp=$($cli_smart -A $disk_dev | grep "Current Drive Temperature" | cut -f2 -d":" | cut -f1 -d"C" | xargs )
echo $disk_temp
}

GetSmartTripTemp() {
disk_dev=$1

disk_temp=$($cli_smart -A $disk_dev | grep "Drive Trip Temperature" | cut -f2 -d":" | cut -f1 -d"C" | sed -e 's/^ //' )
disk_temp=$($cli_smart -A $disk_dev | grep "Drive Trip Temperature" | cut -f2 -d":" | cut -f1 -d"C" | xargs )
echo $disk_temp
}

GetSmartDefects() {
disk_dev=$1

disk_defects=$($cli_smart -A $disk_dev | grep "Elements in grown defect list" | cut -f2 -d":" | sed -e 's/^ //' )
disk_defects=$($cli_smart -A $disk_dev | grep "Elements in grown defect list" | cut -f2 -d":" | xargs )
echo $disk_defects
}

Expand Down Expand Up @@ -272,4 +269,4 @@ case "$action" in
*)
echo "Invalid usage of script"
;;
esac
esac