CODE
----------------------------------------------------------------------------------------------------------
-- Name: wbem_esxi_power_supply_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 power supplies.
-- 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 Power supply units 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_PowerSupply")
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
PSUID = "";
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)
PSUID = 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,PSU = PSUID}
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.PSU,state_code_table[tonumber(value.State)])
bRet = false
end
end
if bRet == true then
SetExitStatus("PSUs are ok",true)
else
SetExitStatus(sErrorString,false)
end
end
-- Name: wbem_esxi_power_supply_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 power supplies.
-- 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 Power supply units 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_PowerSupply")
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
PSUID = "";
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)
PSUID = 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,PSU = PSUID}
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.PSU,state_code_table[tonumber(value.State)])
bRet = false
end
end
if bRet == true then
SetExitStatus("PSUs are ok",true)
else
SetExitStatus(sErrorString,false)
end
end