RAID Monitoring with storcli

In this article, we'll show you how to easily monitor your RAID in Linux with storcli so you know when a faulty disk needs to be replaced.

Monitoring

storcli64 /c0 show all

(c0 indicates which controller you're checking, it's usually 0 if you only have one)

In the script below we check for controller status and if its "optimal" or "needs attention".

If the controller has status "needs attention" you have to investigate further with above command to find out whats the issue.

Automate

Things you need:

  • SFTP client (scp/WinSCP)
  • Alien package (if you're using a distribution that doesn't use .rpm packages)
  • jq package
  • Working SMTP client like postfix
  • Editor (nano or vim)
  1. Start by downloading and unpacking StorCLI from the Broadcom website (https://docs.broadcom.com/docs/1232743397). Unfortunately, you cannot download this directly using wget. You'll need to download it via a web browser and then transfer it to your server using scp or WinSCP.

  2. Install needed packages

apt-get update
apt-get install alien jq
  1. Convert storcli .rpm to .deb
alien storcli-007.2705.0000.0000-1.noarch.rpm
  1. Once you have a .deb version of the file, install it.
dpkg -i storcli_007.2705.0000.0000-2_all.deb
  1. Once the installation is complete, move StorCli64 to /usr/local/bin/
mv /opt/MegaRAID/storcli/storcli64 /usr/local/bin/
  1. Create a file named raidcheck.sh in folder of your choice and edit the file with vim or nano. Paste the following code.
#!/bin/bash

FROM_EMAIL="from@example.com"
TO_EMAIL="to@example.com"
SUBJECT="Controller Status Alert"

send_email() {
    local subject="$1"
    local body="$2"

    {
        echo "Subject: $subject"
        echo "To: $TO_EMAIL"
        echo "From: $FROM_EMAIL"
        echo "MIME-Version: 1.0"
        echo "Content-Type: text/plain; charset=UTF-8"
        echo ""
        echo "$body"
    } | sendmail -t -f "$FROM_EMAIL"
}

status_json=$(storcli64 /call show all j)

controller_status=$(echo "$status_json" | jq -r '.Controllers[0]."Response Data".Status."Controller Status"')

echo "Current Controller Status: $controller_status"

if [[ "$controller_status" != "Optimal" ]]; then
        message="Warning: The controller status is not Optimal.\n\nCurrent Status: $controller_status\n\nDetails:\n$status_json"

        send_email "$SUBJECT" "$message"
    echo "Email notification sent about the controller's non-optimal status."
else
    echo "------------------------------------"
    echo "Controller status is Optimal."
fi

You need to change the "from" and "to" email addresses at the beginning of the script.

  1. Make raidcheck.sh executable.
chmod +x raidcheck.sh
  1. Open crontab and paste the following. Change patch to where your script are located.
10  *   *   *   *   /path/to/your/script/raidcheck.sh

Notes

We recommend that you test the script to ensure it truly works before putting it into live operation. The script is designed to fit most distributions, but there's no guarantee it will suit your specific server.

Hittar du inte det du söker?

Kontakta oss gärna för mer information. Vi hjälper dig att komma fram till den bästa lösningen för dina behov.

Skicka e-post Ring 0200-23 88 00