Cisco.Ucs.IOModule.DataSource (DataSourceModuleType)

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityPublic
RunAsDefault
OutputTypeSystem.Discovery.Data

Member Modules:

ID Module Type TypeId RunAs 
DataSource DataSource Microsoft.Windows.TimedPowerShell.DiscoveryProvider Default

Overrideable Parameters:

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

Source Code:

<DataSourceModuleType ID="Cisco.Ucs.IOModule.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="ClassId" 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="WebProxyUrl" 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="SeedMachineName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="SourceId" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="ManagedEntityId" 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"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="0" name="SetUserLabelAsDisplayName" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="Logging" Selector="$Config/Loging$" ParameterType="string"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
<OverrideableParameter ID="SetUserLabelAsDisplayName" Selector="$Config/SetUserLabelAsDisplayName$" ParameterType="string"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DataSource" TypeID="Windows!Microsoft.Windows.TimedPowerShell.DiscoveryProvider">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<SyncTime/>
<ScriptName>Cisco.Ucs.IOModule.ps1</ScriptName>
<ScriptBody><Script>Param (
$Loging,
$ClassId,
$TypeId,
$WebProxyUrl,
$ProxyId,
$SeedMachineName,
$SourceId,
$ManagedEntityId,
$SetUserLabelAsDisplayName
)

######
# 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'


Function AddUCSCentralKeyProperties($oInstance, $oNode, $cNodeList)
{
$dn = GetXmlAttribute $oNode "dn"
$uniqueDn = "${ProxyId}:$dn"


$computeSystemDn = $dn.Substring(0, $dn.Substring(0, $dn.LastIndexOf('/')).LastIndexOf('/'))
Foreach ($cNode In $cNodeList)
{
$computeSystemItrDn = (GetXmlAttribute $cNode "dn")

if( $computeSystemDn -ieq $computeSystemItrDn )
{
$DomainGroupDn = (GetXmlAttribute $cNode "operGroupDn")
If([string]::IsNullOrEmpty($DomainGroupDn))
{
$domainGroupDn = "Ungrouped-Domains"
}
$DomainGroupUniqueDn = "${ProxyId}:$DomainGroupDn"
$oInstance.AddProperty("$MPElement[Name='Cisco.UcsCentral.DomainGroup']/Id$",$DomainGroupUniqueDn )
If (($DomainGroupDn -eq "domaingroup-root") -or ($DomainGroupDn -eq "Ungrouped-Domains"))
{
$oInstance.AddProperty("$MPElement[Name='Cisco.UcsCentral.DomainGroup']/ParentMoniker$","")
}
Else
{
$oInstance.AddProperty("$MPElement[Name='Cisco.UcsCentral.DomainGroup']/ParentMoniker$", $DomainGroupDn.substring(0, $DomainGroupDn.lastindexofany("/")))
}
$oInstance.AddProperty("$MPElement[Name='Cisco.Ucs.Proxy']/Id$", "sys-"+(GetXmlAttribute $cNode "id"))
$oInstance.AddProperty("$MPElement[Name='Cisco.Ucs.Entity']/UcsName$", (GetXmlAttribute $cNode "name"))
}
}


$oInstance.AddProperty("$MPElement[Name='Cisco.UcsCentral.IOModule']/DomainGroup$", $DomainGroupDn )
$oInstance.AddProperty("$MPElement[Name='Cisco.UcsCentral.IOModule']/UcsCentral$", $ProxyId)

return $oInstance
}

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

