Exchange 2003 Outlook Mobile Access Discovery

Microsoft.Exchange.Protocol.OMA.Discovery (Discovery)

This rule discovers the Exchange 2003 Outlook Mobile Access component on an Exchange 2003 Frontend server

Knowledge Base article:

Summary

This discovery rule discovers the Exchange 2003 Outlook Mobile Access Functionality (OMA) on an Exchange Frontend Server.

Configuration

There is no configuration required. To disable local Exchange 2003 Server role discovery disable (override) the rule “Exchange 2003 Server Initial Discovery”.

OMA Logon monitor via synthetic transactions requires configuration performed by the “Exchange Management Pack Configuration Wizard”.

Element properties:

TargetMicrosoft.Exchange.ServerRole.2003
EnabledTrue
Frequency3600
RemotableFalse

Object Discovery Details:

Discovered Classes and their attribuets:

Member Modules:

ID Module Type TypeId RunAs 
DiscoveryDataSource DataSource System.CommandExecuterDiscoveryDataSource Default

Source Code:

<Discovery ID="Microsoft.Exchange.Protocol.OMA.Discovery" Enabled="onStandardMonitoring" Target="Microsoft.Exchange.ServerRole.2003" ConfirmDelivery="false" Remotable="true" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="Microsoft.Exchange.Protocol.OMA"/>
</DiscoveryTypes>
<DataSource ID="DiscoveryDataSource" TypeID="System!System.CommandExecuterDiscoveryDataSource">
<IntervalSeconds>3600</IntervalSeconds>
<ApplicationName>%windir%\System32\cscript.exe</ApplicationName>
<WorkingDirectory/>
<CommandLine>$file/DiscoverMicrosoftExchangeProtocolOMA.js$ 0 $MPElement$ $Target/Id$ $Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$ $Target/Property[Type="Microsoft.Exchange.ServerRole.2003"]/DistinguishedName$ $Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/NetbiosComputerName$</CommandLine>
<TimeoutSeconds>300</TimeoutSeconds>
<RequireOutput>true</RequireOutput>
<Files>
<File>
<Name>DiscoverMicrosoftExchangeProtocolOMA.js</Name>
<Contents><Script>
//Copyright (c) Microsoft Corporation. All rights reserved.

//*************************************************************
// $ScriptName: "Exchange - Database Discovery" $
//
// TBD: This assumes that there are no Public Folders and/or Mailboxes on a frontend server.
// However this is not a must requirement, just a recommendation.
// For now we assume that a Frontend server does not have databases
//
// $File: DiscoverMicrosoftExchangeProtocolOMA.js $
//
//*************************************************************

// Define Constants

var REGKEY_NOT_EXIST = -2147024894;

var REG_ERROR = 2901;
var REG_ERROR_MSG = "There is problem accessing the registry to retrieve the name of the back-end mailbox. ";

var USER_NOT_EXIST = 2005;
var USER_NOT_EXIST_MSG = "The back-end mailbox account specified does not exist. ";

var MAILBOX_NOT_EXIST = 2006;
var MAILBOX_NOT_EXIST_MSG = "The back-end mailbox account specified does not have an Exchange mailbox. ";

var GENERAL_BE_MAILBOX_ERROR_MSG = "Encountered problem when extracting and verifying the back-end mailbox info.\n\nError: ";

var EVENT_SOURCE = "Exchange MOM";
// Event Constants
var EVENT_TYPE_SUCCESS = 0;
var EVENT_TYPE_ERROR = 1;
var EVENT_TYPE_WARNING = 2;
var EVENT_TYPE_INFORMATION = 4;

var RUNCONFIGAPP = 7988;
var RUNCONFIGAPP_MSG = "Please run the Exchange Management Pack Configuration Utility to properly configure this front-end for monitoring";

// Fetch the parameters
// If the number of arguments is less than 6, quit

//var FQDN, NetbiosComputername, ShortNetbiosDomainname
var SourceType, SourceID, ManagedEntityId, TargetComputer,DistinguishedName,NetBiosComputerName;

if(WScript.Arguments.Unnamed.Count == 6){
SourceType = WScript.Arguments(0);
SourceID = WScript.Arguments(1) ;
ManagedEntityId = WScript.Arguments(2);
TargetComputer = WScript.Arguments(3);
DistinguishedName = WScript.Arguments(4);
NetBiosComputerName=WScript.Arguments(5);
}else{
WScript.quit();
}

var oAPI;
oAPI = new ActiveXObject("Mom.ScriptAPI");

function CreateEvent(strSource, lngEventID, lngEventType, strMsg)
{
oAPI.LogScriptEvent(strSource, lngEventID, lngEventType, strMsg);
}

function GetRootGC()
{
var oGCColl = GetObject("GC:");
var enumGCs = new Enumerator(oGCColl);
if (!enumGCs.atEnd())
return enumGCs.item();

return null;
}

