DPM Heartbeat Update

DPM_Heartbeat_Update (WriteActionModuleType)

Update the DPM heartbeat state

Element properties:

TypeWriteActionModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
InputTypeSystem.BaseData
Comment{8ED5F16D-BE24-40FE-B681-07FB88616DA2}

Member Modules:

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

Source Code:

<WriteActionModuleType ID="DPM_Heartbeat_Update" Accessibility="Internal" Comment="{8ED5F16D-BE24-40FE-B681-07FB88616DA2}">
<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>
'-------------------------------------------------------------------
' &lt;company&gt;Microsoft Corporation&lt;/company&gt;
' &lt;copyright&gt;Copyright (c) Microsoft Corporation 2003&lt;/copyright&gt;
' &lt;summary&gt;
' Update the hearbeat and database components of DPS
' &lt;/summary&gt;
'-------------------------------------------------------------------
Option Explicit

' Constants

' Standard Event ID for script failure
Const EVENT_ID_SCRIPT_FAILURE = 40000
Const EVENT_ID_SERVICE_CRASH = 30500
Const EVENT_ID_DATABASE_CRASH = 30501
Const EVENT_ID_SERVICE_SUCCESS = 30502
Const EVENT_ID_DATABASE_SUCCESS = 30503

'Event log event severity
Const EVENT_TYPE_ERROR = 1
Const EVENT_TYPE_WARNING = 2
Const EVENT_TYPE_INFORMATION = 4

'MOM Alert severity
Const MOMALERT_SEVERITY_CRITICALERROR = 50
Const MOMALERT_SEVERITY_WARNING = 30
Const MOMALERT_SEVERITY_INFORMATION = 20

'Problem state constants
Const ALERT_PROBLEM_STATE_ACTIVE = 3
Const ALERT_PROBLEM_STATE_INACTIVE = 1
Const EVENT_CATEGORY_ACTIVE = 1
Const EVENT_CATEGORY_INACTIVE = 2

'Event field order
Const ALERT_PROBLEM_RECOMMENDEDACTION = "$1"
Const ALERT_COMPUTERNAME = "$2"
Const ALERT_NAME = "$3"
Const ALERT_ROLE = "$4"
Const ALERT_COMPONENT = "$5"
Const ALERT_INSTANCE = "$6"

'Event parameter
Const gEVENT_PARAMETER_DESCRIPTION = 1

'Name used for the state variable used to hold context for DPM MOM script
Const strDPSProductionServerList = "DPSProductionServers"
'Name used for error reporting
Const strProductNameForError = "Data Protection Manager"

'DPM Meta model constants
Const strServerDiscoveryScopeFilter = "ComputerName"
Const strDPSRole = "DPM"
Const strDPSComponentPrimaryKey = "Name"
Const strDPSComponentHeartbeat = "HeartBeat"
Const strDPSComponentDatabase = "Database"
Const strDPSComponentPerf = "Performance"
Const strDPSComponentOther = "Other"

'Constants for hearbeat and connectivity alerts
Dim strDPSDatabaseAlertDescription,strDPSHearbeatAlertDescription
strDPSDatabaseAlertDescription = "The DPM database is not available."&amp; vbNewLine &amp; _
vbNewLine &amp; vbNewLine &amp; "DPM ID:75653C2D-EC0F-4cd4-8189-B416017DB965:0"
Const strDPSDatabaseAlertName = "DPM Database Not Available"
strDPSHearbeatAlertDescription = "The DPM service has failed." &amp; vbNewLine &amp; _
vbNewLine &amp; vbNewLine &amp; "DPM ID:75653C2D-EC0F-4cd4-8189-B416017DB965:0"
Const strDPSHearbeatAlertName = "DPM Service Not Available"

'Event descriptions
Const strDPSServiceDiscoveryComputerDiscoveryEventDescription = "DPM service discovery has updated the list of protected servers."
Const strDPSHeartbeatFailureEventDescription = "During the past 30 minutes, MOM has failed to confirm the completion of any jobs on the DPM computer. This may be due to a failure of the DPM service or a database failure."
Const strDPSHeartbeatSuccessEventDescription = "During the past 30 minutes, MOM has confirmed the completion of at least one job on the DPM computer."