Function EquipmentIOCard($oNode, $cNodeList, $versionFirmware)
{
$sId = GetXmlAttribute $oNode "id"

$dn = GetXmlAttribute $oNode "dn"
$uniqueId = "${ProxyId}:$dn"
$ChassisDn = $dn.Remove($dn.LastIndexOf('/'))
if($ChassisDn -inotmatch "chassis")
{
return $null
}


$oIOModuleInstance = $oDiscoveryData.CreateClassInstance("$ClassId")

if($cNodeList.Count -eq "0")
{
$oIOModuleInstance.AddProperty("$MPElement[Name='Cisco.Ucs.Proxy']/Id$", $ProxyId)
$oIOModuleInstance.AddProperty("$MPElement[Name='Cisco.Ucs.Entity']/UcsName$", $ProxyId)

}
else
{
$oIOModuleInstance.AddProperty("$MPElement[Name='Cisco.UcsCentral.Root']/Id$", $ProxyId)
$oIOModuleInstance = AddUCSCentralKeyProperties $oIOModuleInstance $oNode $cNodeList

}

$oIOModuleInstance.AddProperty("$MPElement[Name='Cisco.Ucs.Seed']/MachineName$", $SeedMachineName)
$chassisUniqueDn = "${ProxyId}:$ChassisDn"
$oIOModuleInstance.AddProperty("$MPElement[Name='Cisco.Ucs.Chassis']/Id$",$chassisUniqueDn )
$oIOModuleInstance.AddProperty("$MPElement[Name='Cisco.Ucs.Object']/TypeId$", $TypeId)
$oIOModuleInstance.AddProperty("$MPElement[Name='Cisco.Ucs.IOModule']/Id$", $uniqueId)


#Cisco.Ucs.IOModule
$oIOModuleInstance.AddProperty("$MPElement[Name='Cisco.Ucs.IOModule']/BaseAddress$", (GetXmlAttribute $oNode "baseAddr"))
$oIOModuleInstance.AddProperty("$MPElement[Name='Cisco.Ucs.IOModule']/ChassisId$", (GetXmlAttribute $oNode "chassisId"))
$oIOModuleInstance.AddProperty("$MPElement[Name='Cisco.Ucs.IOModule']/ConfigState$", (GetXmlAttribute $oNode "configState"))
$oIOModuleInstance.AddProperty("$MPElement[Name='Cisco.Ucs.IOModule']/Discovery$", (GetXmlAttribute $oNode "discovery"))
$oIOModuleInstance.AddProperty("$MPElement[Name='Cisco.Ucs.IOModule']/FirmwareVersion$", $versionFirmware)
$oIOModuleInstance.AddProperty("$MPElement[Name='Cisco.Ucs.IOModule']/LcTs$", (GetXmlAttribute $oNode "lcTs"))
$oIOModuleInstance.AddProperty("$MPElement[Name='Cisco.Ucs.IOModule']/PeerCommStatus$", (GetXmlAttribute $oNode "peerCommStatus"))
$oIOModuleInstance.AddProperty("$MPElement[Name='Cisco.Ucs.IOModule']/PeerDn$", (GetXmlAttribute $oNode "peerDn"))
$oIOModuleInstance.AddProperty("$MPElement[Name='Cisco.Ucs.IOModule']/Presence$", (GetXmlAttribute $oNode "presence"))
$oIOModuleInstance.AddProperty("$MPElement[Name='Cisco.Ucs.IOModule']/Side$", (GetXmlAttribute $oNode "side"))
$oIOModuleInstance.AddProperty("$MPElement[Name='Cisco.Ucs.IOModule']/SwitchId$", (GetXmlAttribute $oNode "switchId"))
$oIOModuleInstance.AddProperty("$MPElement[Name='Cisco.Ucs.IOModule']/Thermal$", (GetXmlAttribute $oNode "thermal"))

#Cisco.Ucs.Device
$oIOModuleInstance.AddProperty("$MPElement[Name='Cisco.Ucs.Device']/Model$", (GetXmlAttribute $oNode "model"))
$oIOModuleInstance.AddProperty("$MPElement[Name='Cisco.Ucs.Device']/Revision$", (GetXmlAttribute $oNode "revision"))
$oIOModuleInstance.AddProperty("$MPElement[Name='Cisco.Ucs.Device']/SerialNumber$", (GetXmlAttribute $oNode "serial"))
$oIOModuleInstance.AddProperty("$MPElement[Name='Cisco.Ucs.Device']/Vendor$", (GetXmlAttribute $oNode "vendor"))
$oIOModuleInstance.AddProperty("$MPElement[Name='Cisco.Ucs.Device']/UserLabel$", (GetXmlAttribute $oNode "usrLbl"))

#Cisco.Ucs.Entity
$oIOModuleInstance.AddProperty("$MPElement[Name='Cisco.Ucs.Entity']/Moniker$", "${dn}/")
$oIOModuleInstance.AddProperty("$MPElement[Name='Cisco.Ucs.Entity']/ModifiedMoniker$", "NA")


#Cisco.Ucs.Object
$oIOModuleInstance.AddProperty("$MPElement[Name='Cisco.Ucs.Object']/Description$", (GetXmlAttribute $oNode "descr"))
$oIOModuleInstance.AddProperty("$MPElement[Name='Cisco.Ucs.Object']/MonitoringServer$", $SeedMachineName)
$oIOModuleInstance.AddProperty("$MPElement[Name='Cisco.Ucs.Object']/WebProxyUrl$", $WebProxyUrl)
$oIOModuleInstance.AddProperty("$MPElement[Name='Cisco.Ucs.Object']/ClassName$", "IOModule")


#System.Entity

$usrLbl = (GetXmlAttribute $oNode "usrLbl")
$displayName=(GetDisplayName $sId)
if($SetUserLabelAsDisplayName -ieq "true" -and !([string]::IsNullOrEmpty($usrLbl)))
{
$displayName+="(" + $usrLbl + ")"
}
$oIOModuleInstance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $displayName)


