Help - Search - Members - Calendar
Full Version: WBEM ESXi raid array monitoring
Intellipool Network Monitor - Forum > Intellipool Network Monitor > Lua scripts
RA
CODE
----------------------------------------------------------------------------------------------------------
-- Name: wbem_esxi_hp_raid_array_status.lua
-- Author: Robert Aronsson, Intellipool AB
-- Version: 1.0
-- Date: 2009-09-10
--
-- Prerequisite: HP WBEM proivder must be installed on VM
-- Script published "AS IS", no warranties made.
--
-- Recomended testing interval: 10 minutes
--
-- Description:
--
-- The script checks the status of disks in a raid array.
-- The script have been tested against a VMWare ESXi server running on HP hardware with HP providers installed
--
-- Arguments: username and password
----------------------------------------------------------------------------------------------------------

function OnEnumerate(sFieldToEnum)

    Enum = LuaScriptEnumResult()
    return Enum
end

-- This function is called by INM to retrieve a script configuration

function OnConfigure()

    -- The variable returned must be called "Config" so INM can find it.
    Config = LuaScriptConfigurator()

    -- Author.
    Config:SetAuthor("Robert Aronsson, Intellipool AB")

    -- Description.
    Config:SetDescription("Checks state of HP's Smart Array Controller hosted on VMWare ESXi")

    -- Minimum build version of INM, set to zero for if no specific build version is required.
    Config:SetMinBuildVersion(5150)

    -- Script version (major/minor)
    Config:SetScriptVersion(1,0)

    Config:AddArgument("Username","Username",LuaScriptConfigurator.CHECK_NOT_EMPTY)
    Config:AddArgument("Password","Password",LuaScriptConfigurator.CHECK_NOT_EMPTY)

    -- Set the entry point, this is the function called by INM
    Config:SetEntryPoint("main")

    -- Done with configuration, return the object
    return Config
end

-- This is the entry point
function PrepareQuery(sClassToQuery)

    wbem_query = [[<?xml version="1.0" encoding="utf-8" ?>
               <CIM CIMVERSION="2.0" DTDVERSION="2.0">
                <MESSAGE ID="1001" PROTOCOLVERSION="1.0">
                   <SIMPLEREQ>
                    <IMETHODCALL NAME="EnumerateInstances">
                       <LOCALNAMESPACEPATH>
                        <NAMESPACE NAME="root"/>
                        <NAMESPACE NAME="cimv2"/>
                       </LOCALNAMESPACEPATH>
                       <IPARAMVALUE NAME="ClassName">
                        <CLASSNAME NAME="]] .. sClassToQuery  .. [["/>
                       </IPARAMVALUE>
                         </IMETHODCALL>
                   </SIMPLEREQ>
                </MESSAGE>
               </CIM>]]
    return wbem_query
end

