This is a beta script and have not been tested in production

CODE
----------------------------------------------------------------------------------------------------------
-- Name: mirrortest.lua
-- Author: Intellipool AB
-- Required INM version: 3.0.5, target machine running mdadm(8)
-- Version: 1.0
-- Date: 2006-05-09
-- Description: using the "mdadm" command it tests if there is any failed devices in a raid configuration
-- Arguments:
-- username
-- password
-- device string
-- Comment: Example device string /dev/md0
----------------------------------------------------------------------------------------------------------

-- Trims whitespaces from start and end of a string
function Trim(s)
    return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
end

-- Creates a table of all lines ending with CR in the text file
function MakeTable(s)
    local sInData = s;
    iLastPos = 0;
    
    t = {};
    max = string.len(sInData);
    for count = 0, max do
        cCharacter = string.byte(sInData,count);
        -- Break on whitespace
        if cCharacter == 32 then
            local sTemp = string.sub(sInData,iLastPos,count);
            iLastPos = count+1;
            table.insert(t,sTemp);
        end
    end
    local sTemp = string.sub(sInData,iLastPos,max);
    table.insert(t,sTemp);
    return t;
end

-- Get arguments
sUsername     = GetArgument(0);
sPassword     = GetArgument(1);
sDevice     = GetArgument(2);

-- Create SSH2 client, notice that it uses standard port 22
SSHClient = TLuaSSH2Client:new();
SSHClient:Open(22,sUsername,sPassword);

-- Format the string that will pull data
sTestString = "mdadm --detail "..sDevice.." | grep \"Failed Devices\"";

-- Execute command
if SSHClient:ExecuteCommand(sTestString) == true then

    -- Parse the output (stdout from the Linux machine)
    sOutput = SSHClient:GetStdOut();
    sOutput = Trim(sOutput);

    tTable = MakeTable(sOutput);
    nTableMax = table.getn(tTable);

    -- The returned string should look something like this
        -- Failed Devices : 0
    -- The script will parse and create a table from delimiting whitespaces in the string, so our number (0)
    -- will be the fourth element in the table
    
    -- Check that we got 4 elements
    if nTableMax < 4 then
        SetExitStatus("Failed to parse output",false);
        return;
    end
    -- print("Output:"..tTable[4]);
    sNumberOfFailedDevices = tonumber(tTable[4]);

    -- Check that it was a number
    if nTableMax == nil then
        SetExitStatus("Failed to parse output",false);
        return;
    end
        
    -- Check that there is no failed devices
    if sNumberOfFailedDevices > 0 then
        sErrorString = "There are one or more failed devices in raid configuration: "..sDevice;
        SetExitStatus(sErrorString,false);
        return;
    else
        sReturnString = "Raid configuration: "..sDevice.." ok!";
        SetExitStatus(sReturnString,true);
    end
else
    -- Could do add some more descriptive text
    SetExitStatus("Test failed, could not execute command",false);    
end