Cisco.UcsCentral.Cartridge.DataSource (DataSourceModuleType)

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityPublic
RunAsDefault
OutputTypeSystem.Discovery.Data

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource System.SimpleScheduler Default
PSScriptPropertyBagProbe ProbeAction Microsoft.Windows.PowerShellPropertyBagTriggerOnlyProbe Default
DataMapper ConditionDetection System.Discovery.ClassSnapshotDataMapper Default
ExpressionFilter ConditionDetection System.ExpressionFilter Default

Overrideable Parameters:

IDParameterTypeSelector
Loggingstring$Config/Loging$
TimeoutSecondsint$Config/TimeoutSeconds$
IntervalSecondsint$Config/IntervalSeconds$

Source Code:

<DataSourceModuleType ID="Cisco.UcsCentral.Cartridge.DataSource" Accessibility="Public" Batching="false">
<Configuration>
<IncludeSchemaTypes>
<SchemaType>System!System.Discovery.MapperSchema</SchemaType>
</IncludeSchemaTypes>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="Loging" type="xsd:string"/>
<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="InstanceSettings" type="SettingsType"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="WebProxyUrl" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="ClassId" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="ChassisId" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="ProxyId" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="IntervalSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="TimeoutSeconds" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="Logging" Selector="$Config/Loging$" ParameterType="string"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="System!System.SimpleScheduler">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<SyncTime/>
</DataSource>
<ProbeAction ID="PSScriptPropertyBagProbe" TypeID="Windows!Microsoft.Windows.PowerShellPropertyBagTriggerOnlyProbe">
<ScriptName>Cisco.UcsCentral.Cartridge.DataSource.ps1</ScriptName>
<ScriptBody><Script>Param (
$Loging,
$TypeId,
$ProxyId,
$WebProxyUrl
)

######
# Declaring Constants
######
########################################################################################
Set-Variable -Name cCODE -Value "19900"
Set-Variable -Name cLOGINGCODE -Value "19901"
Set-Variable -Name cAUTHFAILCODE -Value "19903"
Set-Variable -Name cCONFAILCODE -Value "19904"

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
######
#Referring MOM API
$oScriptAPI = New-Object -ComObject 'MOM.ScriptAPI'


######
# Declaring Class Properties
######
Function AddCartridgeDiscoveryData($cNode,$csNodeList, $DisplayName)
{
$dnCartridge = GetXmlAttribute $cNode "dn"
$versionFirmware = $null
$versionBios = $null
$sId = GetXmlAttribute $cNode "slotId"
#$DisplayName = GetDisplayName "Cartridge" $sId

$ChassisDn = $dnCartridge.Remove($dnCartridge.LastIndexOf('/'))
$chassisUniqueDn = "${ProxyId}:$ChassisDn"

$oCartridgeInstance = GetPropertyBag("false")
$oCartridgeInstance.AddValue("Id", "${ProxyId}:$dnCartridge")

#Cisco.Ucs.Cartridge
$oCartridgeInstance.AddValue("ChassisId", (GetXmlAttribute $cNode "chassisId"))
$oCartridgeInstance.AddValue("Discovery", (GetXmlAttribute $cNode "discovery"))
$oCartridgeInstance.AddValue("Lc", (GetXmlAttribute $cNode "lc"))
$oCartridgeInstance.AddValue("OperState", (GetXmlAttribute $cNode "operState"))

$oCartridgeInstance.AddValue("Operability", (GetXmlAttribute $cNode "operability"))
$oCartridgeInstance.AddValue("Power", (GetXmlAttribute $cNode "power"))
$oCartridgeInstance.AddValue("Presence", (GetXmlAttribute $cNode "presence"))
$oCartridgeInstance.AddValue("SlotId", (GetXmlAttribute $cNode "slotId"))
$oCartridgeInstance.AddValue("Voltage", (GetXmlAttribute $cNode "voltage"))
$oCartridgeInstance.AddValue("ChassisUniqueId", $chassisUniqueDn)


#Cisco.Ucs.Device
$oCartridgeInstance.AddValue("Model", (GetXmlAttribute $cNode "model"))
$oCartridgeInstance.AddValue("Revision", (GetXmlAttribute $cNode "revision"))
$oCartridgeInstance.AddValue("SerialNumber", (GetXmlAttribute $cNode "serial"))
$oCartridgeInstance.AddValue("Vendor", (GetXmlAttribute $cNode "vendor"))
$oCartridgeInstance.AddValue("UserLabel", (GetXmlAttribute $cNode "usrLbl"))

#Cisco.Ucs.Entity
$oCartridgeInstance.AddValue("Moniker", "${dnCartridge}/")
$oCartridgeInstance.AddValue("ModifiedMoniker", "NA")

#Cisco.Ucs.Object
$oCartridgeInstance.AddValue("Description", (GetXmlAttribute $cNode "descr"))
$oCartridgeInstance.AddValue("MonitoringServer", $SeedMachineName)
$oCartridgeInstance.AddValue("WebProxyUrl", $WebProxyUrl)
$oCartridgeInstance.AddValue("ClassName", "Cartridge")


#System.Entity
$oCartridgeInstance.AddValue("DisplayName", $DisplayName)

return $oCartridgeInstance

}

