Monitoring and reporting for Veeam Backup & Replication, VMware vSphere and Microsoft Hyper-V in a single System Center Operations Manager Console
Post Reply
sbanyas
Novice
Posts: 7
Liked: never
Joined: Jul 01, 2015 8:46 pm
Full Name: Scott Banyas
Contact:

VMware Virtual Machine object group based on AD

Post by sbanyas »

Kinda a weird one here that I haven't been able to figure out ... yet.

I'm trying to create a "dynamic" group within SCOM based on server(s) in an Active Directory group. I'm using pieces of Powershell script originally written by Arjan Vroege.

I can get the Windows Computer object to populate in the group correctly, but am struggling with the VMware Virtual Machine object. (we need both objects for the server(s) for dashboarding purposes).

The code snippets are from my custom MP:
...
<ClassType ID="FBL.Troubleshooting.AD.Group" Accessibility="Public" Abstract="false" Base="System!System.Group" Hosted="false" Singleton="true" Extension="false" />
</ClassTypes>
<RelationshipTypes>
<RelationshipType ID="FBL.Troubleshooting.AD.Group.Contains.Windows.Computer" Accessibility="Internal" Abstract="false" Base="System!System.Containment">
<Source ID="FBL.Troubleshooting.AD.Group.Rel.Source" Type="FBL.Troubleshooting.AD.Group" />
<Target ID="FBL.Troubleshooting.AD.Group.Rel.Target.Windows.Computer" Type="Windows!Microsoft.Windows.Computer" />
</RelationshipType>
<RelationshipType ID="FBL.Troubleshooting.AD.Group.Contains.VMware.VMGUEST" Accessibility="Internal" Abstract="false" Base="System!System.Containment">
<Source ID="FBL.Troubleshooting.AD.Group.Rel.Source" Type="FBL.Troubleshooting.AD.Group" />
<Target ID="FBL.Troubleshooting.AD.Group.Rel.Target.VMware.VMGUEST" Type="VeeamVirtExtensionsVMwareLibrary8002218!Veeam.Virt.Extensions.VMware.VMGUEST" />
</RelationshipType>
</RelationshipTypes>
....
<Discovery ID="FBL.Troubleshooting.AD.Group.DiscoveryRule" Enabled="true" Target="SystemCenter!Microsoft.SystemCenter.RootManagementServer" ConfirmDelivery="false" Remotable="true" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="FBL.Troubleshooting.AD.Group" />
</DiscoveryTypes>
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedPowerShell.DiscoveryProvider">
<IntervalSeconds>120</IntervalSeconds>
<SyncTime />
<ScriptName>AD_GroupDiscovery_check.ps1</ScriptName>
<ScriptBody>
# AD_GroupDiscovery_check.ps1
# Written by Arjan Vroege. All rights reserved.

param($SourceID, $ManagedEntityID)

Clear-Variable -Name groupInstance
Clear-Variable -Name groupmembers
Clear-Variable -Name member
Clear-Variable -Name DNSHostName

$scomapi = new-object -comObject "MOM.ScriptAPI"
$DiscData = $scomapi.CreateDiscoveryData(0, $SourceID, $ManagedEntityID)

$scomapi.LogScriptEvent("AD_GroupDiscovery_check.ps1",101,0, "Discovery was executed")

$groupInstance = $DiscData.CreateClassInstance("$MPElement[Name='FBL.Troubleshooting.AD.Group']$")

