<WriteActionModuleType ID="System.Mom.BackwardCompatibility.SubmitServiceStateEventsWriteAction" Accessibility="Internal">
<Configuration/>
<ModuleImplementation>
<Composite>
<MemberModules>
<ConditionDetection TypeID="System.Mom.BackwardCompatibility.NoHost.StandardResponseContext.Mapper" ID="Mapper">
<AlertGeneration>
<GenerateAlert>false</GenerateAlert>
</AlertGeneration>
<InvokerType>0</InvokerType>
<ManagementPackId/>
</ConditionDetection>
<WriteAction TypeID="System.Mom.BackwardCompatibility.ScriptWriteAction" ID="ScriptWriteAction">
<Body><Script>
'--------------------------------------------------------------------------
'
' Back Compat Service Monitor script
'
' This script collects the states of all services running in the system and
' submits Back Compat Service state events (event id 21207) in order for
' converted rules to properly handle service monitoring.
'
'---------------------------------------------------------------------------
Option Explicit
' Returns the State Enum numeric value as defined by MOM 2005
Function GetStateEnumValue(ByRef StateEnumString)
If IsEmpty(StateEnumString) Then
GetStateEnumValue = ""
Exit Function
End If
Dim CurrentIndex
For CurrentIndex = 0 to UBound(aStateEnum, 1)
If (StateEnumString = aStateEnum(CurrentIndex)) Then
GetStateEnumValue = CurrentIndex+1
Exit Function
End If
Next
GetStateEnumValue = 0
End Function
' Returns the Startup Type Enum numeric value as defined by MOM 2005
Function GetStartupTypeEnumValue(ByRef StartupTypeEnumString)
Dim CurrentIndex
For CurrentIndex = 0 to UBound(aStartupTypeEnum, 1)
If (StartupTypeEnumString = aStartupTypeEnum(CurrentIndex)) Then
GetStartupTypeEnumValue = CurrentIndex
Exit Function
End If
Next
GetStartupTypeEnumValue = -1
End Function
' Safely sets the event parameter and logs on failure
Sub SetServiceEventParameter(ByRef oEvent, ByRef ServiceName, ByRef PropertyName, ByRef PropertyValue)
On Error Resume Next
Call oEvent.SetEventParameter(PropertyValue)
If (Err.number <> 0) Then
ScriptContext.Echo "SetEventParameter failed to retrieve '" & PropertyName & "' for service '" & ServiceName & "!"
ScriptContext.Echo PropertyName & " = '" & PropertyValue & "'"
End If
On Error Goto 0
End Sub
' Submits the MOM 2005 specified event for state monitoring
Sub SubmitServiceStateEvent(ByRef SecondsElapsed, ByRef DisplayName, ByRef OldState, ByRef NewState, ByRef ShortName, ByRef StartMode, ByRef Account)
Dim oStateEvent
Set oStateEvent = ScriptContext.CreateEvent()
With oStateEvent
.EventNumber = 21207
.EventSource = "Microsoft Operations Manager"
End With
' If there was no error setting event params, submit the event
If (Err.number = 0) Then
Call ScriptContext.Submit(oStateEvent)
End If
End Sub
Dim objWMIService
Dim colServices
Dim objCurrentService
Dim objScriptState
Dim objServiceSet
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & ScriptContext.TargetFQDNComputer & "\root\cimv2")
' Get the Service Set for storing/retrieving the service states
Set objScriptState = ScriptContext.GetScriptState()
Set objServiceSet = objScriptState.GetSet("__ServiceState")
' Get and save the last time from storage
Dim lastTime
lastTime = objServiceSet.get("lastTime")
Call objServiceSet.put("lastTime", Now)
' Enumerate the services and submit state events
Set colServices = objWMIService.ExecQuery("Select DisplayName, State, Name, StartMode, StartName FROM Win32_Service")
For Each objCurrentService in colServices
' Ignore services without a name
If ( Not IsNull(objCurrentService) And Not IsNull(objCurrentService.Name) And Not IsEmpty(objCurrentService.Name) ) Then
' Get and save the last State from storage
Dim oldState
oldState = objServiceSet.get(objCurrentService.Name)
' If there is a state change, update the state and submit the event
If oldState <> objCurrentService.State Then
Call objServiceSet.put(objCurrentService.Name, objCurrentService.State)