Origen de datos de detección de relación entre agentes

Microsoft.SystemCenter.ADIntegrationRelationshipDiscovery (DataSourceModuleType)

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityInternal
RunAsSystem.PrivilegedMonitoringAccount
OutputTypeSystem.Discovery.Data

Member Modules:

ID Module Type TypeId RunAs 
DataSource DataSource Microsoft.Windows.TimedScript.DiscoveryProvider Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$Intervalo (segundos)
TimeoutSecondsint$Config/TimeoutSeconds$Tiempo de espera en segundos

Source Code:

<DataSourceModuleType ID="Microsoft.SystemCenter.ADIntegrationRelationshipDiscovery" Accessibility="Internal" RunAs="System!System.PrivilegedMonitoringAccount" Batching="false">
<Configuration>
<xsd:element name="IntervalSeconds" type="xsd:integer"/>
<xsd:element name="TimeoutSeconds" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DataSource" TypeID="Windows!Microsoft.Windows.TimedScript.DiscoveryProvider">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<SyncTime/>
<ScriptName>DiscoverHealthServiceCommunicationRelationships.js</ScriptName>
<Arguments>0 $MPElement$ $Target/Id$ $Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$ "$Target/ManagementGroup/Name$"</Arguments>
<ScriptBody><Script>

var oAPI = new ActiveXObject("MOM.ScriptAPI");
var oShell = new ActiveXObject("WScript.Shell");
var oArgs = WScript.Arguments;

// Process Arguments:
// 0 - SourceType
// 1 - SourceId
// 2 - ManagedEntityId
// 3 - ComputerIdentity
// 4 - ManagementGroupName

var SourceType = oArgs(0);
var SourceId = oArgs(1);
var ManagedEntityId = oArgs(2);
var ComputerIdentity = oArgs(3);
var ManagementGroupName = oArgs(4);

WScript.Echo("\nSourceType: " + SourceType);
WScript.Echo("SourceId " + SourceId);
WScript.Echo("ManagedEntityId: " + ManagedEntityId);
WScript.Echo("ComputerIdentity: " + ComputerIdentity);
WScript.Echo("ManagementGroupName: " + ManagementGroupName);

var SCRIPT_NAME = "DiscoverHealthServiceCommunicationRelationships.js";
var ENU_MESSAGE_BASE = "HealthServiceCommuncation relationship discovery for HealthServices configured via AD Integration\n\r";
var MAX_FAILOVERS = 10;

var EVENTLOG_SUCCESS = 0x0000; /* Information event */
var EVENTLOG_AUDIT_FAILURE = 0x0010; /* Failure Audit event */
var EVENTLOG_AUDIT_SUCCESS = 0x0008; /* Success Audit event */
var EVENTLOG_ERROR_TYPE = 0x0001; /* Error event */
var EVENTLOG_INFORMATION_TYPE = 0x0004; /* Information event */
var EVENTLOG_WARNING_TYPE = 0x0002; /* Warning event */

// Checking for the EnableADIntegration and UseActiveDirectory keys are also done in the DiscoverAgentRelationships.js discovery
// That script actually updates the HealthService.ActiveDirectoryManaged property as well as submits discovery data for
// the AgentRelationshipSettings object. These checks are duplicated here just for error checking in case the RegKeys were
// manually removed and we have not run discovery yet.

var EnableADIntegrationRegValue = "HKLM\\SYSTEM\\CurrentControlSet\\Services\\HealthService\\Parameters\\ConnectorManager\\EnableADIntegration";
var UseActiveDirectoryRegValue = "HKLM\\SOFTWARE\\Microsoft\\Microsoft Operations Manager\\3.0\\Agent Management Groups\\" + ManagementGroupName + "\\UseActiveDirectory";
var PrimarySCPInfoRegValue = "HKLM\\SOFTWARE\\Microsoft\\Microsoft Operations Manager\\3.0\\Agent Management Groups\\" + ManagementGroupName + "\\AD Cache\\Primary SCP Info\\Service DNS Name";
var SecondarySCPInfoRootRegKey = "HKLM\\SOFTWARE\\Microsoft\\Microsoft Operations Manager\\3.0\\Agent Management Groups\\" + ManagementGroupName + "\\AD Cache\\Secondary SCP Info Root\\";

var EnableADIntegration = new Boolean(SafeRegRead(EnableADIntegrationRegValue));
var UseActiveDirectory;

