# RAID monitoring with StorCLI

***

StorCLI is a tool from Broadcom for monitoring and querying MegaRAID controller cards. Using this tool, you can view the RAID controller status on your dedicated server and be alerted if a disk is failing and needs replacement.

## Installing the tools

Start by downloading StorCLI from Broadcom's 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.

Once you have transferred the zip file to your server, you'll need to unpack it twice—there's a zip file inside the zip file:

{% code title="Multiple commands" %}

```
unzip 007.2705.0000.0000_storcli_rel.zip
cd storcli_rel
unzip Unified_storcli_all_os.zip
```

{% endcode %}

Next, you need to install the package. Broadcom only provides an RPM file, so depending on which Linux distribution you are using, you need to convert the package first. If you are using Fedora, AlmaLinux, or CentOS, no conversion is needed.

{% tabs %}
{% tab title="Fedora/AlmaLinux" %}
If the server is running Fedora or AlmaLinux, you can go ahead and install the package:

{% code title="Multiple commands" %}

```
cd Unified_storcli_all_os/Linux
sudo dnf install ./storcli-007.2705.0000.0000-1.noarch.rpm
```

{% endcode %}
{% endtab %}

{% tab title="Debian/Ubuntu" %}
If the server is using Debian or Ubuntu, you first need to convert the RPM package to a DEB package using `alien`. Start by installing `alien`:

{% code title="Command" %}

```
sudo apt install alien
```

{% endcode %}

Next, convert the RPM package and install it:

{% code title="Multiple commands" %}

```
cd Unified_storcli_all_os/Linux
alien storcli-007.2705.0000.0000-1.noarch.rpm
sudo apt install ./storcli_007.2705.0000.0000-2_all.deb
```

{% endcode %}
{% endtab %}
{% endtabs %}

Once the installation is complete, move the binary `storcli64` to `/usr/local/bin/`.

{% code title="Command" %}

```
sudo mv /opt/MegaRAID/storcli/storcli64 /usr/local/bin/
```

{% endcode %}

You'll also need `jq` to automate the monitoring of the RAID controller. Install the package as shown below, depending on your distribution.

{% tabs %}
{% tab title="Fedora/AlmaLinux" %}
{% code title="Command" %}

```
sudo dnf install jq
```

{% endcode %}
{% endtab %}

{% tab title="Debian/Ubuntu" %}
{% code title="Command" %}

```
sudo apt install jq
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Quering the RAID controller

{% code title="Command" %}

```
sudo storcli64 /c0 show all
```

{% endcode %}

In the above command, `c0` indicates which controller you're checking; it's usually 0 if you only have one.

Before creating the monitoring script, you can check the status of your RAID controller using the following command. If everything is fine, it should return "Optimal". If something is wrong, it returns "Needs attention".

{% code title="Command" %}

```
sudo storcli64 /call show all j | jq -r '.Controllers[0]."Response Data".Status."Controller Status"'
```

{% endcode %}

## Automating the monitoring

The script below will send you an email if the status is not "Optimal".

For the script to work, you'll need a fully working SMTP server installed, such as Postfix. See the article [Sending email from your server using Postfix](/products/compute/guides-for-server-management/sending-email-from-your-server-using-postfix.md) for information on how to set up your own Postfix server.

Next, create a file called `raidcheck.sh` in a directory of your choice and edit the file with `vim` or `nano`. Paste the following code:

{% code title="raidcheck.sh" %}

```bash
#!/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
```

{% endcode %}

You need to change the `FROM_EMAIL` and `TO_EMAIL` variables at the beginning of the script to match your email address and the sender's email address.

You also need to make `raidcheck.sh` executable:

{% code title="Command" %}

```
chmod +x raidcheck.sh
```

{% endcode %}

Next, you'll need to add the script to root's crontab (since `storcli64` requires root permissions to access the controller). You can open root's crontab either by using `sudo crontab -e`, or by first switching to root with `su`, and then running `crontab -e`.

Once root's crontab is open, paste the following line. Change the path to where your script is located. This crontab will run the script 10 minutes past every hour. For more information about crontab, see [Automate tasks in Linux using cron](/products/compute/guides-for-server-management/automate-tasks-in-linux-using-cron.md).

{% code title="Root's crontab" %}

```
10 * * * * /path/to/your/script/raidcheck.sh
```

{% endcode %}

## Notes

We recommend that you test the script to ensure that 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.glesys.com/products/bare-metal/dedicated-servers/how-tos/raid-monitoring-with-storcli.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