$groupmembers = Get-ADGroupMember -Identity "SAVAGETestGroup"
foreach($member in $groupmembers) {
$DNSHostName = Get-ADComputer -Filter 'Name -eq $member.Name' | Select -Expand DNSHostName
If($DNSHostName) {
$scomapi.LogScriptEvent("AD_GroupDiscovery_check.ps1",101,0, "Instance $DNSHostName")

$ComputerServerInstance = $DiscData.CreateClassInstance("$MPElement[Name='Windows!Microsoft.Windows.Server.Computer']$")
$ComputerServerInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $DNSHostName)

$ComputerRelationshipInstance = $DiscData.CreateRelationshipInstance("$MPElement[Name='FBL.Troubleshooting.AD.Group.Contains.Windows.Computer']$")
$ComputerRelationshipInstance.Source = $groupInstance
$ComputerRelationshipInstance.Target = $ComputerServerInstance
$DiscData.AddInstance($ComputerRelationshipInstance)

<!-- Instantiates the Veeam class -->
$VMGUESTServerInstance = $DiscData.CreateClassInstance("$MPElement[Name='VeeamVirtExtensionsVMwareLibrary8002218!Veeam.Virt.Extensions.VMware.VMGUEST']$")
$VMGUESTServerInstance.AddProperty("$MPElement[Name="VeeamVirtExtensionsVMwareLibrary8002218!Veeam.Virt.Extensions.VMware.VMGUEST"]/guestHostName$", $DNSHostName)

$VMGUESTRelationshipInstance = $DiscData.CreateRelationshipInstance("$MPElement[Name='FBL.Troubleshooting.AD.Group.Contains.VMware.VMGUEST']$")
$VMGUESTRelationshipInstance.Source = $groupInstance
$VMGUESTRelationshipInstance.Target = $VMGUESTServerInstance
$DiscData.AddInstance($VMGUESTRelationshipInstance)

} Else {
$scomapi.LogScriptEvent("AD_GroupDiscovery_check.ps1",101,2, "$member instance is not a computer")
}
}

$discData
</ScriptBody>
<Parameters>
<Parameter>
<Name>sourceId</Name>
<Value>$MPElement$</Value>
</Parameter>
<Parameter>
<Name>managedEntityId</Name>
<Value>$Target/Id$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>300</TimeoutSeconds>
<StrictErrorHandling>true</StrictErrorHandling>
</DataSource>
</Discovery>


The following is an error code in my Operations Manager event log:


Discovery data couldn't be inserted to the database. This could have happened because of one of the following reasons:

- Discovery data is stale. The discovery data is generated by an MP recently deleted.
- Database connectivity problems or database running out of space.
- Discovery data received is not valid.

The following details should help to further diagnose:

DiscoveryId: ec3c0971-1ccf-28c0-7613-0d88d1b65c30
HealthServiceId: eead0f7c-62a4-c185-2ba5-4e0ee925fb60
Microsoft.EnterpriseManagement.Common.DiscoveryDataMissingKeyException,Missing key in the discovery data item.
Key property name: Veeam.Virt.Extensions.VMware.VMGUEST.id
Rule ID: ec3c0971-1ccf-28c0-7613-0d88d1b65c30
Instance:
<?xml version="1.0" encoding="utf-16"?><ClassInstance TypeId="{c16b369d-03d1-b8dc-dc18-e898f96288d3}"><Settings><Setting><Name>b6f2cb36-e6f4-d554-0c6b-fbfc00cc9b58</Name><Value>phoscsccm03.fbfs.com</Value></Setting></Settings></ClassInstance>.
Alec King
VP, Product Management
Posts: 1445
Liked: 362 times
Joined: Jan 01, 2006 1:01 am
Contact:

Re: VMware Virtual Machine object group based on AD

Post by Alec King »

Hi Scott,

At first glance it looks like your discovery/script is not providing the essential Key ID property for VMGuest Virtual Machine - Veeam.Virt.Extensions.VMware.VMGUEST.id.

This is the only key ID property for that class. Unlike Windows server class, the DNS Name is NOT the key ID property for VM class.

The VMGUEST Key ID is made of vCenter Name + VM MOREF (vCenter ID for the VM) and will look something like 'PRODVC.domain.local:VM-1234'.

I'll get my team to double-check your script and post back here.

Cheers
Alec
sergey.g
Veteran
Posts: 452
Liked: 76 times
Joined: May 02, 2012 1:49 pm
Full Name: Sergey Goncharenko
Contact:

Re: VMware Virtual Machine object group based on AD

Post by sergey.g »

Hi Scott,

I'll try to add more, but Alec is correct and you need to find ID of a VM with the corresponding DNS name. I was able to come up with something like this:

Code: Select all

$VM_id=get-scomclass -name "Veeam.Virt*VMware*VMGUEST" | get-scomclassinstance | select name, @{n='DNS';e={$_ | select -expand values | ? {$_.Type -like "guesthostname"}}} | ? {$_.DNS -like $DNSHostName}
Then $VM_id.Name will contain ID of the Virtual Machine which you can use for creating it for the releationship target

Code: Select all

$VMGUESTServerInstance.AddProperty("$MPElement[Name="VeeamVirtExtensionsVMwareLibrary8002218!Veeam.Virt.Extensions.VMware.VMGUEST"]/id$", $VM_id.Name)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest