var SourceType = oArgs(0);
var SourceId = oArgs(1);
var ManagedEntityId = oArgs(2);
var ComputerIdentity = oArgs(3);
var ManagementGroupName = oArgs(4);
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 & 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);
}
}
if ((EnableADIntegration == false) || (UseActiveDirectory == false))
{
var oDiscovery = oAPI.CreateDiscoveryData(SourceType, SourceId, ManagedEntityId);
oDiscovery.IsSnapshot = false;
oAPI.Return(oDiscovery);
}
if ((EnableADIntegration == true) && (UseActiveDirectory == true))
{
var PrimarySCPInfo = SafeRegRead(PrimarySCPInfoRegValue);
WScript.Echo("\nPrimary SCP Info value: " + PrimarySCPInfo);
}
if ((EnableADIntegration == true) && (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 < 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";
// 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;
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>