SMS 2003 Site Backup Event Suppression

SMS_2003_Site_Backup_Event_Suppression (WriteActionModuleType)

Monitors the SMS Site Backup service and accordingly raises the current event or not

Element properties:

TypeWriteActionModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
InputTypeSystem.BaseData
Comment{D096B7B7-30C9-4B0B-A414-8C170280D145}

Member Modules:

ID Module Type TypeId RunAs 
RunScriptAction WriteAction System.Mom.BackwardCompatibility.ScriptResponse Default

Source Code:

<WriteActionModuleType ID="SMS_2003_Site_Backup_Event_Suppression" Accessibility="Internal" Comment="{D096B7B7-30C9-4B0B-A414-8C170280D145}">
<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"/>
</Configuration>
<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 Site Backup Event Suppression
'
' Purpose - Checks if the SMS Site Backup service is running. If it is not,
' a duplicate event will be created with only its source being
' altered to this script's name.
'
' 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 - WMI service must be running in order to determine if the SMS
' Site Backup service is running.
'
' Parameters - None
'
' Change Hist - Date Version Description
' -------- --------------- -----------
' 04/07/04 02.50.0174.0000 Created
'
' (c) Copyright 2004, Microsoft Corp., All Rights Reserved
'*******************************************************************************

Option Explicit


'Event Severity Constants
'========================

Const EVENT_TYPE_SUCCESS = 0
Const EVENT_TYPE_ERROR = 1
Const EVENT_TYPE_WARNING = 2
Const EVENT_TYPE_INFORMATION = 4

Const EVENTLOG_AUDIT_SUCCESS = 8
Const EVENTLOG_AUDIT_FAILURE = 16


'Event Number Constants
'======================

Const EVENT_ID_NOTANEVENT = 1100
Const EVENT_ID_SCRIPTSUCCESS = 1101
Const EVENT_ID_SCRIPTERROR = 1102
Const EVENT_ID_ACCESSDENIED = 1105


'VBScript Runtime Error Number Constants
'=======================================

Const VB_ERROR_CAN_NOT_PERFORM_OPERATION = 17 'Can't perform requested operation



Sub Main()

On Error Resume Next


'Service the current processing rule. If the event processing rule
'for which this script is executing as a response finds that the SMS
'Site Backup service is running simply return otherwise raise a
'duplicate event with this script's name as its source.
'===================================================================

ServiceCurrentEventProcessingRule

If 0 &lt;&gt; Err.number Then
ScriptError "service current event processing rule." &amp; GetErrorString(Err)
End If

End Sub


'******************************************************************************
' Name: ServiceCurrentEventProcessingRule
'
' Purpose: Service the current processing rule. If the event processing
' rule for which this script is executing as a response finds that
' the SMS Site Backup service is running simply return otherwise
' raise a duplicate event with this script's name as its source.
'
' Parameters: None
'
' Returns: Nothing
'
Sub ServiceCurrentEventProcessingRule()

Dim intServiceStarted


On Error Resume Next


'If the SMS Site Backup service is running, do not create a
'corresponding event processing object. Simply return thereby
'effectively consuming the object.
'=============================================================

intServiceStarted = IsSMSSiteBackupServiceStarted()

If intServiceStarted = True Then
Exit Sub
End If

'This processing rule has not been placed in maintenance mode. Create
'the appropriate processing object.
'=====================================================================

If ScriptContext.IsEvent() Then
CreateEvent
Else
Err.Raise VB_ERROR_CAN_NOT_PERFORM_OPERATION
Exit Sub
End If

End Sub


'******************************************************************************
' Name: CreateEvent
'
' Purpose: To generate a MOM event for the current event processing rule.
'
' Parameters: None
'
' Returns: Nothing
'
Sub CreateEvent()

Dim objEvent


On Error Resume Next


'Create MOM event object.
'========================

Set objEvent = ScriptContext.CreateEvent

'Initialize the properties of the new event object and submit it.
'================================================================

InitializeEvent(objEvent)

If 0 = Err.number Then
ScriptContext.Submit objEvent
End If

Set objEvent = Nothing

End Sub


'******************************************************************************
' Name: InitializeEvent
'
' Purpose: Initialize the specified event to the event in the current script
' context.
'
' Parameters: objEvent, newly created event to be initialized.
'
' Returns: Nothing
'
Sub InitializeEvent(objEvent)