'PS Meta Model constants
Const strPSRole = "DPM Protected"
Const strPSComponentPrimaryKey = "Volume/Computer"
Const strPSComponentReplica = "Replica"
Const strPSComponentShadowCopy = "Shadow Copies"
Const strPSComponentConnectivity = "Connectivity"
Const strPSComponentRecovery = "Recovery"

'Database related constants
Const strConnectionString = "integrated security=SSPI;Provider=SQLOLEDB; Data Source=(local)\MICROSOFT$DPM$;Initial Catalog=DPMDB;"
Const strProcedureDataSource = "prc_MOM_DataSource_Get"
Const strProcedureProductionServer = "prc_MOM_ProductionServer_Get"
Const strProcedureHeartbeat = "prc_MOM_Heartbeat_Get"
Const strProcedureParamServerName = "@ServerName"
Const strDbParamPS = "ServerName"
Const boolDbParamAgentDeleted = "Deleted"
Const strDbParamVolume = "Volume"
Const strDbParamReturnValue = "@RETURN_VALUE"
Const strDbParamConnectivityJobCount = "JobCount"

'ADO Constants
Const intADONVarChar = 202
Const intADOInt = 3
Const intADOParamInput = 1
Const intADOParamReturnValue = 4
Const intADOCmdStoredProc = 4

'=============
' Method: CreateStoredProcedure
' Description: Create a command to execute a stored procedure. Adds the return value as an argument for the command
' Arguments
' strProcName - Name of the stored procedure
' objCommand - ADO command
' objConnection - ADO connection
'=============
Sub CreateStoredProcedure(strProcName,objCommand,objConnection)
Dim returnParam

set objCommand = CreateObject("ADODB.Command")
set returnParam = objCommand.CreateParameter(strDbParamReturnValue,intADOInt, intADOParamReturnValue)
objCommand.Parameters.Append returnParam
With objCommand
Set .ActiveConnection = objConnection
.CommandText = strProcName
.CommandType = intADOCmdStoredProc
End With
End Sub

'=============
' Method: ValidateStoredProcedureReturnValue
' Description: Validate the return value of the stored procedure
' Arguments
' objCommand - ADO command
' strProcedureName - Name of the stored procedure
'=============
Sub ValidateStoredProcedureReturnValue(objCommand,strProcedureName)
Dim returnVal
returnVal = objCommand.Parameters(strDbParamReturnValue).Value
'If we are returning custom error values this will not work
If (returnVal &lt;&gt;0) Then
ThrowScriptError returnVal, strProcedureName
End If
End Sub

'=============
' Method: Trace
' Description: Trace to the MOM Log.
' Uses the strComponent defined globally for the file
'=============
Sub Trace(strMessage)
On Error Resume Next
Dim strMsg
strMsg = strComponent &amp; ": " &amp; strMessage
ScriptContext.Echo strMsg
End Sub

'=============
' Method: ThrowScriptError
' Description: Creates an event and sends it back to the mom server
'This triggers a 'MOM' MOM pack rule which displays an error to the user
'Execution of the script stops after the event is created
'=============

Sub ThrowScriptError(intErrorCode,strErrorDescription)
On Error Resume Next
Dim objScriptErrorEvent

Set objScriptErrorEvent = ScriptContext.CreateEvent()
With objScriptErrorEvent
.EventNumber = EVENT_ID_SCRIPT_FAILURE
.EventType = EVENT_TYPE_ERROR
.Message = strVbError
.SetEventParameter strProductNameForError
.SetEventParameter intErrorCode 'Error Event
.SetEventParameter strErrorDescription 'Error description
.SetEventParameter intErrCode
End With
ScriptContext.Submit objScriptErrorEvent
ScriptContext.Quit
End Sub

'=============
' Method: Create a MOM Alert
' If the Role is empty it means it is a stateless alert and there is no need to set the role,component,instane and problem state
'=============

