Cisco.Imc.ServerNode.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.ServerNode.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.ServerNode.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 ComputeServerNode($oNode, $hostname, $IpAddress)
{
$oComputeServerNode = GetPropertyBag("false")
$modDn = $oNode.ParentNode.HostName + "/" + (GetXmlAttribute $oNode "dn")

#Cisco.UCS.CSeries.RackUnit
$oComputeServerNode.AddValue("AvailableMemory", (GetXmlAttribute $oNode "availableMemory"))
$oComputeServerNode.AddValue("Id", (GetXmlAttribute $oNode "serverId"))
$oComputeServerNode.AddValue("IPAddress", $IpAddress)
$oComputeServerNode.AddValue("MemorySpeed", (GetXmlAttribute $oNode "memorySpeed"))
$oComputeServerNode.AddValue("Name", (GetXmlAttribute $oNode "name"))
$oComputeServerNode.AddValue("NmOfAdaptor", (GetXmlAttribute $oNode "numOfAdaptors"))
$oComputeServerNode.AddValue("NmOfCore", (GetXmlAttribute $oNode "numOfCores"))
$oComputeServerNode.AddValue("NmOfCoresEnabled", (GetXmlAttribute $oNode "numOfCoresEnabled"))
$oComputeServerNode.AddValue("NmOfCpus", (GetXmlAttribute $oNode "numOfCpus"))
$oComputeServerNode.AddValue("NmOfEthHostIfs", "NOT APPLICABLE")
$oComputeServerNode.AddValue("NmOfFcHostIfs", "NOT APPLICABLE")

$oComputeServerNode.AddValue("NmOfThread", (GetXmlAttribute $oNode "numOfThreads"))
$oComputeServerNode.AddValue("OperPower", (GetXmlAttribute $oNode "operPower"))
$oComputeServerNode.AddValue("OriginalUuid", (GetXmlAttribute $oNode "originalUuid"))
$oComputeServerNode.AddValue("Presence", (GetXmlAttribute $oNode "presence"))
$oComputeServerNode.AddValue("TotalMemory", (GetXmlAttribute $oNode "totalMemory"))
$oComputeServerNode.AddValue("UUID", (GetXmlAttribute $oNode "uuid"))

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

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

#Cisco.UCS.CSeries.Object
$oComputeServerNode.AddValue("Description", (GetXmlAttribute $oNode "usrLbl"))



#System.Entity
$oComputeServerNode.AddValue("DisplayName", $hostname)

return $oComputeServerNode
}



######
# 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.ServerNode.DataSource.ps1", $iErrorEventId, $iEventType, $sMessage)
}

###
# Find Host Name and IP Address of Server
###

Function GetHostNameAndIpAddress($mNodeList, $dn, [ref]$hostname, [ref]$IpAddress)
{

$dn = $dn + "/mgmt/if-"
Foreach( $mNode in $mNodeList)
{
$mgmtDn = (GetXmlAttribute $mNode "dn")
if($mgmtDn.StartsWith($dn))
{
$hostname.value = (GetXmlAttribute $mNode "hostname")
$IpAddress.value = (GetXmlAttribute $mNode "v4IPAddr")
}
}
}



######
# 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 = "topSystem computeServerNode mgmtIf"
$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("computeServerNode")
$mNodeList = $oXmlDocument.GetElementsByTagName("mgmtIf")

If ($oNodeList.Count -ne "0")
{
Foreach ($oNode In $oNodeList)
{
$dn = (GetXmlAttribute $oNode "dn")
$hostname=""
$IpAddress = ""

$dn = $dn + "/mgmt/if-"
Foreach( $mNode in $mNodeList)
{
$mgmtDn = (GetXmlAttribute $mNode "dn")
if($mgmtDn.StartsWith($dn))
{
$hostname = (GetXmlAttribute $mNode "hostname")
$IpAddress = (GetXmlAttribute $mNode "v4IPAddr")
}
}
#GetHostNameAndIpAddress $mNodeList $dn ([ref]$hostname) ([ref]$IpAddress)

$oPropertyBag = ComputeServerNode $oNode $hostname $IpAddress
$oPropertyBag.AddValue("DisplayName",$hostname)
$oPropertyBag.AddValue("IPAddress",$IpAddress)
$oPropertyBag.AddValue("HostName",$oNode.ParentNode.HostName)
$oPropertyBag.AddValue("FirmwareVersion", $oNode.ParentNode.FirmwareVersion)
$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>