IPB

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> WBEM ESXi fan monitoring, The script checks the status of installed fans.
RA
post Sep 10 2009, 11:30 AM
Post #1


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

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



CODE
----------------------------------------------------------------------------------------------------------
-- Name: wbem_esxi_fan_status.lua
-- Author: Robert Aronsson, Intellipool AB
-- Version: 1.0
-- Date: 2009-09-10
--
-- Prerequisite: 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 installed fans.
-- 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 fan sensor 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("OMC_DiscreteSensor")
    conn:Post(sURI, Extra_Headers, wbem_query)

    sData = conn:GetContent(1)

    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
        SensorCaption = "";
        HealthStatus = 0
        SensorType = 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")
                -- Name of the sensor
                if sParam == "Caption" then
                    Value = Property:FindChildNode("VALUE",0)    
                    if Value:IsValid() == true then SensorCaption = Value:GetData() end
                end
                -- State of it
                if sParam == "HealthState" then
                    Value = Property:FindChildNode("VALUE",0)    
                    if Value:IsValid() == true then HealthStatus = Value:GetData() end
                end
                -- Type
                if sParam == "SensorType" then
                    Value = Property:FindChildNode("VALUE",0)    
                    if Value:IsValid() then SensorType = Value:GetData() end
                end

                iCount= iCount +1;
                Property = Instance:FindChildNode("PROPERTY",iCount)    
            end
            
            -- We're only interested in Tachometers here
            if SensorType == "5" then
                status = {State=HealthStatus,Caption = SensorCaption}
                table.insert(status_table,status)
            end
        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.Caption,state_code_table[tonumber(value.State)])
            bRet = false
        end
    end

    if bRet == true then
        SetExitStatus("Fans are ok",true)
    else
        SetExitStatus(sErrorString,false)
    end
end


--------------------
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

 



RSS Lo-Fi Version Time is now: 10th September 2010 - 09:35 PM