try
{
UseActiveDirectory = new Boolean(oShell.RegRead(UseActiveDirectoryRegValue));
}
catch (e)
{
switch (e.number &amp; 0xFFFF)
{
// HRESULT 0x80070002: ERROR_FILE_NOT_FOUND - Severity: FAILURE (1), FACILITY_WIN32 (0x7), Code 0x2
// If UseActiveDirectory RegValue DOES NOT EXIST the agent for this Management Group IS AD Integrated
case 2 :
UseActiveDirectory = new Boolean(true);
break;
default :
PrintError(e);
throw(e);
}
}



WScript.Echo("\nEnableADIntegration value: " + EnableADIntegration);
WScript.Echo("UseActiveDirectory value: " + UseActiveDirectory);

if ((EnableADIntegration == false) || (UseActiveDirectory == false))
{
var oDiscovery = oAPI.CreateDiscoveryData(SourceType, SourceId, ManagedEntityId);
oDiscovery.IsSnapshot = false;
oAPI.Return(oDiscovery);
}


if ((EnableADIntegration == true) &amp;&amp; (UseActiveDirectory == true))
{
var PrimarySCPInfo = SafeRegRead(PrimarySCPInfoRegValue);
WScript.Echo("\nPrimary SCP Info value: " + PrimarySCPInfo);
}

if ((EnableADIntegration == true) &amp;&amp; (UseActiveDirectory == true))
{
// There can be many Secondary SCP Info reg keys. For RC1, just going to do 10
// In RC2 may change this to WMI StdRegProv so we can enumerate through the Secondary SCP Info Root key
// WshShell.RegRead() doesn't return objects.

var SecondarySCPInfoPrefix = "Secondary SCP Info ";
var SecondarySCPInfoRegKeys = new Array(MAX_FAILOVERS -1);

for (var i = 0; i &lt; MAX_FAILOVERS; i++)
{
if (PrimarySCPInfo != null)
{
var regPath = SecondarySCPInfoRootRegKey + SecondarySCPInfoPrefix + (i+1).toString() + "\\Service DNS Name";
var regValue = SafeRegRead(regPath);

if (regValue != null)
{
// Verify Topology
// -- Bad Topo #1: 2 Primary relationships.
// This one can't happen since I only read one specific RegValue and create only 1 relationship instance
// Note that if there are ever any 2 Secondary TARGETs pointing to the same server, its already handled on the server side
// -- Bad Topo #2: Both Primary and Secondary TARGETs point to same DNS Name
if (PrimarySCPInfo.toString().toLowerCase() == regValue.toString().toLowerCase())
{
var ENU_MESSAGE = ENU_MESSAGE_BASE
ENU_MESSAGE += "Invalid topology detected.\n";
ENU_MESSAGE += "\tRelationship Source (Agent) : " + ComputerIdentity + "\n";
ENU_MESSAGE += "\tRelationship Target (Primary SCP Info) : " + PrimarySCPInfo.toString() + "\n";
ENU_MESSAGE += "\tRelationship Target (Secondary SCP Info): " + regValue.toString() + "\n\n";
ENU_MESSAGE += "Ignoring cached Secondary SCP Info from: " + regPath + "\n";

oAPI.LogScriptEvent(SCRIPT_NAME, 6029, EVENTLOG_WARNING_TYPE, ENU_MESSAGE);

WScript.Echo(PrimarySCPInfo.toString().toLowerCase());
WScript.Echo(regValue.toString().toLowerCase());
WScript.Echo(ENU_MESSAGE);
}
else
{
SecondarySCPInfoRegKeys[i] = regValue;
}
}
}
}
SecondarySCPInfoRegKeys = SecondarySCPInfoRegKeys.sort();
}


