'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"
'Constants for hearbeat and connectivity alerts
Dim strDPSDatabaseAlertDescription,strDPSHearbeatAlertDescription
strDPSDatabaseAlertDescription = "The DPM database is not available."& vbNewLine & _
vbNewLine & vbNewLine & "DPM ID:75653C2D-EC0F-4cd4-8189-B416017DB965:0"
Const strDPSDatabaseAlertName = "DPM Database Not Available"
strDPSHearbeatAlertDescription = "The DPM service has failed." & vbNewLine & _
vbNewLine & vbNewLine & "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."
'=============
' 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 <>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 & ": " & 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) <> 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 " & 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 Timed heartbeat check"
'=============
' Method: Main
' Description: The Sub called by MOM Runtime (with ScriptContext object)
'=============
Sub Main()
On Error Resume Next
'Check the heartbeat of the DPM Server
Call CheckHeartbeat()
If (Err.number <> 0) Then
ThrowScriptError Err.number, Err.Description
End If
End Sub
'=============
' Method: CheckHeartbeat
' Description: Check the heartbeat of the DPM Server
'=============
Sub CheckHeartbeat
Dim objConnection,objHeartbeatCommand,objHeartbeatRecordSet,intCount
Trace "Checking DPM heartbeat"
'Create the AODB object
Set objConnection = CreateObject("ADODB.Connection")
'Open the db connection
objConnection.Open strConnectionString
'Create the record set to retrieve the servernames
CreateStoredProcedure strProcedureHeartbeat,objHeartbeatCommand,objConnection
set objHeartbeatRecordSet=objHeartbeatCommand.execute
Do Until objHeartbeatRecordSet.EOF
'Get the count of connectivity jobs
intCount = objHeartbeatRecordSet(strDbParamConnectivityJobCount)
if (intCount > 0) Then
Trace "DPM heartbeat success"
CreateEvent EVENT_TYPE_INFORMATION,strDPSHeartbeatSuccessEventDescription,ScriptContext.TargetNetbiosComputer,ScriptContext.TargetNetbiosDomain,EVENT_ID_SERVICE_SUCCESS
CreateEvent EVENT_TYPE_INFORMATION,strDPSHeartbeatSuccessEventDescription,ScriptContext.TargetNetbiosComputer,ScriptContext.TargetNetbiosDomain,EVENT_ID_DATABASE_SUCCESS
Else
Trace "DPM heartbeat fail"
CreateEvent EVENT_TYPE_ERROR,strDPSHeartbeatFailureEventDescription,ScriptContext.TargetNetbiosComputer,ScriptContext.TargetNetbiosDomain,EVENT_ID_SERVICE_CRASH
End If
' Exit the do loop
Exit Do
Loop
'Clean up
objHeartbeatRecordSet.Close
set objHeartbeatRecordSet = Nothing
ValidateStoredProcedureReturnValue objHeartbeatCommand, strProcedureDataSource
set objHeartbeatCommand = Nothing
objConnection.Close
set objConnection = Nothing
End Sub