IPB

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> WBEM ESXi raid array monitoring, The script checks the status of disks in a raid array.
RA
post Sep 10 2009, 11:26 AM
Post #1


INM wizard
**********

Group: Root Admin
Posts: 2,314
Joined: 24-August 04
From: Intellipool AB, Härnösand, Sweden
Member No.: 3



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


--------------------
Go to the top of the page
 
+Quote Post
tomer
post Sep 30 2009, 01:07 PM
Post #2


New to the forum


Group: Members
Posts: 2
Joined: 22-September 08
Member No.: 1,722



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 ?
Go to the top of the page
 
+Quote Post
RA
post Sep 30 2009, 03:10 PM
Post #3


INM wizard
**********

Group: Root Admin
Posts: 2,314
Joined: 24-August 04
From: Intellipool AB, Härnösand, Sweden
Member No.: 3



Update to latest version of INM


--------------------
Go to the top of the page
 
+Quote Post
christian@switch...
post Feb 9 2010, 06:12 PM
Post #4


New to the forum


Group: Members
Posts: 3
Joined: 3-November 09
Member No.: 2,241



Hi!

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

Best regards
Christian
Go to the top of the page
 
+Quote Post
RA
post Feb 10 2010, 07:32 AM
Post #5


INM wizard
**********

Group: Root Admin
Posts: 2,314
Joined: 24-August 04
From: Intellipool AB, Härnösand, Sweden
Member No.: 3



The output from your server did not contain the expected result, its possible that it do not export information about your raid array.


--------------------
Go to the top of the page
 
+Quote Post
CommArc
post Jul 6 2010, 05:03 AM
Post #6


Rookie
*

Group: Members
Posts: 11
Joined: 27-December 07
Member No.: 1,257



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
Go to the top of the page
 
+Quote Post
RA
post Jul 6 2010, 07:37 AM
Post #7


INM wizard
**********

Group: Root Admin
Posts: 2,314
Joined: 24-August 04
From: Intellipool AB, Härnösand, Sweden
Member No.: 3



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.


--------------------
Go to the top of the page
 
+Quote Post
CommArc
post Jul 8 2010, 05:01 AM
Post #8


Rookie
*

Group: Members
Posts: 11
Joined: 27-December 07
Member No.: 1,257



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
Go to the top of the page
 
+Quote Post
RA
post Jul 8 2010, 09:43 AM
Post #9


INM wizard
**********

Group: Root Admin
Posts: 2,314
Joined: 24-August 04
From: Intellipool AB, Härnösand, Sweden
Member No.: 3



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).


--------------------
Go to the top of the page
 
+Quote Post
CommArc
post Jul 8 2010, 10:08 AM
Post #10


Rookie
*

Group: Members
Posts: 11
Joined: 27-December 07
Member No.: 1,257



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.
Go to the top of the page
 
+Quote Post
CommArc
post Jul 8 2010, 09:43 PM
Post #11


Rookie
*

Group: Members
Posts: 11
Joined: 27-December 07
Member No.: 1,257



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

Go to the top of the page
 
+Quote Post
christian@switch...
post Aug 13 2010, 01:34 PM
Post #12


New to the forum


Group: Members
Posts: 3
Joined: 3-November 09
Member No.: 2,241



QUOTE(CommArc @ Jul 8 2010, 10:43 PM) *
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


Hi!

And the solution is...?

/Christian
Go to the top of the page
 
+Quote Post
dtsgk
post Aug 13 2010, 09:28 PM
Post #13


Rookie
*

Group: Members
Posts: 18
Joined: 29-November 06
Member No.: 561



QUOTE(christian@switch-it.se @ Aug 13 2010, 02:34 PM) *
Hi!

And the solution is...?

/Christian


Hi Christian :-)

Change Intellipool service to logon with an ordinary user account. Let this user account trust the ESXi server certificate (put in local computer store).

/Göran K
Go to the top of the page
 
+Quote Post
christian@switch...
post Aug 17 2010, 01:52 PM
Post #14


New to the forum


Group: Members
Posts: 3
Joined: 3-November 09
Member No.: 2,241



QUOTE(dtsgk @ Aug 13 2010, 10:28 PM) *
Hi Christian :-)

Change Intellipool service to logon with an ordinary user account. Let this user account trust the ESXi server certificate (put in local computer store).

/Göran K


=) Hahah!

Klart att hu bor på detta forum.
Thanx for the fast reply.

Dags för en lunch snart tycker jag...

/C
Go to the top of the page
 
+Quote Post
RA
post Aug 17 2010, 02:15 PM
Post #15


INM wizard
**********

Group: Root Admin
Posts: 2,314
Joined: 24-August 04
From: Intellipool AB, Härnösand, Sweden
Member No.: 3



QUOTE
Dags för en lunch snart tycker jag...


Bara så ni vet, Intellipool bjuder alla kunder med vägarna förbi Sundsvall på lunch, bara att hojta till ... smile.gif


--------------------
Go to the top of the page
 
+Quote Post
dtsgk
post Today, 05:33 AM
Post #16


Rookie
*

Group: Members
Posts: 18
Joined: 29-November 06
Member No.: 561



QUOTE(RA @ Aug 17 2010, 03:15 PM) *
Bara så ni vet, Intellipool bjuder alla kunder med vägarna förbi Sundsvall på lunch, bara att hojta till ... smile.gif


Jag ska komma ihåg det! (Hade en kund i Järvsö tidigare, får kolla upp det igen...)

/Göran
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

 



RSS Lo-Fi Version Time is now: 8th September 2010 - 07:12 AM