function GetBEMailbox(strComputerName)
{
var mailboxaccount = null;
var objShell = new ActiveXObject("WScript.Shell");
try
{
mailboxaccount = objShell.RegRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Exchange MOM\\FEMonitoring\\" + strComputerName + "\\BEAccount");
if ( null == mailboxaccount || mailboxaccount.length == 0)
return null;
}
catch (err)
{
if (err.number == REGKEY_NOT_EXIST)
return null;
throw REG_ERROR;
}

var IADsPathname = new ActiveXObject("Pathname");
var oConnect = new ActiveXObject("ADODB.Connection");
oConnect.Provider = "ADsDSOObject";
oConnect.Open();
var command = new ActiveXObject("ADODB.Command");
command.ActiveConnection = oConnect;
var objRootGC = GetRootGC();
command.CommandText = "SELECT homeMDB, AdsPath, sAMAccountName FROM '" + objRootGC.ADsPath + "' WHERE sAMAccountName='" + mailboxaccount + "' AND objectclass='user' AND objectCategory='person' ORDER BY sAMAccountName";
command.Properties("Page Size") = 100;
command.Properties("Timeout") = 10; //seconds
command.Properties("searchscope") = 2; //ADS_SCOPE_SUBTREE
command.Properties("Chase referrals") = 0x20 | 0x40; //ADS_CHASE_REFERRALS_ALWAYS
command.Properties("Cache Results") = false; //do not cache the result set
var rs = command.Execute();

var bAccountExist = false;
var bMailboxExist = false;
var backendServerName;
var homeMDBPath = null;

if (!rs.EOF)
{
rs.MoveFirst();
while (!rs.EOF)
{
for(i = 0; i&lt;rs.Fields.Count; i++){
if (rs.Fields(i).Name == "sAMAccountName")
if (rs.Fields(i).Value.toLowerCase() == mailboxaccount.toLowerCase())
bAccountExist = true;

if (rs.Fields(i).Name == "homeMDB")
{
homeMDBPath = rs.Fields(i).Value;
if (homeMDBPath != null &amp;&amp; homeMDBPath != "")
{
bMailboxExist = true;
IADsPathname.Set(rs.Fields(i).Value, 4); // ADS_SETTYPE_DN
IADsPathname.EscapedMode = 4; // ADS_ESCAPEDMODE_OFF_EX
backendServerName = IADsPathname.GetElement(3).substring(3);
}
}
}
rs.MoveNext();
}
}

if (!bAccountExist)
throw USER_NOT_EXIST;
if (!bMailboxExist)
throw MAILBOX_NOT_EXIST;

if (backendServerName.toLowerCase() != mailboxaccount.toLowerCase())
{
return backendServerName;
}

return mailboxaccount;

}

function IsFrontEnd(strServerName)
{
var oConnect = new ActiveXObject("ADODB.Connection");
oConnect.Provider = "ADsDSOObject";
oConnect.Open();
var command = new ActiveXObject("ADODB.Command");
command.ActiveConnection = oConnect;
var objRootDSE = GetObject("LDAP://rootDSE");

command.CommandText = "SELECT CN FROM 'LDAP://" + objRootDSE.Get("configurationNamingContext") + "' WHERE CN='" + strServerName + "' AND serverRole=1";
command.Properties("Page Size") = 100;
command.Properties("Timeout") = 10;
command.Properties("searchscope") = 2;
command.Properties("Chase referrals") = 0x20 | 0x40;
command.Properties("Cache Results") = false;
var rs = command.Execute();

var boolIsFrontEnd = false;
if (!rs.EOF){
rs.MoveFirst();
if (rs.Fields(0).Value.toUpperCase() == strServerName.toUpperCase())
boolIsFrontEnd = true;
}
return boolIsFrontEnd;
}

function HResultToString(hresult)
{
return "0x" + (hresult &lt; 0 ? hresult + 0x100000000 : hresult).toString(16).toUpperCase() + "(" + hresult +")";
}

MainRoutine:
{
var discoveryData;
discoveryData = oAPI.CreateDiscoveryData(SourceType, SourceID, ManagedEntityId);
try
{
strMailbox = GetBEMailbox(NetBiosComputerName);
bLogonEnabled = (null != strMailbox);
if(bLogonEnabled==true){
var oExchangeOMAInstance;
// Create Server (Exchange &amp; Exchange Frontend) collection with the
// Computer (full netbios name: domain\servername) as scope
oExchangeOMAInstance = discoveryData.CreateClassInstance("$MPElement[Name='Microsoft.Exchange.Protocol.OMA']$");
oExchangeOMAInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", TargetComputer);
oExchangeOMAInstance.AddProperty("$MPElement[Name='Microsoft.Exchange.ServerRole.2003']/DistinguishedName$", DistinguishedName);
oExchangeOMAInstance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "OMA");
// Add it to the discovery data
discoveryData.AddInstance(oExchangeOMAInstance);
}
}
catch(err)
{
var strErr = "";

if (err == REG_ERROR)
strErr = REG_ERROR_MSG;
else if (err == USER_NOT_EXIST)
strErr = USER_NOT_EXIST_MSG;
else if (err == MAILBOX_NOT_EXIST)
strErr = MAILBOX_NOT_EXIST_MSG;
else
strErr = GENERAL_BE_MAILBOX_ERROR_MSG + HResultToString(err.number) + " " + err.description;

CreateEvent(EVENT_SOURCE, RUNCONFIGAPP, EVENT_TYPE_ERROR, strErr + "\n\n" + RUNCONFIGAPP_MSG);
}

// Pass back the result to MOM
oAPI.Return(discoveryData);

}//MainRoutine
</Script></Contents>
</File>
</Files>
</DataSource>
</Discovery>