Cisco.Imc.Chassis.Load.ProbeAction (ProbeActionModuleType)

Element properties:

TypeProbeActionModuleType
IsolationAny
AccessibilityPublic
RunAsDefault
OutputTypeSystem.PropertyBagData

Member Modules:

ID Module Type TypeId RunAs 
PassThroughProbe ProbeAction System.PassThroughProbe Default
ScriptPropertyBagProbe ProbeAction Microsoft.Windows.PowerShellPropertyBagProbe Default

Overrideable Parameters:

IDParameterTypeSelector
LogingLevelint$Config/LogingLevel$
TimeoutSecondsint$Config/TimeoutSeconds$

Source Code:

<ProbeActionModuleType ID="Cisco.Imc.Chassis.Load.ProbeAction" Accessibility="Public" Batching="false" PassThrough="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="LogingLevel" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="SecureInput" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="TimeoutSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="TypeId" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="UserName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="WebProxyUrl" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="LogingLevel" Selector="$Config/LogingLevel$" ParameterType="int"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<ProbeAction ID="ScriptPropertyBagProbe" TypeID="Windows!Microsoft.Windows.PowerShellPropertyBagProbe">
<ScriptName>Cisco.Imc.Chassis.Load.ProbeAction.ps1</ScriptName>
<ScriptBody><Script>Param (
$Loging,
$SecureInput,
$TypeId,
$UserName,
$WebProxyUrl
)

######
# Declaring Constants
######
########################################################################################
Set-Variable -Name cCODE -Value "19950"
Set-Variable -Name cLOGINGCODE -Value "19951"
Set-Variable -Name cAUTHFAILCODE -Value "19953"
Set-Variable -Name cCONFAILCODE -Value "19954"

Set-Variable -Name cERROR -Value "1"
Set-Variable -Name cWARNING -Value "2"
Set-Variable -Name cINFORMATION -Value "4"

Set-Variable -Name cSTATEDATA -Value "3"

Set-Variable -Name cSERVICENAME -Value "CiscoUcsMonitoringService"
########################################################################################

######
# Declaring Variables
######

#CSeriesAgent Url
$sWebProxyUrl = $WebProxyUrl

#Toggle Log Generation
$sLoging = $Loging

#Authentication
$sUserName = $UserName
$sSecureInput = $SecureInput

#Type ID
$sTypeId = $TypeId

#Refering MOM API
$oScriptAPI = New-Object -ComObject 'MOM.ScriptAPI'

######
# Declaring Class Properties
######

Function AddChassis($oNode, $ipAddress)
{
$oEquipmentChassis = GetPropertyBag("false")

$modDn = $oNode.ParentNode.HostName + "/" + (GetXmlAttribute $oNode "dn")

#Cisco.Imc.Chassis
$oEquipmentChassis.AddValue("IPAddress", $ipAddress)
$oEquipmentChassis.AddValue("ProductName", (GetXmlAttribute $oNode "name"))


#Cisco.UCS.CSeries.Device
$oEquipmentChassis.AddValue("Model", (GetXmlAttribute $oNode "model"))
$oEquipmentChassis.AddValue("SerialNumber", (GetXmlAttribute $oNode "serial"))
$oEquipmentChassis.AddValue("Vendor", "Not Applicable")
$oEquipmentChassis.AddValue("Revision", "Not Applicable")
$oEquipmentChassis.AddValue("UserLabel", (GetXmlAttribute $oNode "usrLbl"))

#Cisco.UCS.CSeries.Entity
$oEquipmentChassis.AddValue("Moniker", (GetXmlAttribute $oNode "dn"))
$oEquipmentChassis.AddValue("ModifiedMoniker", $modDn)

#Cisco.UCS.CSeries.Object
$oEquipmentChassis.AddValue("Description", (GetXmlAttribute $oNode "usrLbl"))
#$oEquipmentChassis.AddValue("WebProxyUrl", $WebProxyUrl)
#$oEquipmentChassis.AddValue("MonitoringServer", (GetXmlAttribute $oNode "descr"))


#System.Entity
$oEquipmentChassis.AddValue("DisplayName", (GetDisplayName $sId))

return $oEquipmentChassis
}

######
# Getting Display Name for the UCS Component
######
Function GetDisplayName($sNamePart)
{
$sDisplayName = "IMC {0}"

return $sDisplayName.Replace("{0}", $sNamePart)
}

######
# Checking status of the service
######
Function CheckService($serviceName, $machineName)
{
$machineName = $machineName.Split("/")[2].Split(":")[0]
$sAgentService = Get-Service -Name $serviceName -ComputerName $machineName -ErrorAction SilentlyContinue | Where-Object {$_.Status -eq "Running"}

if ($sAgentService -eq $null){
return $false
}

return $true
}