if ((PrimarySCPInfo != null) || (SecondarySCPInfoRegKeys != null))
{
var oDiscovery = oAPI.CreateDiscoveryData(SourceType, SourceId, ManagedEntityId);

// Discovery data for Primary communication - Microsoft.SystemCenter.HealthServiceCommunication

// Source of HealthServiceCommunication relationship
var oHSCommunicationSource = oDiscovery.CreateClassInstance("$MPElement[Name='SCLibrary!Microsoft.SystemCenter.HealthService']$");
oHSCommunicationSource.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", ComputerIdentity);

// Target of HealthServiceCommunication relationship
var oHSCommunicationTarget = oDiscovery.CreateClassInstance("$MPElement[Name='SCLibrary!Microsoft.SystemCenter.HealthService']$");
oHSCommunicationTarget.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", PrimarySCPInfo.toString());

var oHealthServiceCommunication = oDiscovery.CreateRelationshipInstance("$MPElement[Name='SCLibrary!Microsoft.SystemCenter.HealthServiceCommunication']$");
oHealthServiceCommunication.Source = oHSCommunicationSource;
oHealthServiceCommunication.Target = oHSCommunicationTarget;

oDiscovery.AddInstance(oHealthServiceCommunication);

// Discovery data for Secondary failover communcation instances - Microsoft.SystemCenter.HealthServiceSecondaryCommunication
// Can be null since there may be no failovers configured at all
if (SecondarySCPInfoRootRegKey != null)
{
// Source of HealthServiceSecondaryCommunication relationship
var oHSSecondaryCommunicationSource = oDiscovery.CreateClassInstance("$MPElement[Name='SCLibrary!Microsoft.SystemCenter.HealthService']$");
oHSSecondaryCommunicationSource.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", ComputerIdentity);

// Target of HealthServiceSecondaryCommunication relationship
var oHSSecondaryCommunicationTarget;

for (key in SecondarySCPInfoRegKeys)
{
if (SecondarySCPInfoRegKeys[key] != null)
{
oHSSecondaryCommunicationTarget = oDiscovery.CreateClassInstance("$MPElement[Name='SCLibrary!Microsoft.SystemCenter.HealthService']$");
oHSSecondaryCommunicationTarget.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", SecondarySCPInfoRegKeys[key].toString());

var oHealthServiceSecondaryCommunication = oDiscovery.CreateRelationshipInstance("$MPElement[Name='SCLibrary!Microsoft.SystemCenter.HealthServiceSecondaryCommunication']$");
oHealthServiceSecondaryCommunication.Source = oHSSecondaryCommunicationSource;
oHealthServiceSecondaryCommunication.Target = oHSSecondaryCommunicationTarget;

oDiscovery.AddInstance(oHealthServiceSecondaryCommunication);
}
}
}

oAPI.Return(oDiscovery);
}

function PrintError(error)
{
WScript.Echo("============================= BEGIN ERROR =================================\n");
WScript.Echo("Error Type : " + error);
WScript.Echo("Error Number : " + error.number);
WScript.Echo("Error Code : " + (error.number &amp; 0xFFFF));
WScript.Echo("Win32 Facility : " + (error.number&gt;&gt;16 &amp; 0x1FFF));
WScript.Echo("Error Source : " + error.Source);
WScript.Echo("Error Description : " + error.description);
WScript.Echo("============================== END ERROR ==================================\n");
}

function SafeRegRead(registryPath)
{
try
{
return oReg = oShell.RegRead(registryPath);
}
catch (e)
{
switch (e.number &amp; 0xFFFF)
{
// HRESULT 0x80070002: ERROR_FILE_NOT_FOUND - Severity: FAILURE (1), FACILITY_WIN32 (0x7), Code 0x2
case 2 :
CheckADRegKeyType(registryPath);
break;
default :
PrintError(e);
}
}
}

function CheckADRegKeyType(registryPath)
{
WScript.Echo("\nRegistry Path: " + registryPath);

var regExCriteria = /(Primary|Secondary) SCP Info\s{0,1}\d*/gi;
WScript.Echo("Registry Criteria: " + regExCriteria);

var matchResults = registryPath.match(regExCriteria);
WScript.Echo("RegEx Results: " + matchResults);

if (matchResults != null)
{
switch (matchResults[0])
{
case "Primary SCP Info" :
var ENU_MESSAGE = ENU_MESSAGE_BASE;
ENU_MESSAGE += "Could not find " + "\"" + registryPath + "\"\n";
ENU_MESSAGE += "The HealthService needs at least a primary management server to communicate.\n";
ENU_MESSAGE += "This may indicate that the following:\n";
ENU_MESSAGE += "\t* HealthService has not queried and cached the AD SCPs yet\n";
ENU_MESSAGE += "\t* HealthService doesn't have access to any SCPs, yet is configured for AD Integration\n";
ENU_MESSAGE += "Match results: " + matchResults[1];
oAPI.LogScriptEvent(SCRIPT_NAME, 6028, EVENTLOG_WARNING_TYPE, ENU_MESSAGE);
WScript.Quit(1);
break;
case "Secondary SCP Info " :
WScript.Echo("\nCould not find \"" + matchResults[1] + "\\Service DNS Name\" under \"" + SecondarySCPInfoRootRegKey + "\"");
WScript.Echo("\nThis is not a fatal error as the HealthService may not have any failovers.");
WScript.Echo("\nMatch results: " + matchResults[1]);
break;
default :
throw("Unknown RegKey Type");
}
}
}
</Script></ScriptBody>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DataSource"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>