Sub CreateAlert (objAlert,alertLevel,strComputer,strDomain,strAlertSource,strAlertDescription,strAlertName,strRole,strComponent,strInstance,intProblemState)
Set objAlert = ScriptContext.CreateAlert()
objAlert.AlertLevel = alertLevel
objAlert.Computer = strComputer
objAlert.ComputerDomain = strDomain
objAlert.AlertSource = strAlertSource
objAlert.Description = strAlertDescription
objAlert.Name = strAlertName
If (Len(strRole) &lt;&gt; 0) Then
objAlert.ServerRole = strRole
objAlert.Component = strComponent
objAlert.ServerRoleInstance = strInstance
objAlert.ProblemState = intProblemState
End If
End Sub

'=============
' Method: Create and submit a MOM Alert
'=============
Sub CreateAndSubmitAlert (objAlert,alertLevel,strComputer,strDomain,strAlertSource,strAlertDescription,strAlertName,strRole,strComponent,strInstance,intProblemState)
CreateAlert objAlert,alertLevel,strComputer,strDomain,strAlertSource,strAlertDescription,strAlertName,strRole,strComponent,strInstance,intProblemState
ScriptContext.Submit objAlert
End Sub

'=============
' Method: Create a MOM Event
'=============
Sub CreateEvent (intEventSeverity,strMessage,strComputer,strDomain,intEventNumber)
Dim objEvent
Trace "Creating event " &amp; intEventNumber
Set objEvent = ScriptContext.CreateEvent()
With objEvent
.EventType = intEventSeverity
.Message = strMessage
.LoggingComputer = strComputer
.LoggingDomain = strDomain
.EventNumber = intEventNumber
End With
ScriptContext.Submit objEvent
End Sub

Const strComponent = "DPM Connectivity"

'=============
' Method: Main
' Description: The Sub called by MOM Runtime (with ScriptContext object)
'=============
Sub Main()
On Error Resume Next
'Update the DPM Status
Call UpdateDPSStatus()
If (Err.number &lt;&gt; 0) Then
ThrowScriptError Err.number, Err.Description
End If
End Sub

'=============
' Method: UpdateDPSStatus
' Description: Update the heartbeat component of the DPM server
'=============
Sub UpdateDPSStatus()
Trace "Entered update DPM heartbeat Status"
Dim objAlert,dbAlert
Dim intEventID
Dim strComputer,strDomain
If (ScriptContext.IsEvent) Then
' Retrieve the event ID
intEventID = ScriptContext.Event.EventNumber
strComputer = ScriptContext.TargetNetbiosComputer
strDomain = ScriptContext.TargetNetbiosDomain
If (intEventID = EVENT_ID_SERVICE_CRASH)Then
Trace " DPM heartbeat - Red"
CreateAndSubmitAlert objAlert,MOMALERT_SEVERITY_CRITICALERROR,strComputer,strDomain,strComputer,strDPSHearbeatAlertDescription,strDPSHearbeatAlertName,strDPSRole,strDPSComponentHeartbeat,strComputer,ALERT_PROBLEM_STATE_ACTIVE
ElseIf (intEventID = EVENT_ID_SERVICE_SUCCESS)Then
Trace " DPM heartbeat - Green"
'Set the heartbeat to green
CreateAndSubmitAlert objAlert,MOMALERT_SEVERITY_INFORMATION,strComputer,strDomain,strComputer,strDPSHearbeatAlertDescription,strDPSHearbeatAlertName,strDPSRole,strDPSComponentHeartbeat,strComputer,ALERT_PROBLEM_STATE_INACTIVE
End If
End If
End Sub</Script></Body>
<Language>VBScript</Language>
<Name>DPM Heartbeat Update</Name>
<Parameters/>
<ManagementPackId>[Microsoft.SystemCenter.DPM,,1.0.0.1]</ManagementPackId>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="RunScriptAction"/>
</Composition>
</Composite>
</ModuleImplementation>
<InputType>SystemLibrary!System.BaseData</InputType>
</WriteActionModuleType>