//*************************************************************
// $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) > maxMsgLength)
{
msg = msg.substring(0, maxMsgLength - (truncatedMsgSuffix.length)) + truncatedMsgSuffix;
}
else
{
msg = msg + defaultMsgSuffix;
}
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 = "";
///////////////////////////////////////////////
//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)),
"");
}