Dim lParamID
Dim lParamCount
Dim strValue
Dim objCurrentEvent


On Error Resume Next


'Initialize the properties of the new event object.
'Note, commented out lines indicate properties that can not be set or
'that are required.
'====================================================================

Set objCurrentEvent = ScriptContext.Event

'objEvent.ID = ScriptContext.Event.ID
objEvent.EventType = objCurrentEvent.EventType
objEvent.Category = objCurrentEvent.Category
'objEvent.Time = objCurrentEvent.Time
objEvent.LoggingComputer = objCurrentEvent.LoggingComputer
objEvent.SourceComputer = objCurrentEvent.SourceComputer
objEvent.UserName = objCurrentEvent.UserName
objEvent.MessageDLL = objCurrentEvent.MessageDLL
'objEvent.MessageDLLFileVersion = objCurrentEvent.MessageDLLFileVersion
objEvent.EventNumber = objCurrentEvent.EventNumber
objEvent.Message = objCurrentEvent.Message
objEvent.LoggingDomain = objCurrentEvent.LoggingDomain
objEvent.SourceDomain = objCurrentEvent.SourceDomain
objEvent.EventSource = objCurrentEvent.EventSource
objEvent.LocalTime = objCurrentEvent.LocalTime

lParamCount = objCurrentEvent.EventParameterCount

If lParamCount Then

For lParamID = 1 to lParamCount
strValue = objCurrentEvent.EventParameter(lParamID)
objEvent.SetEventParameter(strValue)
Next

End If

'objEvent.UserDomainName = objCurrentEvent.UserDomainName

'Override the event source with this script's name.
'==================================================

objEvent.EventSource = ScriptContext.Name

Set objCurrentEvent = Nothing

End Sub


'******************************************************************************
' Name: IsSMSSiteBackupServiceStarted
'
' Purpose: Checks if the SMS Site Backup service is started, running.
'
' Parameters: None
'
' Returns: Integer, the data to return or zero
'
Function IsSMSSiteBackupServiceStarted()

Dim objServiceSet
Dim objService
Dim strQuery


On Error Resume Next


'Get the status of the SMS Site Backup service. If WMI is not running
'or WMI is inaccessible or backup service is not registered, consider
'the service as not started.
'=====================================================================

strQuery = "select * from Win32_Service where Name='SMS_SITE_BACKUP'"

Set objServiceSet = GetObject("winmgmts:\\"+ ScriptContext.TargetComputer+ "\root\cimv2").ExecQuery(strQuery)

IsSMSSiteBackupServiceStarted = False

If Err Then
Set objServiceSet = Nothing
ScriptError "execute a WMI query to get the WMI Win32_Service object for SMS_SITE_BACKUP." &amp; GetErrorString(Err)
Exit Function
End If

If Not IsEmpty(objServiceSet) Then

For Each objService In objServiceSet
IsSMSSiteBackupServiceStarted = objService.Started
Next

Set objService = Nothing

End If

Set objServiceSet = Nothing

End Function


'******************************************************************************
' 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
'
' Returns: 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 &gt;= 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 = &amp;HFFFF0000
Const HiWord8007 = &amp;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 " &amp; (lErr And LoWordMask))

Dim strMessage, i

Do
strMessage = oExec.stdout.ReadLine()
i = i + 1
Loop While (Len(strMessage) = 0) And (i &lt; 5)

strErr = strMessage

End If

End If

End If

GetErrorString = vbCrLf &amp; "The error returned was: '" &amp; strErr &amp; "' " &amp; lErr &amp; " (0x" &amp; Hex(lErr) &amp; ")"

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." &amp; vbCrLf &amp; "Failed to " &amp; 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 objEvent


On Error Resume Next

Set objEvent = ScriptContext.CreateEvent

objEvent.EventNumber = lEventID
objEvent.EventType = lEventType
objEvent.Message = "The script '" &amp; ScriptContext.Name &amp; "' " &amp; strMessage

ScriptContext.Submit objEvent

End Sub
</Script></Body>
<Language>VBScript</Language>
<Name>SMS 2003 Site Backup Event Suppression</Name>
<Parameters/>
<ManagementPackId>[Microsoft.SMS.2003,,1.0.0.1]</ManagementPackId>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="RunScriptAction"/>
</Composition>
</Composite>
</ModuleImplementation>
<InputType>SystemLibrary!System.BaseData</InputType>
</WriteActionModuleType>