Microsoft_Exchange_2010_Get_Site_Name (DataSourceModuleType)

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityPublic
RunAsDefault
OutputTypeSystem.PropertyBagData

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource Microsoft.Windows.TimedScript.PropertyBagProvider Default

Overrideable Parameters:

IDParameterTypeSelector
IntervalSecondsint$Config/IntervalSeconds$
SyncTimestring$Config/SyncTime$
TimeoutSecondsint$Config/TimeoutSeconds$
targetServerstring$Config/targetServer$

Source Code:

<DataSourceModuleType ID="Microsoft_Exchange_2010_Get_Site_Name" Accessibility="Public">
<Configuration>
<xsd:element name="IntervalSeconds" type="xsd:int"/>
<xsd:element name="SyncTime" type="xsd:string"/>
<xsd:element name="TimeoutSeconds" type="xsd:int"/>
<xsd:element name="targetServer" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" ParameterType="int" Selector="$Config/IntervalSeconds$"/>
<OverrideableParameter ID="SyncTime" ParameterType="string" Selector="$Config/SyncTime$"/>
<OverrideableParameter ID="TimeoutSeconds" ParameterType="int" Selector="$Config/TimeoutSeconds$"/>
<OverrideableParameter ID="targetServer" ParameterType="string" Selector="$Config/targetServer$"/>
</OverrideableParameters>
<ModuleImplementation>
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedScript.PropertyBagProvider">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<SyncTime>$Config/SyncTime$</SyncTime>
<ScriptName>GetSite.js</ScriptName>
<Arguments>"$Config/targetServer$"</Arguments>
<ScriptBody><Script>

//*************************************************************
// $ScriptName: "Microsoft Exchange 2010 - Get Site Name" $
//
// Generate an Operations Manager event with the site name of the local server.
//
// Events created by this script:
// SOURCE ID TYPE DESCRIPTION
// MSExchange Monitoring Server Info 30001 inform [Active Directory Site Name]
// MSExchange Monitoring Server Info 30002 warning Unexpected error happened...
//
//*************************************************************

var EVENT_SOURCE = "MSExchange Monitoring Server Info";
var SITE_INFO_ID = 30001;
var UNEXPECTED_ERROR_ID = 30002;
var UNEXPECTED_ERROR_MSG = "An unexpected error occurred when accessing the ADSystemInfo object. " + "\n" + "Error number: %0" + "\n" + "Error description: %1";


// Typed property bag constants
var ALERT_DATA_TYPE = 0;
var EVENT_DATA_TYPE = 1;
var PERF_DATA_TYPE = 2;
var STATE_DATA_TYPE = 3;

// Global variable pointing to the OpsMgr07 ScriptAPI
//
var oAPI = new ActiveXObject("MOM.ScriptAPI");




// Event Constants
var EVENT_TYPE_SUCCESS = 0;
var EVENT_TYPE_ERROR = 1;
var EVENT_TYPE_WARNING = 2;
var EVENT_TYPE_INFORMATION = 4;


// Global variable used to identify the target computer - it must be set with the FQDN of the target computer,
// this information must be the first parameter of the script
//
var _globalTargetComputer = WScript.Arguments(0);


function LoggingComputer()
{
return _globalTargetComputer;
}
























// Global variable used by the CreateEventEx to report the exact diagnostic cmdlet used by the rule, if one was specified
//
var _globalCmdletCommandScriptParam = null;

// Truncates a message, if necessary, appending the appropriate suffix
//
function TruncatedMsg(msg, maxMsgLength, truncatedMsgSuffix, defaultMsgSuffix)
{
if ((msg.length + defaultMsgSuffix.length) &gt; maxMsgLength)
{
msg = msg.substring(0, maxMsgLength - (truncatedMsgSuffix.length)) + truncatedMsgSuffix;
}
else
{
msg = msg + defaultMsgSuffix;
}

return msg;
}

function CreateEvent(strSource, lngEventID, lngEventType, strMsg, strComputer)
{
CreateEventEx(strSource, lngEventID, lngEventType, strMsg, "", strComputer, true);
}

function CreateEvent(strSource, lngEventID, lngEventType, strMsg, strInstanceName, strComputer)
{
CreateEventEx(strSource, lngEventID, lngEventType, strMsg, strInstanceName, strComputer, true);
}

function CreateReportEvent(strSource, lngEventID, lngEventType, strMsg, strComputer)
{
CreateEventEx(strSource, lngEventID, lngEventType, strMsg, "", strComputer, false);
}

function CreateEventEx(strSource, lngEventID, lngEventType, strMsg, strInstanceName, strComputer, blnIncRuleName)
{
var objNewEvent = oAPI.CreateTypedPropertyBag(EVENT_DATA_TYPE);

// For OpsMgr 2007 R2, the limit can be higher; but for SP1 it is around 128K for some monitors.
// We could have lifted the limit altogether but this runs the risk that a task may be logging too
// much data and causing the monitor to fail. For this reason, having a higher limit as opposed
// to none is safer -- as we would rather have the message get truncated then to risk the monitor failing.
// This higher limit should be adequate for including verbose and call stacks in the event message.
var MAX_MOM_MSG_LEN = 128000;

var truncatedMsgSuffix = "...";
var defaultMsgSuffix = "";


if (blnIncRuleName)
{
if (_globalCmdletCommandScriptParam != null)
defaultMsgSuffix += "\n\nDiagnostic command: \"" + _globalCmdletCommandScriptParam + "\"";
truncatedMsgSuffix += defaultMsgSuffix;
}
objNewEvent.AddValue("Message", TruncatedMsg(strMsg, MAX_MOM_MSG_LEN, truncatedMsgSuffix, defaultMsgSuffix));
objNewEvent.AddValue("EventNumber", lngEventID);
objNewEvent.AddValue("EventType", lngEventType);
objNewEvent.AddValue("EventSource", strSource);

if (strInstanceName == null)
{
strInstanceName = "";
}
objNewEvent.AddValue("EventInstanceName", strInstanceName);

if (strComputer == "" || strComputer == null)
{
strComputer = LoggingComputer();
}
objNewEvent.AddValue("LoggingComputer", strComputer);

oAPI.AddItem(objNewEvent);
}


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


///////////////////////////////////////////////
//EventText -Replace escaped character %# with
//elements in the input array "param"
//
//This function assumes a zero base array
// e.g. EventText("%0 is the server. %1 is the client", new Array("Exchange", "Outlook"))
// would return "Exchange is a server. Outlook is a client"
//
// but EventText("%1 is the server. %2 is the client", new Array("Exchange", "Outlook"))
// would return "Outlook is a server. %2 is a client"
function EventText(eventText, param)
{
var index;
for (index in param)
{
eventText = eventText.replace("%"+index, param[index]);
}
return eventText;
}



MainRoutine:
{
var adSystemInfo;

// TODO: How to check for agentless target in OpsMgr07? Do not generate the event for agentless managed computers

// create the event for site info
try
{
adSystemInfo = new ActiveXObject("ADSystemInfo");
CreateReportEvent(
EVENT_SOURCE,
SITE_INFO_ID,
EVENT_TYPE_INFORMATION,
adSystemInfo.SiteName, // the message body is the site name
""); // use default computer name
}
catch(err)
{
CreateEvent(
EVENT_SOURCE,
UNEXPECTED_ERROR_ID,
EVENT_TYPE_WARNING,
EventText(UNEXPECTED_ERROR_MSG, new Array( HResultToString(err.number), err.description)),
"");
}

}//MainRoutine

oAPI.ReturnItems();


</Script></ScriptBody>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DS"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
</DataSourceModuleType>