Port Data Source

Cisco.Unified.Computing.System.Port.DataSource (DataSourceModuleType)

Port Data Source Description

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityPublic
RunAsDefault
OutputTypeSystem.Discovery.Data

Member Modules:

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

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$Interval SecondsInterval Seconds Description
LogingLevelint$Config/LogingLevel$Logging Level (0/1)Logging Level (0/1) Description
SendRequestbool$Config/SendRequest$Send RequestSend Request Description
TimeoutSecondsint$Config/TimeoutSeconds$Timeout SecondsTimeout Seconds Description

Source Code:

<DataSourceModuleType ID="Cisco.Unified.Computing.System.Port.DataSource" Accessibility="Public" Batching="false">
<Configuration>
<IncludeSchemaTypes>
<SchemaType>System!System.Discovery.MapperSchema</SchemaType>
</IncludeSchemaTypes>
<xsd:element minOccurs="1" name="ClassId" type="xsd:string"/>
<xsd:element minOccurs="1" name="InstanceSettings" type="SettingsType"/>
<xsd:element minOccurs="1" name="IntervalSeconds" type="xsd:integer"/>
<xsd:element minOccurs="1" name="LogingLevel" type="xsd:integer"/>
<xsd:element minOccurs="1" name="Moniker" type="xsd:string"/>
<xsd:element minOccurs="1" name="PortData" type="xsd:string"/>
<xsd:element minOccurs="1" name="SecureInput" type="xsd:string"/>
<xsd:element minOccurs="1" name="SendRequest" type="xsd:boolean"/>
<xsd:element minOccurs="1" name="TimeoutSeconds" type="xsd:integer"/>
<xsd:element minOccurs="1" name="TypeId" type="xsd:string"/>
<xsd:element minOccurs="1" name="Url" type="xsd:string"/>
<xsd:element minOccurs="1" name="UserName" type="xsd:string"/>
<xsd:element minOccurs="1" name="WebProxyUrl" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="LogingLevel" Selector="$Config/LogingLevel$" ParameterType="int"/>
<OverrideableParameter ID="SendRequest" Selector="$Config/SendRequest$" ParameterType="bool"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="Scheduler" TypeID="System!System.Discovery.Scheduler">
<Scheduler>
<SimpleReccuringSchedule>
<Interval Unit="Seconds">$Config/IntervalSeconds$</Interval>
</SimpleReccuringSchedule>
<ExcludeDates/>
</Scheduler>
</DataSource>
<ProbeAction ID="PSScriptPropertyBagProbe" TypeID="Windows!Microsoft.Windows.PowerShellPropertyBagTriggerOnlyProbe">
<ScriptName>Cisco.Unified.Computing.System.Port.DataSource.ps1</ScriptName>
<ScriptBody><Script>
Param (
$Loging,
$Moniker,
$PortData,
$SecureInput,
$SendRequest,
$TypeId,
$Url,
$UserName,
$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 "ScomUcsAgent"
########################################################################################

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

#ScomUcsAgent Url
$sWebProxyUrl = $WebProxyUrl
$sPortData = $PortData
#Toggle Log Generation
$sLoging = $Loging

#Connection
$sUrl = $Url

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

#Parent distinguished name
$sMoniker = $Moniker

#Cache
$bSendRequest = $SendRequest
$sTypeId = $TypeId

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

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

Function PortGroup($oNode)
{
$oPortGroup = GetPropertyBag("false")

$sId = GetXmlAttribute $oNode "portId"

#Cisco.Unified.Computing.System.Port
$oPortGroup.AddValue("ChassisId", (GetXmlAttribute $oNode "chassisId"))
$oPortGroup.AddValue("EpDn", (GetXmlAttribute $oNode "epDn"))
$oPortGroup.AddValue("Id", "$sId")
$oPortGroup.AddValue("IfRole", (GetXmlAttribute $oNode "ifRole"))
$oPortGroup.AddValue("IfType", (GetXmlAttribute $oNode "ifType"))
$oPortGroup.AddValue("LicState", (GetXmlAttribute $oNode "licState"))
$oPortGroup.AddValue("Locale", (GetXmlAttribute $oNode "locale"))
$oPortGroup.AddValue("Mac", (GetXmlAttribute $oNode "mac"))
$oPortGroup.AddValue("Mode", (GetXmlAttribute $oNode "mode"))
$oPortGroup.AddValue("OperSpeed", (GetXmlAttribute $oNode "operSpeed"))
$oPortGroup.AddValue("PeerChassisId", (GetXmlAttribute $oNode "peerChassisId"))
$oPortGroup.AddValue("PeerDn", (GetXmlAttribute $oNode "peerDn"))
$oPortGroup.AddValue("PeerPortId", (GetXmlAttribute $oNode "peerPortId"))
$oPortGroup.AddValue("PeerSlotId", (GetXmlAttribute $oNode "peerSlotId"))
$oPortGroup.AddValue("SlotId", (GetXmlAttribute $oNode "slotId"))
$oPortGroup.AddValue("StateQual", (GetXmlAttribute $oNode "stateQual"))
$oPortGroup.AddValue("SwitchId", (GetXmlAttribute $oNode "switchId"))
$oPortGroup.AddValue("Transport", (GetXmlAttribute $oNode "transport"))
$oPortGroup.AddValue("Type", (GetXmlAttribute $oNode "type"))
$oPortGroup.AddValue("XcvrType", (GetXmlAttribute $oNode "xcvrType"))

#Cisco.Unified.Computing.System.Device
$oPortGroup.AddValue("Model", (GetXmlAttribute $oNode "model"))
$oPortGroup.AddValue("Revision", (GetXmlAttribute $oNode "revision"))
$oPortGroup.AddValue("SerialNumber", (GetXmlAttribute $oNode "serial"))
$oPortGroup.AddValue("Vendor", (GetXmlAttribute $oNode "vendor"))
$oPortGroup.AddValue("UserLabel", (GetXmlAttribute $oNode "usrLbl"))

#Cisco.Unified.Computing.System.Entity
$oPortGroup.AddValue("Moniker", (GetXmlAttribute $oNode "dn"))

#Cisco.Unified.Computing.System.Object
$oPortGroup.AddValue("Description", (GetXmlAttribute $oNode "descr"))

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

return $oPortGroup
}

######
# Getting Display Name for the UCS Component
######
Function GetDisplayName($sNamePart)
{
$sDisplayName = "Port {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)
{
$oPBag = $oScriptAPI.CreateTypedPropertyBag($cSTATEDATA)

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

return $oPBag
}

###
# Generate General Events
###
Function LogEvent ($sMessage, $iEventType, $iErrorEventId)
{
$oScriptAPI.LogScriptEvent("Cisco.Unified.Computing.System.Port.DataSource.ps1", $iErrorEventId, $iEventType, $sMessage)
}

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

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

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

If ((![string]::IsNullOrEmpty($sUserName)) -AND ($sUserName.Contains("@")))
{
$sUserName = 'ucs-' + $sUserName.Split('@')[1] + '\' + $sUserName.Split('@')[0]
}

If (![string]::IsNullOrEmpty($sWebProxyUrl))
{
Try
{
$oConnection = New-WebServiceProxy -Uri ($sWebProxyUrl + "?WSDL") -Namespace "Cisco.Ucs.UcsAgent"
If ($oConnection -eq $null)
{
#LogEvent "Connection to Cisco UCS Management Service failed." $cERROR $cCODE
Exit
}
$oXmlDocument = $oConnection.ConfigScope($sUrl, $sUserName, $sSecureInput, "false", "false", $sMoniker, $sPortData.Split(" ")[0].Trim() , $bSendRequest, $sTypeId)
}
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($sPortData.Split(" ")[0].Trim())

if ($oNodeList.Count -eq "0")
{
Exit
}

$sMoniker = $sMoniker + $sPortData.Split(" ")[1].Trim()
Foreach ($oNode in $oNodeList | Where-Object {$_.dn -like "$sMoniker*"})
{
$oPropertyBag = PortGroup $oNode
$oScriptAPI.AddItem($oPropertyBag)
#$oScriptAPI.Return($oPropertyBag)
$oPropertyBag
}
}
Else
{
LogEvent "Response XML document is empty" $cERROR $cCODE
Exit
}

$oConnection = $null
$endTime = (Get-Date)
If ($sLoging -eq "1"){
$totalTimes = ($endTime - $startTime).TotalMilliseconds
LogEvent "$totalTimes" $cERROR $cCODE
}

}
Else
{
#LogEvent "Service Connection error" $cERROR $cCODE
Exit
}

$oPropertyBag = GetPropertyBag "true"
$oScriptAPI.AddItem($oPropertyBag)
#$oScriptAPI.Return($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>Moniker</Name>
<Value>$Config/Moniker$</Value>
</Parameter>
<Parameter>
<Name>PortData</Name>
<Value>$Config/PortData$</Value>
</Parameter>
<Parameter>
<Name>SecureInput</Name>
<Value>$Config/SecureInput$</Value>
</Parameter>
<Parameter>
<Name>SendRequest</Name>
<Value>$Config/SendRequest$</Value>
</Parameter>
<Parameter>
<Name>TypeId</Name>
<Value>$Config/TypeId$</Value>
</Parameter>
<Parameter>
<Name>Url</Name>
<Value>$Config/Url$</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>
<ConditionDetection ID="ExpressionFilter" TypeID="System!System.ExpressionFilter">
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery>Property[@Name='IsEmpty']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value>false</Value>
</ValueExpression>
</SimpleExpression>
</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="Scheduler"/>
</Node>
</Node>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>