#!/bin/bash
raid1=$(egrep '^md.+raid1' /proc/mdstat| awk '{print $5, $6}' | grep -oP 'sd[a-z](?=[1-9]\[)' | sort -u | wc -l)
if [[ $raid1 > 0 ]]
then
  grubs=$(egrep '^md.+raid1' /proc/mdstat| awk '{print $5, $6}' | grep -oP 'sd[a-z](?=[1-9]\[)' | sort -u | while read drives; do dd bs=512 count=1 if=/dev/$drives 2>/dev/null |strings;done | grep -c GRUB)
  if [[ $grubs != 2 ]]
  then
    if [ -f /etc/zabbix/zabbix_agentd.conf ]
    then
      zabbix_conf="/etc/zabbix/zabbix_agentd.conf"
    elif [ -f /opt/zabbix/etc/zabbix_agentd.conf ]
    then
      zabbix_conf="/opt/zabbix/etc/zabbix_agentd.conf"
    fi

    if [ -f /usr/bin/zabbix_sender ]
    then
      zabbix_send="/usr/bin/zabbix_sender"
    elif [ -f /opt/zabbix/bin/zabbix_sender ]
    then
      zabbix_send="/opt/zabbix/bin/zabbix_sender";
    fi
    $zabbix_send -s `uname -n` -c $zabbix_conf -k eig.grub -o $grubs
  fi
fi

