Cisco.UcsCentral.Fex.DataSource (DataSourceModuleType)
Element properties:
Member Modules:
Overrideable Parameters:
Source Code:
<DataSourceModuleType ID="Cisco.UcsCentral.Fex.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="ComputeSystemDn" 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.Fex.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 EquipmentFex($oNode, $cNodeList)
{
$SetUserLabelAsDisplayName="true"
$dn = GetXmlAttribute $oNode "dn"
$uniqueId = "${ProxyId}:$dn"
$sId = GetXmlAttribute $oNode "id"
$computeSystemDn = $dn.substring(0, $dn.lastindexofany("/"))
$oFexInstance = GetPropertyBag("false")
$oFexInstance.AddValue("Id", $uniqueId )
#Cisco.Ucs.Fex
$oFexInstance.AddValue("OperQualifier", (GetXmlAttribute $oNode "operQualifier"))
$oFexInstance.AddValue("Operability", (GetXmlAttribute $oNode "operability"))
$oFexInstance.AddValue("SwitchId", (GetXmlAttribute $oNode "switchId"))
$oFexInstance.AddValue("ComputeSystemDn", $computeSystemDn)
#Cisco.Ucs.Device
$oFexInstance.AddValue("Model", (GetXmlAttribute $oNode "model"))
$oFexInstance.AddValue("Revision", (GetXmlAttribute $oNode "revision"))
$oFexInstance.AddValue("SerialNumber", (GetXmlAttribute $oNode "serial"))
$oFexInstance.AddValue("Vendor", (GetXmlAttribute $oNode "vendor"))
$oFexInstance.AddValue("UserLabel", (GetXmlAttribute $oNode "usrLbl"))
#Cisco.Ucs.Entity
$oFexInstance.AddValue("Moniker", "${dn}/")
$oFexInstance.AddValue("ModifiedMoniker", "NA")
#Cisco.Ucs.Object
$oFexInstance.AddValue("Description", (GetXmlAttribute $oNode "descr"))
$oFexInstance.AddValue("MonitoringServer", $SeedMachineName)
$oFexInstance.AddValue("WebProxyUrl", $WebProxyUrl)
$oFexInstance.AddValue("ClassName", "Fex")
#System.Entity
$usrLbl = (GetXmlAttribute $oNode "usrLbl")
$displayName = (GetDisplayName $sId)
if($SetUserLabelAsDisplayName -ieq "true" -and !([string]::IsNullOrEmpty($usrLbl)))
{
$displayName+="(" + $usrLbl + ")"
}
$oFexInstance.AddValue("DisplayName", $displayName)
return $oFexInstance
}
######
# Getting Display Name for the UCS Component
######
Function GetDisplayName($sNamePart)
{
$sDisplayName = "Fabric Extender {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.Fex.DataSource.ps1", $iErrorEventId, $iEventType, $sMessage)
}
###
# Filling PropertyBags
###
Function GetPropertyBag($sIsEmpty)
{
$oPBag = $oScriptAPI.CreateTypedPropertyBag($cSTATEDATA)
$oPBag.AddValue("IsEmpty", $sIsEmpty)
return $oPBag
}
######
# 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
}
#$oConnectionHandle = $oConnection.GetHandle()
#$oConnectionHandle.InstanceId = $TypeId
#$oConnectionHandle.
$ManagedObjects = "computeSystem equipmentFex"
$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("equipmentFex")
$cNodeList = $oXmlDocument.GetElementsByTagName("computeSystem")
If ($oNodeList.Count -ne "0")
{
Foreach ($oNode In $oNodeList)
{
$oPropertyBag = EquipmentFex $oNode $cNodeList
$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='ComputeSystemDn']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value>$Config/ComputeSystemDn$</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>