######
# Getting Display Name for the UCS Component
######
Function GetDisplayName($type, $id)
{
$sDisplayName = "{1} {2}"
$sDisplayName = $sDisplayName.Replace("{1}", $type)
$sDisplayName = $sDisplayName.Replace("{2}", $id)
return $sDisplayName
}

######
# 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)
{
$oPBag = $oScriptAPI.CreateTypedPropertyBag($cSTATEDATA)

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

return $oPBag
}

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

Function GetRunningFirmwareAndBiosVersion($vNodeList, $Moniker)
{
Foreach ($vNode In $vNodeList | Where-Object {$_.dn -like "$Moniker*"})
{
$dnFirmware = GetXmlAttribute $vNode "dn"

if ($dnFirmware -eq $Moniker + "/mgmt/fw-system")
{
$versionFirmware = GetXmlAttribute $vNode "version"
}
ElseIf ($dnFirmware -eq $Moniker + "/bios/fw-boot-loader")
{
$versionBios = GetXmlAttribute $vNode "version"
}
}

return "$versionFirmware|$versionBios"
}

######
# Main Method
######
Function Main
{

$startTime = (Get-Date)

If ([string]::IsNullOrEmpty($WebProxyUrl))
{
LogEvent "Service Connection error" $cERROR $cCODE
Exit
}

if (!(CheckService $cSERVICENAME $WebProxyUrl))
{
LogEvent "Service Not Found or Not Running." $cERROR $cCODE
Exit
}

$oPropertyBag = $null

Try
{
If ($Loging -eq "true")
{
$evtArgs = "Connecting to UCS Monitoring Service..."
LogEvent "$evtArgs" $cINFORMATION $cCODE
}

$oConnection = New-WebServiceProxy $WebProxyUrl
If ($oConnection -eq $null)
{
LogEvent "Connection to Cisco UCS Monitoring Service failed." $cERROR $cCODE
Exit
}

If ($Loging -eq "true")
{
$evtArgs = "Connection successful."
LogEvent "$evtArgs" $cINFORMATION $cCODE
}

#$oConnectionHandle = $oConnection.GetHandle()
#$oConnectionHandle.InstanceId = $TypeId
#$oConnectionHandle.
$ManagedObjects = "computeSystem computeCartridge" #computeCartridge
$oConnection.TimeOut = 600000
$oXmlDocument = $oConnection.GetManagedObjects($TypeId, $ManagedObjects)
}
Catch [system.exception]
{
LogEvent $_.Exception.Message $cERROR $cCODE
Exit
}

If ($oXmlDocument.ErrorCode -eq "0")
{
$oXmlDocument = GetXmlDocument $oXmlDocument.ClassData
If (![string]::IsNullOrEmpty($oXmlDocument))
{
$cNodeList = $oXmlDocument.GetElementsByTagName("computeCartridge")
$csNodeList = $oXmlDocument.GetElementsByTagName("computeSystem")
if($cNodeList.Count -ne "0")
{
Foreach( $cNode In $cNodeList)
{

$dnCartridge = (GetXmlAttribute $cNode "dn")
$oPropertyBag = AddCartridgeDiscoveryData $cNode $csNodeList (GetDisplayName "Cartridge" (GetXmlAttribute $cNode "slotId"))
$oScriptAPI.AddItem($oPropertyBag)
$oPropertyBag

}

}
}
}

$oXmlDocument = $null
$oConnectionHandle = $null
$oConnection = $null

$endTime = (Get-Date)
If ($Loging -eq "true")
{
$totalTimes = ($endTime - $startTime).TotalMilliseconds
LogEvent ("Total time: " + $totalTimes + " Milliseconds") $cINFORMATION $cCODE
}
$oPropertyBag = GetPropertyBag "true"
$oScriptAPI.AddItem($oPropertyBag)
$oPropertyBag

}

Main</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>Loging</Name>
<Value>$Config/Loging$</Value>
</Parameter>
<Parameter>
<Name>TypeId</Name>
<Value>$Config/TypeId$</Value>
</Parameter>
<Parameter>
<Name>ProxyId</Name>
<Value>$Config/ProxyId$</Value>
</Parameter>
<Parameter>
<Name>WebProxyUrl</Name>
<Value>$Config/WebProxyUrl$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
<ConditionDetection ID="ExpressionFilter" TypeID="System!System.ExpressionFilter">
<Expression>
<And>
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery>Property[@Name='IsEmpty']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value>false</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery>Property[@Name='ChassisUniqueId']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value>$Config/ChassisId$</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</And>
</Expression>
</ConditionDetection>
<ConditionDetection ID="DataMapper" TypeID="System!System.Discovery.ClassSnapshotDataMapper">
<ClassId>$Config/ClassId$</ClassId>
<InstanceSettings>$Config/InstanceSettings$</InstanceSettings>
</ConditionDetection>
</MemberModules>
<Composition>
<Node ID="DataMapper">
<Node ID="ExpressionFilter">
<Node ID="PSScriptPropertyBagProbe">
<Node ID="DS"/>
</Node>
</Node>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>