OpsMgr 2007 MP Error – Try Using a Fully Qualified Name

I ran into the following error while developing my vCenter Management Pack; it plagued me for days: Unable to resolve the monitoring class property name specified in the discovery data item. Try using a fully qualified name.

My class hierarchy looks like this:

vCenter Server –hosts–> Datacenter –hosts–> Hosts –contains–> (host instances) –hosts–> Interfaces

My discovery targets the “Hosts” class, because I need it to run on the vCenter server itself. However, this error only occurred when I tried to discover host interfaces, not hosts. The property name listed in the error event data was the ‘host instance’ key property “Uid“. So, my discoveryData string looked something like “$MPElement[Name=’JPPacks.VMWare.vCenter.vCenterServer.Datacenter.ESXCluster.Host]/Uid$” . The problem was that OpsMgr couldn’t resolve this MPElement variable to the GUID of the Host/Uid property in the OpsMgr Database because it can only resolve MPElement variables of elements in the target’s tree. Because my host instances are contained by hosts, and not hosted by hosts, it couldn’t resolve the property GUID.

Luckily, the OpsMgr Command Shell can.

I had to use this method to find the GUID to discover the interface instances:

  1. Load the MOM Snap-in
  2. Find and connect to the OpsMgr RMS
  3. Find the GUID of the Host Instance’s UID property.
  4. Use the GUID instead of a regular MPElement variable.

Here is some code to help! To make it work, change the class name in the function “Get-PropertyGUID”. Don’t forget to look through the script on your own; I’m a prolific PowerShell script writer, but I’m still a hack. Also, you must have the OpsMgr Command Shell installed on the system running this script. If you’re using this script in an actual discovery, the computer system’s account must be in the “MOM Operators” group. Since you can’t add computers directly, you’ll need to create an AD group with the computer as a member, then add that newly created group to the MOM Operators role.


$error.clear()
$fail = $false
$scriptName = "Mom-GUIDLookup.ps1 b02"
$opsmgrAPI = New-Object -comObject 'MOM.ScriptAPI'

#global vars
$script:debugLevel = 4 #verbosity
$script:blnWriteToScreen = $true #write to the screen
$script:blnWriteToOpsMgrLog = $false #write to the opsmgr log

Function Write-Out($msg,$severity)
{
$intLevel = 4
If($intLevel -eq $null)
{$intLevel = 4}

If($severity -eq $null)
{$severity = 0}

If($intLevel -le $script:debugLevel)
{
If($script:blnWriteToScreen -eq $true)
{
Switch($severity)
{
0 {$color = "white"}
1 {$color = "yellow"}
2 {$color = "magenta"}
}
Write-Host -f $color $msg
}
Else{}
If($script:blnWriteToOpsMgrLog -eq $true)
{
If($severity -eq 1){$severity = 2}
ElseIf($severity -eq 2){$severity = 1}
$opsmgrAPI.LogScriptEvent($scriptName,0,$severity,$msg)
}
Else{}
}
}