return $oIOModuleInstance
}

######
# Getting Display Name for the UCS Component
######
Function GetDisplayName($sNamePart)
{
$sDisplayName = "IO Module {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
}

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

Function GetRunningFirmwareVersion($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"
}
}
return $versionFirmware
}
######
# 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 Cisco 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
}
$ioModuleMO = [string]::Empty
$ioModuleMO = "equipmentIOCard equipmentSwitchIOCard equipmentSharedIOModule equipmentSystemIOController"

$ManagedObjects = "computeSystem $ioModuleMO firmwareRunning"
$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))
{
$oNodeList = $oXmlDocument.GetElementsByTagName("equipmentIOCard")
#if($oNodeList.Count -eq "0")
{
$oNodeList += $oXmlDocument.GetElementsByTagName("equipmentSharedIOModule")
}
#if($oNodeList.Count -eq "0")
{
$oNodeList +=$oXmlDocument.GetElementsByTagName("equipmentSwitchIOCard")
}
$oNodeList +=$oXmlDocument.GetElementsByTagName("equipmentSystemIOController")

$vNodeList = $oXmlDocument.GetElementsByTagName("firmwareRunning")
$cNodeList = $oXmlDocument.GetElementsByTagName("computeSystem")

If ($oNodeList.Count -ne "0")
{
$oDiscoveryData = $oScriptAPI.CreateDiscoveryData(0, $SourceId, $ManagedEntityId)

Foreach ($oNode In $oNodeList)
{

$ioModuleDn = (GetXmlAttribute $oNode "dn")
$versionFirmware = GetRunningFirmwareVersion $vNodeList $ioModuleDn
$oIOModuleInstance = EquipmentIOCard $oNode $cNodeList $versionFirmware
if( $oIOModuleInstance -ne $null)
{
$oDiscoveryData.AddInstance($oIOModuleInstance)
}
}
}
}
}

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

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

$oDiscoveryData
}
Main</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>Loging</Name>
<Value>$Config/Loging$</Value>
</Parameter>
<Parameter>
<Name>ClassId</Name>
<Value>$Config/ClassId$</Value>
</Parameter>
<Parameter>
<Name>TypeId</Name>
<Value>$Config/TypeId$</Value>
</Parameter>
<Parameter>
<Name>WebProxyUrl</Name>
<Value>$Config/WebProxyUrl$</Value>
</Parameter>
<Parameter>
<Name>ProxyId</Name>
<Value>$Config/ProxyId$</Value>
</Parameter>
<Parameter>
<Name>SeedMachineName</Name>
<Value>$Config/SeedMachineName$</Value>
</Parameter>
<Parameter>
<Name>SourceId</Name>
<Value>$Config/SourceId$</Value>
</Parameter>
<Parameter>
<Name>ManagedEntityId</Name>
<Value>$Config/ManagedEntityId$</Value>
</Parameter>
<Parameter>
<Name>SetUserLabelAsDisplayName</Name>
<Value>$Config/SetUserLabelAsDisplayName$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DataSource"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>