From 0c015deb45b6faa7ced01e0f5946edd6237d0bdb Mon Sep 17 00:00:00 2001 From: badfiles Date: Wed, 20 Nov 2019 20:09:03 +0300 Subject: [PATCH 1/5] fix battery status; --- adaptec-raid.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/adaptec-raid.sh b/adaptec-raid.sh index 457776f..3524594 100644 --- a/adaptec-raid.sh +++ b/adaptec-raid.sh @@ -51,15 +51,15 @@ LLDBattery() { bt_json="" while [ $i -le $ctrl_count ] do - #ctrl_bt=$($cli GETCONFIG $i AD | grep "Controller Battery Information" ) + ctrl_bt=$($cli GETCONFIG $i AD | grep "Controller Battery Information" ) 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=$($cli GETCONFIG $i AD | grep -E "^\s+Status\s+[:]" | cut -f2 -d":" | sed -e 's/^ //' ) len=${#bt_status} if [ $len -ne 0 ] then - bt_info="{\"{#CTRL.ID}\":\"$i\",\"{#CTRL.BATTERY}\":\"$i\"}," + bt_info="{\"{#CTRL.ID}\":\"$i\",\"{#CTRL.BATTERY}\":\"$bt_status\"}," bt_json=$bt_json$bt_info fi fi @@ -83,7 +83,7 @@ LLDLogicalDrives() { 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" " | sed -e 's/^ //' ) 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/^ //' ) @@ -272,4 +272,4 @@ case "$action" in *) echo "Invalid usage of script" ;; -esac \ No newline at end of file +esac From f8593b3e14ebbea1a56c9786e36ad9845f645091 Mon Sep 17 00:00:00 2001 From: badfiles Date: Thu, 21 Nov 2019 10:10:37 +0300 Subject: [PATCH 2/5] fix CTRL.BATTERY value --- adaptec-raid.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adaptec-raid.sh b/adaptec-raid.sh index 3524594..63620c9 100644 --- a/adaptec-raid.sh +++ b/adaptec-raid.sh @@ -59,7 +59,7 @@ LLDBattery() { len=${#bt_status} if [ $len -ne 0 ] then - bt_info="{\"{#CTRL.ID}\":\"$i\",\"{#CTRL.BATTERY}\":\"$bt_status\"}," + bt_info="{\"{#CTRL.ID}\":\"$i\",\"{#CTRL.BATTERY}\":\"$i\"}," bt_json=$bt_json$bt_info fi fi From 631e044b50bf19fe2469717ac5d5a78ed75475a0 Mon Sep 17 00:00:00 2001 From: badfiles Date: Thu, 21 Nov 2019 15:58:22 +0300 Subject: [PATCH 3/5] improve performance --- adaptec-raid.sh | 70 ++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 38 deletions(-) diff --git a/adaptec-raid.sh b/adaptec-raid.sh index 63620c9..53afafa 100644 --- a/adaptec-raid.sh +++ b/adaptec-raid.sh @@ -17,18 +17,16 @@ cli='/usr/local/sbin/arcconf' cli_sg='/usr/bin/sg_scan' cli_smart='/usr/sbin/smartctl' -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 @@ -36,8 +34,7 @@ LLDControllers() { 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 } @@ -45,17 +42,18 @@ LLDControllers() { 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 $i 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 @@ -66,30 +64,27 @@ LLDBattery() { i=$((i+1)) done - bt_json=$(echo $bt_json | sed -e 's/,$//') - lld_data="{\"data\":[$bt_json]}" - - echo $lld_data + lld_data="{\"data\":[${bt_json::-1}]}" - #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 @@ -101,21 +96,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 @@ -130,9 +125,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 } @@ -161,10 +155,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}' ) @@ -178,7 +172,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 } @@ -195,28 +189,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 } From a889f21e3fa84d1db27b5bd663860b85680ecf61 Mon Sep 17 00:00:00 2001 From: badfiles Date: Thu, 21 Nov 2019 15:59:59 +0300 Subject: [PATCH 4/5] add missing vars --- adaptec-raid.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/adaptec-raid.sh b/adaptec-raid.sh index 53afafa..6789e75 100644 --- a/adaptec-raid.sh +++ b/adaptec-raid.sh @@ -13,6 +13,9 @@ # Github: https://github.com/GOID1989/zbx-adaptec-raid # +action=$1 +part=$2 + cli='/usr/local/sbin/arcconf' cli_sg='/usr/bin/sg_scan' cli_smart='/usr/sbin/smartctl' From df7a25c31bc5e1da2f39f964aee9bce21a2cb247 Mon Sep 17 00:00:00 2001 From: badfiles Date: Thu, 21 Nov 2019 16:00:48 +0300 Subject: [PATCH 5/5] add missing vars --- adaptec-raid.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/adaptec-raid.sh b/adaptec-raid.sh index 6789e75..e4d1193 100644 --- a/adaptec-raid.sh +++ b/adaptec-raid.sh @@ -13,13 +13,13 @@ # Github: https://github.com/GOID1989/zbx-adaptec-raid # -action=$1 -part=$2 - cli='/usr/local/sbin/arcconf' cli_sg='/usr/bin/sg_scan' cli_smart='/usr/sbin/smartctl' +action=$1 +part=$2 + LLDControllers() { ctrl_count=$($cli GETCONFIG | grep "Controllers found:" | cut -f2 -d":" | xargs )