working with live dashboard
This commit is contained in:
74
templates/drive_check_service.sh
Normal file
74
templates/drive_check_service.sh
Normal file
@ -0,0 +1,74 @@
|
||||
#!/bin/bash
|
||||
# this is a big loop to handle the database
|
||||
|
||||
exec 2> /dev/null
|
||||
while true; do
|
||||
# update active drives more frequently
|
||||
curl -s "http://172.17.0.1:5000/refresh_active_drives"
|
||||
clear
|
||||
# get all disks
|
||||
DISK_LIST=$(ls -lo /dev/sd? | awk '{print $9}')
|
||||
# process each disk
|
||||
IFS=$'\n' read -rd '' -a DISK_ARRAY <<< "$DISK_LIST"
|
||||
for DISK in "${DISK_ARRAY[@]}"; do
|
||||
# store smartctl data once
|
||||
SMART_DATA=$(smartctl -x $DISK)
|
||||
NVME_CHECK=$(echo "$SMART_DATA" | grep "NVMe Version")
|
||||
SSD_CHECK=$(echo "$SMART_DATA" | grep "Rotation Rate" | grep "Solid State")
|
||||
# if either SATA SSD or NVMe
|
||||
if [ -n "$NVME_CHECK" ] || [ -n "$SSD_CHECK" ]; then
|
||||
BLOCK_SIZE=$(fdisk -l $DISK | grep 'Sector size' | awk '{print $4}' )
|
||||
# SATA Logic
|
||||
if [ -n "$SSD_CHECK" ] ; then
|
||||
# Set Variables
|
||||
TBW=$(echo "$SMART_DATA" | grep "Logical Sectors Written" | \
|
||||
awk -v BLOCK_SIZE="$BLOCK_SIZE" '{print $4 * BLOCK_SIZE / (2 ^ 40)}')
|
||||
PLR=$(echo "$SMART_DATA" | grep Percent_Lifetime_Remain | awk '{print $4}')
|
||||
CAPACITY=$(echo "$SMART_DATA" | grep "User Capacity" | cut -d '[' -f 2 | sed 's/]//g')
|
||||
SERIAL=$(echo "$SMART_DATA" | grep "Serial Number" | cut -d ":" -f 2 | xargs)
|
||||
MODEL=$(echo "$SMART_DATA" | grep "Device Model" | cut -d ":" -f 2 | xargs)
|
||||
SMART=$(echo "$SMART_DATA" | grep "self-assessment test result" | cut -d ":" -f 2 | xargs)
|
||||
FLAVOR="SATA SSD"
|
||||
DRIVE_EXISTS=$(curl -s "http://172.17.0.1:5000/check?serial_lookup=$SERIAL" | jq .serial_number_exists)
|
||||
if [ -x "$TBW"] ; then
|
||||
TBW="unknown"
|
||||
fi
|
||||
# database handler
|
||||
if [ "$DRIVE_EXISTS" == "false" ] ; then
|
||||
H_MODEL=$(echo $MODEL | sed 's/ /%20/g')
|
||||
H_FLAVOR=$(echo $FLAVOR | sed 's/ /%20/g')
|
||||
H_CAPACITY=$(echo $CAPACITY | sed 's/ /%20/g')
|
||||
curl -s "http://172.17.0.1:5000/add_drive?serial=$SERIAL&model=$H_MODEL&flavor=$H_FLAVOR&capacity=$H_CAPACITY&TBW=$TBW&smart=$SMART"
|
||||
else
|
||||
curl -s "http://172.17.0.1:5000/update_drive?serial=$SERIAL&TBW=$TBW&smart=$SMART"
|
||||
fi
|
||||
# NVMe Logic
|
||||
elif [ -n "$NVME_CHECK" ] ; then
|
||||
# Set Variables
|
||||
MODEL=$(echo "$SMART_DATA" | grep "Model Number" | cut -d ":" -f 2 | xargs)
|
||||
SERIAL=$(echo "$SMART_DATA" | grep "Serial Number" | cut -d ":" -f 2 | xargs)
|
||||
TBW=$(echo "$SMART_DATA" | grep "Data Units Written" | sed 's/,//g' | \
|
||||
awk -v BLOCK_SIZE="$BLOCK_SIZE" '{print $4 * BLOCK_SIZE / (2 ^ 30)}')
|
||||
AVAIL_SPARE=$(echo "$SMART_DATA" | grep "Available Spare:" | cut -d ':' -f 2 | xargs)
|
||||
CAPACITY=$(echo "$SMART_DATA" | grep "amespace 1 Size" | cut -d '[' -f 2 | sed 's/]//g')
|
||||
SMART=$(echo "$SMART_DATA" | grep "self-assessment test result" | cut -d ":" -f 2 | xargs)
|
||||
FLAVOR="NVMe"
|
||||
DRIVE_EXISTS=$(curl -s "http://172.17.0.1:5000/check?serial_lookup=$SERIAL" | jq .serial_number_exists)
|
||||
if [ -x "$TBW"] ; then
|
||||
TBW="unknown"
|
||||
fi
|
||||
# database handler
|
||||
if [ "$DRIVE_EXISTS" == "false" ] ; then
|
||||
H_MODEL=$(echo $MODEL | sed 's/ /%20/g')
|
||||
H_FLAVOR=$(echo $FLAVOR | sed 's/ /%20/g')
|
||||
H_CAPACITY=$(echo $CAPACITY | sed 's/ /%20/g')
|
||||
curl -s "http://172.17.0.1:5000/add_drive?serial=$SERIAL&model=$H_MODEL&flavor=$H_FLAVOR&capacity=$H_CAPACITY&TBW=$TBW&smart=$SMART"
|
||||
else
|
||||
curl -s "http://172.17.0.1:5000/update_drive?serial=$SERIAL&TBW=$TBW&smart=$SMART"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done
|
||||
# sleep and loop again
|
||||
sleep 0.5
|
||||
done
|
||||
Reference in New Issue
Block a user