Function Load-MOMSnapin
{
$fail = $null
$fail = $false
$snapin = "Microsoft.EnterpriseManagement.OperationsManager.Client"
$msg = "Script is attempting to load snap-in: """ + $snapin + """."
Write-Out $msg
$snapinTest = $null
$snapinTest = Get-PSSnapin $snapin -registered -ea silentlycontinue
If($snapinTest -ne $null)
{
$msg = "The required snap-in is installed on this system: """ + $snapin + """. Adding the snap-in."
Write-Out $msg
$snapinTest = $null
$snapinTest = Get-PSSnapin $snapin -ea silentlycontinue
If($snapinTest -eq $null)
{$blnAdded = Add-PSSnapin $snapin}
Else
{}
}
Else
{
$fail = $true
$msg = "Required Snap-In is not installed on this system: """ + $snapin + """."
Write-Out $msg 2
}

If($fail -eq $false)
{
$snapinTest = $null
$snapinTest = Get-PSSnapin $snapin
if($snapinTest -eq $null)
{
$fail = $true
$msg = "Script didn't complete loading snap-ins; could not add the snapin: """ + $snapin + """."
Write-Out $msg 2
}
}

If($fail -eq $false)
{$retval = $true}
Else
{$retval = $false}
Return $retval
}

Function Get-RMSServer
{
$RMSServer = $null

$machineKey = "HKLM:\\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Machine Settings"
If((Test-Path $machineKey) -eq $true)
{
$objKey = Get-ItemProperty -path:$machineKey -name:"DefaultSDKServiceMachine" -ErrorAction:SilentlyContinue
If($objKey -ne $null -and $objKey -ne "")
{$RMSServer = $objKey.DefaultSDKServiceMachine}
}

If($RMSServer -eq $null -or $RMSServer -eq "")
{
#write-host -f green "ehy"
$MgmtGroupsKey = $null
$MgmtGroupsKey = "HKLM:\\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Agent Management Groups"
If((Test-Path $mgmtGroupsKey) -eq $false)
{
$msg = "Failed to process a syslog event; can't find the RMS Server name in registry"
Write-Out $msg 2
}
Else
{
$mgmtGroups = $null
$mgmtGroups = GCI $MgmtGroupsKey
#write-host -f cyan $MgmtGroupsKey

If($mgmtGroups -is [array])
{$strMgmtGroupKey = $mgmtGroups[0].Name}
Else
{$strMgmtGroupKey = $mgmtGroups.Name}

$strMgmtGroupKey = $strMgmtGroupKey -replace("HKEY_LOCAL_MACHINE","HKLM:\")
#write-host -f yellow $strMgmtGroupKey

$strMachineKey = $null
$strMachineKey = $strMgmtGroupKey + "\Parent Health Services"
$RMSServer = $null
$RMSServer = (Get-ItemProperty -path:$strMachineKey -name:"NetworkName" -ErrorAction:SilentlyContinue).NetworkName
}
}
#write-host -f yellow "RMSServer: $RMSServer"
Return $RMSServer
}

Function Get-HostUIDPropertyGUID()
{
$objClassObjects = $null
$objClassObjects = Get-MonitoringClass -name "JPPacks.VMWare.vCenter.vCenterServer.Datacenter.ESXCluster.Host" -path "OperationsManagerMonitoring::" | Get-MonitoringObject -path "OperationsManagerMonitoring::"

Foreach($objClassObject in $objClassObjects)
{
$objUID = $null
$prop = $null
$prop = "[JPPacks.VMWare.vCenter.vCenterServer.Datacenter.ESXCluster.Host].Uid"
$objUID = $objClassObject.$prop
$name = $objClassObject.Name
$objProperty = $objClassObject.GetMonitoringProperties() | Where-Object {$_.Name -eq "Uid"}
$strHostUidGuid = $objProperty.Id.Guid
}

Return $strHostUidGuid
}

#Load MOM Snap-Ins
If($fail -eq $false)
{
$blnLoaded = Load-MOMSnapin
If($blnLoaded -ne $true)
{$fail = $true}
}

$opsmgrRMS = Get-RMSServer
If($opsmgrRMS -eq $null -or $opsmgrRMS -eq "")
{
$msg = "Could not get the RMS server name from the registry."
Write-Out $msg
$fail = $true
}

#connect to mgmt server
If($fail -eq $false)
{
$msg = "Connecting to the management server """ + $opsmgrRMS + """."
Write-Out $msg
$strConnect = New-ManagementGroupConnection $opsmgrRMS
$msg = "Connection result: """ + $strConnect + """."
Write-Out $msg
If($strConnect -eq "")
{
$msg = "Failed to connecto the management server: """ + $opsmgrRMS + """."
Write-Out $msg 2
$fail = $true
}
}

 

$GUID = Get-HostUIDPropertyGUID
$msg = "GUID: """ + $GUID + """."
Write-Out $msg

Advertisements

2 thoughts on “OpsMgr 2007 MP Error – Try Using a Fully Qualified Name

  1. Pingback: OpsMgr 2007 MP Authoring – Proxying Syslog Events « windowsmasher

  2. Pingback: Table of Contents | windowsmasher

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s