######
# Getting Valid XML Document
######
Function GetXmlDocument($sXmlString)
{
$oXmlDocument = New-Object System.Xml.XmlDocument

If ($oXmlDocument.LoadXml($sXmlString))
{
LogEvent ("Microsoft.XMLDOM Parse error: " + [string]($oXmlDocument.ParseError)) $cERROR $cCODE

$oXmlDocument = $Null
}
return $oXmlDocument
}

######
# Getting XML Attribute Values
######
Function GetXmlAttribute($oNode, $sAttributeName)
{
$oAttribute = $oNode.Attributes.GetNamedItem($sAttributeName)

$oValue = $null

If ($oAttribute)
{
$oValue = $oAttribute.Value
}

return $oValue
}

###
# Filling PropertyBags
###
Function GetPropertyBag($sIsEmpty)
{
$oBag = $oScriptAPI.CreateTypedPropertyBag($cSTATEDATA)

$oBag.AddValue("IsEmpty", $sIsEmpty)

return $oBag
}

###
# Generate General Events
###
Function LogEvent ($sMessage, $iEventType, $iErrorEventId)
{
$oScriptAPI.LogScriptEvent("Cisco.Imc.Chassis.DataSource.ps1", $iErrorEventId, $iEventType, $sMessage)
}

######
# Main Method
######
Function Main
{
$startTime = (Get-Date)

If (([string]::IsNullOrEmpty($sUserName)) -OR ([string]::IsNullOrEmpty($sSecureInput)))
{
#LogEvent "Run-As-Account not associated with Run-As-Profile of this IMC Group." $cERROR $cCODE
Exit
}

if ((CheckService $cSERVICENAME $sWebProxyUrl))
{
$oPropertyBag = $null

If (![string]::IsNullOrEmpty($sWebProxyUrl))
{
Try
{
$oConnection = New-WebServiceProxy -Uri $sWebProxyUrl
If ($oConnection -eq $null)
{
#LogEvent "Connection to Cisco IMC Management Service failed." $cERROR $cCODE
Exit
}

#$oXmlDocument = $oConnection.ComputeRackUnit($sUserName, $sSecureInput, $sTypeId)

$ManagedObjects = "equipmentChassis"
$oConnection.TimeOut = 600000
$oXmlDocument = $oConnection.GetManagedObjects($sTypeId, $ManagedObjects)
}
Catch [System.Exception]
{
LogEvent $_.Exception.Message $cERROR $cCODE
Exit
}

If ($oXmlDocument.ErrorCode -eq "0")
{
$oXmlDocument = GetXmlDocument $oXmlDocument.ClassData
}
Else
{
Exit
}

If (![string]::IsNullOrEmpty($oXmlDocument))
{
$oNodeList = $oXmlDocument.GetElementsByTagName("equipmentChassis")

If ($oNodeList.Count -ne "0")
{
Foreach ($oNode In $oNodeList)
{
#$id = $oNode.ParentNode.HostName
$ipAddress = $oNode.ParentNode.Address
#$fVersion = $oNode.ParentNode.FirmwareVersion

$oPropertyBag = AddChassis $oNode $ipAddress
$oPropertyBag.AddValue("HostName", $oNode.ParentNode.HostName)
$oScriptAPI.AddItem($oPropertyBag)
$oPropertyBag
}
}

$oNodeList = $null
}

$oXmlDocument = $null
$oConnection = $null

$endTime = (Get-Date)
If ($sLoging -eq "1"){
$totalTimes = ($endTime - $startTime).TotalSeconds
LogEvent "$totalTimes seconds" $cINFORMATION $cCODE
}
#$totalTimes = ($endTime - $startTime).TotalSeconds
#LogEvent "$totalTimes seconds" $cINFORMATION $cCODE

}

$oPropertyBag = GetPropertyBag "true"
$oScriptAPI.AddItem($oPropertyBag)
$oPropertyBag
}
Else
{
#LogEvent "Service Not Found or Not Running." $cERROR $cCODE
Exit
}
}

Main</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>Loging</Name>
<Value>$Config/LogingLevel$</Value>
</Parameter>
<Parameter>
<Name>SecureInput</Name>
<Value>$Config/SecureInput$</Value>
</Parameter>
<Parameter>
<Name>TypeId</Name>
<Value>$Config/TypeId$</Value>
</Parameter>
<Parameter>
<Name>UserName</Name>
<Value>$Config/UserName$</Value>
</Parameter>
<Parameter>
<Name>WebProxyUrl</Name>
<Value>$Config/WebProxyUrl$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
<ProbeAction ID="PassThroughProbe" TypeID="System!System.PassThroughProbe"/>
</MemberModules>
<Composition>
<Node ID="ScriptPropertyBagProbe">
<Node ID="PassThroughProbe"/>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
<TriggerOnly>true</TriggerOnly>
</ProbeActionModuleType>