function main()

    sUsername = GetArgument(0)
    sPassword = GetArgument(1)

        sURI = "\\cimom"
        port_num = 5989
    
    conn = TLuaHTTPClient()

    local iRet = conn:Connect(port_num,true,sUsername,sPassword)
    if iRet == 0 then
        SetExitStatus("Cannot connect to host",false)
        return
    end

    Extra_Headers = "";
    wbem_query = PrepareQuery("HPVC_SAStorageExtent")
    conn:Post(sURI, Extra_Headers, wbem_query)

    sData = conn:GetContent(1)

    -- print(sData)
    Reader = TLuaXMLReader();
    iRet = Reader:FromXML(sData);
    if iret == false then
        SetExitStatus("Failed to parse XML",false)
        return;
    end

    -- Store disk status in this table
    status_table = {}

    -- Create a dictionary look up
    state_code_table = {}
    table.insert(state_code_table,"0","Unknown state")
    table.insert(state_code_table,"10","Degraded state")
    table.insert(state_code_table,"15","Minor failure")
    table.insert(state_code_table,"20","Major failure")
    table.insert(state_code_table,"25","Critical Failure")
    table.insert(state_code_table,"30","Non-recoverable Error")


    -- Parse XML
    NamedInstance = Reader:FindNode("VALUE.NAMEDINSTANCE",Reader:GetRootNode())    
    if NamedInstance:IsValid() == false then
        SetExitStatus("Failed to parse XML",false)
        return;
    end
    Parent = NamedInstance:GetParentNode()
    NamedInstanceCount = 0
    while (NamedInstance:IsValid()) == true do
        DiskID = "";
        HealthStatus = 0
        Instance = NamedInstance:FindChildNode("INSTANCE",0)    
        if Instance:IsValid() == true then
            iCount = 0;
            Property = Instance:FindChildNode("PROPERTY",iCount)
            while (Property:IsValid() == true) do
                
                sParam = Property:FindAttribute("NAME")
                if sParam == "Caption" then
                    Value = Property:FindChildNode("VALUE",0)    
                    DiskID = Value:GetData()
                end

                if sParam == "HealthState" then
                    Value = Property:FindChildNode("VALUE",0)    
                    HealthStatus = Value:GetData()
                end
                iCount= iCount +1;
                Property = Instance:FindChildNode("PROPERTY",iCount)    
            end
            status = {State=HealthStatus,Disk = DiskID}
            table.insert(status_table,status)
        end
        NamedInstanceCount = NamedInstanceCount + 1
        NamedInstance = Parent:FindChildNode("VALUE.NAMEDINSTANCE",NamedInstanceCount)
    end

    -- evaluate
    sErrorString = ""
    bRet = true

    for key,value in pairs(status_table) do

        if value.State ~= "5" then
            sErrorString = sErrorString .. string.format("%s, State: %s\n",value.Disk,state_code_table[tonumber(value.State)])
            bRet = false
        end
    end

    if bRet == true then
        SetExitStatus("Disks are ok",true)
    else
        SetExitStatus(sErrorString,false)
    end
end
tomer
HI,
when trying to run i get error:

Syntax error in LUA script , [string ""]:100: attempt to call global `TLuaXMLReader' (a nil value).


any idea what can this be ?
RA
Update to latest version of INM
christian@switch-it.se
Hi!

I recieve "Failed to parse XML" when I run the script.
Do you know why?

Best regards
Christian
RA
The output from your server did not contain the expected result, its possible that it do not export information about your raid array.
CommArc
These ESXi scripts are doing my head in!

The three that I've tried, RAID, power supply and fan monitoring all work fine when run from the LUA IDE on our intellipool server, as soon as I try and run them in IntelliPool I get "Failed to parse XML"

I dont understand why it works from the IDE but not IntelliPool, I'm using the same username and password in both, I have ticked the no logon account option I've modified the output of the script to show me the username and password it's getting passed from IntelliPool and it is correct.

This is the part of the script it is failing on

NamedInstance = Reader:FindNode("VALUE.NAMEDINSTANCE",Reader:GetRootNode())
if NamedInstance:IsValid() == false then
SetExitStatus("Failed to parse XML",false)
return;
end

I modified the SetExitStatus so it showed a different error message for each stage to determine where it was failing.

I've modified the script to print the contents of the sData variable after the query is performed and it definitly is getting the correct information back from the ESXi server

Any assistance is appreciated

Thanks
Greg
RA
I think the problem is that you do not get any data, put the following snippet

CODE
    
if sData == "" then
        SetExitStatus("No data returned",false)
        return
    end


after this line (Aprox line 124)

CODE
    sData = conn:GetContent(1)


If it prints "No data returned", the request have timed out.
CommArc
I added the code as suggest and yes you are correct this I received a "No data returned" error. But that doesnt answer the question as to why the script will return the data from the IDE but not from IntelliPool. If its a timeout, is there a way to increase this?

Thanks
Greg
RA
The problem is probably the Winhttp api we use, it may be so that the server requires a client certificate for authentication against the ESXi server, on the desktop your user has such certificate in the local store, while in "service mode" there is no certificate in the machine store (which the local system uses).
CommArc
Thanks for the reply I tried the scripts against an older ESXi 3.5 server and the scripts worked from Intellipool so its possibly ESXi 4 that is the problem. I'll try and investigate further.
CommArc
Not sure if this is relevant or not, but if I change the script and use SetExitStatus(GetLastError(),false) as the exit code it returns 12150 which I think corresponds to

ERROR_HTTP_HEADER_NOT_FOUND
The requested header could not be located.

Thanks
Greg

This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.