Cisco.UcsCentral.LocalServiceProfile.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$

Source Code:

<DataSourceModuleType ID="Cisco.UcsCentral.LocalServiceProfile.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="BladeClassId" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="RackUnitClassId" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="ServerUnitClassId" 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"/>
</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"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DataSource" TypeID="Windows!Microsoft.Windows.TimedPowerShell.DiscoveryProvider">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<SyncTime/>
<ScriptName>Cisco.UcsCentral.LocalServiceProfile.ps1</ScriptName>
<ScriptBody><Script>Param (
$Loging,
$ClassId,
$BladeClassId,
$RackUnitClassId,
$ServerUnitClassId,
$TypeId,
$WebProxyUrl,
$ProxyId,
$SeedMachineName,
$SourceId,
$ManagedEntityId
)

######
# 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 LocalLsServer($oNode, $iNode)
{

$serviceProfileDn = GetXmlAttribute $oNode "lsDn"
$uniqueId = "${ProxyId}:$serviceProfileDn"

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

$oLsServerInstance.AddProperty("$MPElement[Name='Cisco.Ucs.Seed']/MachineName$", $SeedMachineName)
$oLsServerInstance.AddProperty("$MPElement[Name='Cisco.UcsCentral.Root']/Id$", $ProxyId)
$orgDn = $serviceProfileDn.Remove($serviceProfileDn.LastIndexOf('/'))
$oLsServerInstance.AddProperty("$MPElement[Name='Cisco.UcsCentral.Organization']/Id$", "${proxyId}:$orgDn")
If ($orgDn -eq "org-root")
{
$oLsServerInstance.AddProperty("$MPElement[Name='Cisco.UcsCentral.Organization']/ParentMoniker$","")
}
Else
{
$oLsServerInstance.AddProperty("$MPElement[Name='Cisco.UcsCentral.Organization']/ParentMoniker$", $orgDn.substring(0, $orgDn.lastindexofany("/")))
}

$oLsServerInstance.AddProperty("$MPElement[Name='Cisco.Ucs.Entity']/UcsName$", $ProxyId)
$oLsServerInstance.AddProperty("$MPElement[Name='Cisco.Ucs.Object']/TypeId$", $TypeId)
$oLsServerInstance.AddProperty("$MPElement[Name='Cisco.UcsCentral.LocalServiceProfile']/Id$", $uniqueId)

#Cisco.Ucs.ServiceProfile
$oLsServerInstance.AddProperty("$MPElement[Name='Cisco.UcsCentral.LocalServiceProfile']/AssignState$", (GetXmlAttribute $iNode "assignState"))
$oLsServerInstance.AddProperty("$MPElement[Name='Cisco.UcsCentral.LocalServiceProfile']/AssocState$", (GetXmlAttribute $iNode "assocState"))
$oLsServerInstance.AddProperty("$MPElement[Name='Cisco.UcsCentral.LocalServiceProfile']/ConfigQualifier$", (GetXmlAttribute $iNode "configQualifier"))
$oLsServerInstance.AddProperty("$MPElement[Name='Cisco.UcsCentral.LocalServiceProfile']/ConfigState$", (GetXmlAttribute $iNode "configState"))
$oLsServerInstance.AddProperty("$MPElement[Name='Cisco.UcsCentral.LocalServiceProfile']/MgmtIpAddr$", (GetXmlAttribute $iNode "mgmtIpAddr"))
$oLsServerInstance.AddProperty("$MPElement[Name='Cisco.UcsCentral.LocalServiceProfile']/InstanceDn$", (GetXmlAttribute $iNode "dn"))
$oLsServerInstance.AddProperty("$MPElement[Name='Cisco.UcsCentral.LocalServiceProfile']/SysId$", (GetXmlAttribute $iNode "id"))
$oLsServerInstance.AddProperty("$MPElement[Name='Cisco.UcsCentral.LocalServiceProfile']/Name$", (GetXmlAttribute $oNode "name"))
$oLsServerInstance.AddProperty("$MPElement[Name='Cisco.UcsCentral.LocalServiceProfile']/OperState$", (GetXmlAttribute $iNode "operState"))
$oLsServerInstance.AddProperty("$MPElement[Name='Cisco.UcsCentral.LocalServiceProfile']/PhysicalDn$", (GetXmlAttribute $iNode "physDn"))
$oLsServerInstance.AddProperty("$MPElement[Name='Cisco.UcsCentral.LocalServiceProfile']/PolicyLevel$", (GetXmlAttribute $iNode "policyLevel"))
$oLsServerInstance.AddProperty("$MPElement[Name='Cisco.UcsCentral.LocalServiceProfile']/PolicyOwner$", (GetXmlAttribute $iNode "policyOwner"))
$oLsServerInstance.AddProperty("$MPElement[Name='Cisco.UcsCentral.LocalServiceProfile']/SystemName$", (GetXmlAttribute $iNode "systemName"))
$oLsServerInstance.AddProperty("$MPElement[Name='Cisco.UcsCentral.LocalServiceProfile']/UserLabel$", (GetXmlAttribute $iNode "usrLbl"))
$oLsServerInstance.AddProperty("$MPElement[Name='Cisco.UcsCentral.LocalServiceProfile']/UUID$", (GetXmlAttribute $iNode "uuid"))
$oLsServerInstance.AddProperty("$MPElement[Name='Cisco.UcsCentral.LocalServiceProfile']/Version$", (GetXmlAttribute $iNode "version"))


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

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


#System.Entity
$oLsServerInstance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", (GetXmlAttribute $oNode "name"))


return $oLsServerInstance
}

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

