The number of files in the inbox that if exceeded will result in an event being raised
InboxDirectoryName
string
$Config/Parameters/InboxDirectoryName$
InboxDirectoryName
A directory under SMS\inboxes
Source Code:
<WriteActionModuleType ID="SMS_2003_Monitor_SMS_Inbox" Accessibility="Internal" Comment="{03E6FD65-83F1-40F6-A6D7-2E7DE2F13846}">
<Configuration>
<IncludeSchemaTypes>
<SchemaType>MomBackwardCompatibility!System.Mom.BackwardCompatibility.AlertGenerationSchema</SchemaType>
</IncludeSchemaTypes>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="AlertGeneration" type="AlertGenerationType"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="InvokerType" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Parameters" minOccurs="0">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="FileCountThreshold" type="xsd:string" minOccurs="0"/>
<xsd:element name="InboxDirectoryName" type="xsd:string" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="FileCountThreshold" Selector="$Config/Parameters/FileCountThreshold$" ParameterType="string"/>
<OverrideableParameter ID="InboxDirectoryName" Selector="$Config/Parameters/InboxDirectoryName$" ParameterType="string"/>
</OverrideableParameters>
<ModuleImplementation>
<Composite>
<MemberModules>
<WriteAction ID="RunScriptAction" TypeID="MomBackwardCompatibility!System.Mom.BackwardCompatibility.ScriptResponse">
<AlertGeneration>$Config/AlertGeneration$</AlertGeneration>
<InvokerType>$Config/InvokerType$</InvokerType>
<Body><Script>
'*******************************************************************************
' Script Name - SMS 2003 Monitor SMS Inbox
'
' Purpose - Monitors an SMS Inbox and raises an event when the number of
' files in it exceeds a threshold.
'
' 1720 - An event used to report that an inbox threshold has been
' exceeded.
'
' The following additional events can be raised:
'
' 1100 - An event used only for debugging or tracing.
' 1101 - Script executed successfully.
' 1102 - An error occurred in executing this script.
' 1105 - Accessed denied due to connection failure or permissions.
'
' Assumptions - This script will only run on SMS 2003 Site Servers.
'
' This script does not support agentless mode and will silently
' terminate.
'
' The inbox threshold specified must be greater than 0.
'
' Parameters - InboxDirectoryName A directory under SMS\inboxes.
' FileCountThreshold The number of files in the inbox that if
' exceeded will result in an event being
' raised.
'
' Change Hist - Date Version Description
' -------- --------------- -----------
' 07/14/04 05.0.2706.0000 Created
' 07/22/04 05.0.2706.0000 Removed error event for non-existent
' inbox.
' 09/07/04 05.0.2751.0000 Updated FileCountThreshold input
' parameter checking.
'
' (c) Copyright 2004, Microsoft Corp., All Rights Reserved
'*******************************************************************************
'******************************************************************************
' Name: Main
'
' Purpose: Entry point for program execution.
'
' Parameters: None
'
' Returns: Nothing
'
Sub Main()
Dim strInboxDirectoryName
Dim intFileCountThreshold
On Error Resume Next
LogMessage DBG_TRACE, ScriptContext.Name & " script starting at local time: " & CStr(Time)
'This script does not support agentless monitoring.
'==================================================
If ScriptContext.IsTargetAgentless Then
LogMessage DBG_TRACE, "No action taken; agentless monitoring is not supported."
Exit Sub
End If
'Get the input parameters; the inbox directory name and file count
'threshold.
'=================================================================
If ((0 <> Err.number) or _
IsEmpty(strInboxDirectoryName) or _
IsNull(strInboxDirectoryName) or _
(strInboxDirectoryName = "")) Then
LogMessage DBG_ERROR, "Failed to get script parameter " & SCRIPT_PARAM_INBOX_DIRECTORY_NAME & " or invalid value."
ScriptError "get script parameter " & SCRIPT_PARAM_INBOX_DIRECTORY_NAME & " or invalid value."
Exit Sub
End If
If ((0 <> Err.number) or _
IsEmpty(intFileCountThreshold) or _
(intFileCountThreshold <= 0)) Then
LogMessage DBG_ERROR, "Failed to get script parameter " & SCRIPT_PARAM_INBOX_FILE_COUNT_THRESHOLD & " or invalid value."
ScriptError "get script parameter " & SCRIPT_PARAM_INBOX_FILE_COUNT_THRESHOLD & " or invalid value."
Exit Sub
End If
LogMessage DBG_TRACE, ScriptContext.Name & " script completed at local time: " & CStr(Time)
End Sub
'******************************************************************************
' Name: CheckInbox
'
' Purpose: Checks if the number of files in the specified inbox has exceeded
' the specified threshold. If so, an event is raised.
'
' Parameters: strInboxDirectoryName, the inbox to check.
' intFileCountThreshold, the threshold to event on.
'
' Returns: Nothing
'
Sub CheckInbox(strInboxDirectoryName, intFileCountThreshold)
Dim strError
Dim intFileCount
On Error Resume Next
'Get the current file count for the specified inbox.
'===================================================
'If the current file count exceeds the specified threshold for the
'inbox, create an event.
'=================================================================
If intFileCount = 0 Then
LogMessage DBG_TRACE, "Inbox " & strInboxDirectoryName & " is empty."
ElseIf intFileCount <= intFileCountThreshold Then
LogMessage DBG_TRACE, "Inbox " & strInboxDirectoryName & " has not exceeded its file count threshold of " & intFileCountThreshold & "."
Else
LogMessage DBG_WARNING, "Inbox " & strInboxDirectoryName & " contains " & intFileCount & " files which exceeds its threshold of " & intFileCountThreshold & " files."
CreateSMSInboxThresholdExceededEvent strInboxDirectoryName, intFileCountThreshold, intFileCount
End If
End Sub
'******************************************************************************
' Name: GetInboxFileCount
'
' Purpose: Gets the current file count from the specified inbox under the
' SMS\inboxes directory.
'
' Parameters: strInboxDirectoryName, the inbox to check.
'
' Returns: the numbers of files in the inbox if successful otherwise 0.
'
Function GetInboxFileCount(strInboxDirectoryName)
Dim objFSO
Dim objInboxFolder
Dim objFiles
Dim strInboxPath
On Error Resume Next
'Construct the full path for the specified inbox.
'================================================
strInboxPath = GetSMSInstallationPath()
If IsEmpty(strInboxPath) Then
GetInboxFileCount = 0
Exit Function
End If
strInboxPath = strInboxPath & "\inboxes\" & strInboxDirectoryName
'Check if the inbox exists.
'==========================
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not objFSO.FolderExists(strInboxPath) Then
LogMessage DBG_ERROR, "Failed to verify existence of inbox: " & strInboxPath & "."
GetInboxFileCount = 0
Set objFSO = Nothing
Err.Clear
Exit Function
End If
'Get the number of files in the inbox.
'=====================================
Set objInboxFolder = objFSO.GetFolder(strInboxPath)
Set objFiles = objInboxFolder.Files
GetInboxFileCount = objFiles.Count
'Cleanup
'=======
Set objFiles = Nothing
Set objInboxFolder = Nothing
Set objFSO = Nothing
End Function
'******************************************************************************
' Name: GetSMSInstallationPath
'
' Purpose: Get the SMS Installation Directory from the registry under the
' SMS Identification key.
'
' Parameters: None
'
' Returns: String, SMS Installation path if successful otherwise empty.
'
Function GetSMSInstallationPath()
Dim strError
Dim objShell
On Error Resume Next
'Create the WSH Shell object for accessing the registry.
'=======================================================
Set objShell = CreateObject("WScript.Shell")
'Read the Installation Directory value from under the SMS
'Identification key.
'========================================================
GetSMSInstallationPath = objShell.RegRead(REG_KEY_IDENTIFICATION & REG_VAL_INSTALLATION_DIRECTORY)
If IsEmpty(GetSMSInstallationPath) Then
strError = GetErrorString(Err)
LogMessage DBG_ERROR, "Failed to read registry value." & strError
ScriptError "read registry value." & strError
Err.Clear
End If
Set objShell = Nothing
End Function
'******************************************************************************
' Name: GetSMSSiteCode
'
' Purpose: Get the SMS Site Code from the registry under the SMS
' Identification key.
'
' Parameters: None
'
' Returns: String, returns the SMS Site Code if successful otherwise empty.
'
Function GetSMSSiteCode()
Dim strError
Dim objShell
On Error Resume Next
'Create the WSH Shell object for accessing the registry.
'=======================================================
Set objShell = CreateObject("WScript.Shell")
'Read the Site Code value from under the SMS Identification key.
'===============================================================
GetSMSSiteCode = objShell.RegRead(REG_KEY_IDENTIFICATION & REG_VAL_SITE_CODE)
If IsEmpty(GetSMSSiteCode) Then
strError = GetErrorString(Err)
LogMessage DBG_ERROR, "Failed to read registry value." & strError
ScriptError "read registry value." & strError
Err.Clear
End If
Set objShell = Nothing
End Function
'******************************************************************************
' Name: CreateSMSInboxThresholdExceededEvent
'
' Purpose: To generate a MOM event containing the inbox name, file count
' threshold and the current file count exceeding that threshold.
'
' Parameters: strInboxDirectoryName, the inbox that was checked.
' intFileCountThreshold, the threshold for the inbox.
' intFileCount, the number of files currently in the inbox.
'
' Returns: Nothing
'
Sub CreateSMSInboxThresholdExceededEvent(strInboxDirectoryName, intFileCountThreshold, intFileCount)
strMessage = "SMS site '" & strSiteCode & "' has inbox " & strInboxDirectoryName & " with " & intFileCount & " files which exceeds its threshold of " & intFileCountThreshold & " files."
oEvent.Message = strMessage
'Submit, raise, this event to MOM.
'=================================
LogMessage DBG_TRACE, "Submitting event " & EVENT_ID_SMS_INBOX_THRESHOLD_EXCEEDED & "."
ScriptContext.Submit oEvent
'Cleanup
'=======
Set oEvent = Nothing
End Sub
'******************************************************************************
' Name: GetErrorString
'
' Purpose: Attempts to find the description for an error if an error with
' no description is passed in.
'
' Parameters: oErr The error object
'
' Return: String, the description for the error. (Includes the error code.)
'
Function GetErrorString(oErr)
Dim lErr, strErr
lErr = oErr
strErr = oErr.Description
On Error Resume Next
If 0 >= Len(strErr) Then
' If we don't have an error description, then check to see if the error
' is a 0x8007xxxx error. If it is, then look it up.
Const ErrorMask = &HFFFF0000
Const HiWord8007 = &H80070000
Const LoWordMask = 65535 ' This is equivalent to 0x0000FFFF
If (lErr And ErrorMask) = HiWord8007 Then
' Attempt to use 'net helpmsg' to get a description for the error.
Dim oShell
Set oShell = CreateObject("WScript.Shell")
If Err = 0 Then
Dim oExec
Set oExec = oShell.Exec("net helpmsg " & (lErr And LoWordMask))
Dim strMessage, i
Do
strMessage = oExec.stdout.ReadLine()
i = i + 1
Loop While (Len(strMessage) = 0) And (i < 5)
strErr = strMessage
End If
End If
End If
GetErrorString = vbCrLf & "The error returned was: '" & strErr & "' " & lErr & " (0x" & Hex(lErr) & ")"
End Function
'******************************************************************************
' Name: ScriptError
'
' Purpose: To generate a warning about a runtime script error.
'
' Parameters: strError The description of the error
'
' Returns: Nothing
'
Sub ScriptError(strError)
LogEvent EVENT_ID_SCRIPTERROR, EVENT_TYPE_WARNING, "encountered a runtime error." & vbCrLf & "Failed to " & strError
End Sub
'******************************************************************************
' Name: LogEvent
'
' Purpose: To generate a MOM event
'
' Parameters: lEventID The event code
' lEventType The severity of the event
' strMessage The message to include in the event
'
' Returns: Nothing
'
Sub LogEvent(lEventID, lEventType, strMessage)
Dim oEvent
On Error Resume Next
Set oEvent = ScriptContext.CreateEvent
oEvent.EventNumber = lEventID
oEvent.EventType = lEventType
oEvent.Message = "The script '" & ScriptContext.Name & "' running under processing rule '" & ScriptContext.ProcessingRule.Name & "' " & strMessage
ScriptContext.Submit oEvent
End Sub
'******************************************************************************
' Name: LogMessage
'
' Purpose: To log a message to ScriptContext and MOM's agent response log.
'
' Parameters: lLevel The debug level for this message i.e. trace,
' warning or error
' strMessage The message to write
'
' Returns: Nothing
'
Sub LogMessage(lLevel, strMessage)
If (lLevel < DBG_NONE) Then
If (lLevel = DBG_ERROR) Then
ScriptContext.Echo "[Error]: " + strMessage
ElseIf (lLevel = DBG_WARNING) Then
ScriptContext.Echo "[Warning]: " + strMessage
ElseIf (lLevel = DBG_TRACE) Then
ScriptContext.Echo "[Trace]:" + strMessage
End If