Hi All!
Today im completed works with Zabbix array and disk discovering with MegaCli.
Next we should thinking about “PREPROCESSING” Zabbix function for monitoring disks via smartmontools.
Okay, posting script
#!/bin/bash
echo "{"
echo " \"data\":["
echo ""
#get count of disk arrays, needed for Bash array hacking :)
narray=`ls -l /dev/disk/by-path/ | grep -E "scsi-[0-9]:[0-9]:*:[0-9]"|grep -v part|wc -l`
#get number of disk arrays from megacli
getnarray=`/opt/MegaRAID/MegaCli/MegaCli64 -pdlist -aall -nolog|grep -E 'DiskGroup'|awk '{print$4}'|sort -n|uniq -d|sed 's/\,//'`
#compare number disk arrays with Linux Kernel Stack disks (sda, sdb, etc), needed for Smartmontools
getdisk=`echo "$getnarray"|while read i; do
ls -l /dev/disk/by-path/ | grep -E "scsi-[0-9]:[0-9]:$i:[0-9]"|grep -v part| awk -F ":" '{print($6),($7)}'|awk '{print$1,$4}'|sed 's/\.\.\/\.\.\///'
done`
#From formatted and comparision list of arrays we are complete them with disks containing on RAID adapter
result=`echo "$getdisk"|while read a b; do
/opt/MegaRAID/MegaCli/MegaCli64 -pdlist -aall -nolog|grep -A3 "DiskGroup: $a"|grep 'Device Id'|awk '{print$3}'|while read c; do
echo $c $b
done
done`
#complete JSON for Zabbix
arr=($result)
length=${#arr[*]}
echo "$result"|while read c b; do
let n=n+$narray
echo " {"
echo " \"{#DISKNAME}\":\"/dev/$b -d sat+megaraid,$c\","
echo " \"{#SMART_ENABLED}\":\"1\""
if [[ "$n" -eq "$length" ]]; then
echo " }"
else
echo " },"
fi
done
echo " ]"
echo "}"