Function GetDisplayName($sNamePart)
{
$sDisplayName = "{0}"
return $sDisplayName.Replace("{0}", $sNamePart)
}
###
# Generate General Events
###
Function LogEvent ($sMessage, $iEventType, $iErrorEventId)
{
$oScriptAPI.LogScriptEvent("Cisco.Ucs.ServiceProfile.DataSource.ps1", $iErrorEventId, $iEventType, $sMessage)
}

######
# 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 computeInstance computeInstanceMapping"
$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))
{
$iNodeList = $oXmlDocument.GetElementsByTagName("computeInstance")
$oNodeList = $oXmlDocument.GetElementsByTagName("computeInstanceMapping")
$cNodeList = $oXmlDocument.GetElementsByTagName("computeSystem")

If ($oNodeList.Count -ne "0")
{
$oDiscoveryData = $oScriptAPI.CreateDiscoveryData(0, $SourceId, $ManagedEntityId)
Foreach ($oNode In $oNodeList)
{
$instanceDn = (GetXmlAttribute $oNode "instanceDn")
Foreach($iNode In $iNodeList)
{
$dn = (GetXmlAttribute $iNode "dn")
if( $dn -ieq $instanceDn)
{
$oLsServerInstance = LocalLsServer $oNode $iNode
$oDiscoveryData.AddInstance($oLsServerInstance)

#Add reference relationship to the Servers..
$assocState = GetXmlAttribute $iNode "assocState"
$serverDn = GetXmlAttribute $iNode "physDn"
$computeSystemDn=""
if( $assocState -eq "associated")
{


if($serverDn.Contains("blade") )
{
$oServerInstance = $oDiscoveryData.CreateClassInstance("$BladeClassId")
$ChassisDn = $serverDn.Remove($serverDn.LastIndexOf('/'))
$oServerInstance.AddProperty("$MPElement[Name='Cisco.Ucs.Chassis']/Id$", "${ProxyId}:$ChassisDn")
$computeSystemDn = $serverDn.Substring(0, $serverDn.Substring(0, $serverDn.LastIndexOf('/')).LastIndexOf('/'))
}
elseif($serverDn.Contains("server") )
{
$oServerInstance = $oDiscoveryData.CreateClassInstance("$ServerUnitClassId")
$CartridgeDn = $serverDn.Remove($serverDn.LastIndexOf('/'))
$ChassisDn = $CartridgeDn.Remove($CartridgeDn.LastIndexOf('/'))
$oServerInstance.AddProperty("$MPElement[Name='Cisco.Ucs.Chassis']/Id$", "${ProxyId}:$ChassisDn")
$oServerInstance.AddProperty("$MPElement[Name='Cisco.Ucs.Cartridge']/Id$", "${ProxyId}:$CartridgeDn")
$computeSystemDn = $serverDn.Substring(0, $serverDn.Substring(0, $serverDn.Substring(0, $serverDn.LastIndexOf('/')).LastIndexOf('/')).LastIndexOf('/'))

}
else
{
$oServerInstance = $oDiscoveryData.CreateClassInstance("$RackUnitClassId")
$computeSystemDn = $serverDn.Substring(0, $serverDn.LastIndexOf('/'))
}

#$computeSystemDn = $serverDn.Substring(0, $serverDn.Substring(0, $serverDn.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"
$oServerInstance.AddProperty("$MPElement[Name='Cisco.UcsCentral.DomainGroup']/Id$",$DomainGroupUniqueDn )
If (($DomainGroupDn -eq "domaingroup-root") -or ($DomainGroupDn -eq "Ungrouped-Domains"))
{
$oServerInstance.AddProperty("$MPElement[Name='Cisco.UcsCentral.DomainGroup']/ParentMoniker$","")
}
Else
{
$oServerInstance.AddProperty("$MPElement[Name='Cisco.UcsCentral.DomainGroup']/ParentMoniker$", $DomainGroupDn.substring(0, $DomainGroupDn.lastindexofany("/")))
}
$oServerInstance.AddProperty("$MPElement[Name='Cisco.Ucs.Proxy']/Id$", "sys-"+(GetXmlAttribute $cNode "id"))
}
}

$oServerInstance.AddProperty("$MPElement[Name='Cisco.UcsCentral.Root']/Id$", $ProxyId)
$oServerInstance.AddProperty("$MPElement[Name='Cisco.Ucs.Seed']/MachineName$", $SeedMachineName)
$oServerInstance.AddProperty("$MPElement[Name='Cisco.Ucs.Server']/Id$", "${ProxyId}:$serverDn")

$oReferenceRelCon = $oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='Cisco.UcsCentral.LocalServiceProfileRefersServer']$")
$oReferenceRelCon.Source = $oLsServerInstance
$oReferenceRelCon.Target = $oServerInstance
$oDiscoveryData.AddInstance($oReferenceRelCon)
}
}
}
#$oLsServerInstance = LsServer $oNode
#$oDiscoveryData.AddInstance($oLsServerInstance)

}
}
}
}

$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>BladeClassId</Name>
<Value>$Config/BladeClassId$</Value>
</Parameter>
<Parameter>
<Name>RackUnitClassId</Name>
<Value>$Config/RackUnitClassId$</Value>
</Parameter>
<Parameter>
<Name>ServerUnitClassId</Name>
<Value>$Config/ServerUnitClassId$</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>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DataSource"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>