Const STATE_ALERTSOURCE = "VCS for Windows Management Pack"
Const STATE_NAME = "Veritas Cluster Service '%1' State"
Const GROUP_STATE_DESCRIPTION_RED = "The Group %1 has failed or is unavailable"
Const GROUP_STATE_DESCRIPTION_YELLOW = "The Group %1 is in a pending state or is partially online."
Const GROUP_STATE_DESCRIPTION_GREEN = "The Group %1 is online in the cluster."
Const GROUP_STATE_DESCRIPTION_GREEN_ONNODE = "The Group %1 is offline on the current node."
Const STATE_DESCRIPTION_RED = "The Resource %1 has failed or is unavailable"
Const STATE_DESCRIPTION_YELLOW = "The Resource %1 is in a pending state or is partially online."
Const STATE_DESCRIPTION_GREEN = "The Resource %1 is online in the cluster."
Const STATE_DESCRIPTION_GREEN_ONNODE = "The Resource %1 is offline on the current node."
Sub Main()
Dim objFSO, objShell, wfolder
Dim objTextFile, strAPIState
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set wfolder = objFSO.GetSpecialFolder(WindowsFolder)
'Create Current StateFile
Dim objScriptExec
Set objScriptExec = objShell.Exec("%VCS_HOME%\Bin\MOMUtil.exe discover")
Set objTextFile = objFSO.OpenTextFile(FILE_DIRECTORY & FILENAME, ForWriting, True)
strAPIState = objScriptExec.StdOut.ReadAll
If InStr (1, strAPIState, "error", 1) > 0 Then
'if some failure
Exit Sub
Else
objTextFile.WriteLine(strAPIState)
End If
objTextFile.close
'State Changed so generate alert for new state
Set objTextFile = objFSO.OpenTextFile(FILE_DIRECTORY & FILENAME,ForReading, true)
Dim FirstGroup
Dim oGroup, oService
Set oGroup = New CSubGroupRole
Set oService = New CSubGroupRole
FirstGroup = 1
Dim arrServiceList, strNextLine
Do While objTextFile.AtEndOfline <> True
strNextLine = objTextFile.Readline
arrServiceList = Split(strNextLine , ",")
Select Case( arrServiceList(0) )
Case "Group" :
If ( FirstGroup = 1) Then
FirstGroup = 0
oGroup.Define arrServiceList(1), "Group"
oService.Define arrServiceList(1), "Service"
oGroup.AddState arrServiceList(2), arrServiceList(1)
Else
With ScriptContext
.Echo ""
.Echo "Updating Resource Group State: "
oGroup.CreateAlert()
oService.CreateAlert()
.Echo ""
End With
oGroup.AddState arrServiceList(2), arrServiceList(1)
End If
Case "Resource" :
oService.AddState arrServiceList(3), arrServiceList(2)
Case "End" :
With ScriptContext
.Echo ""
.Echo "Updating Resource Group State: "
oGroup.CreateAlert()
oService.CreateAlert()
.Echo ""
End With
oGroup.ResetAll
oService.ResetAll
'Exit Do
End Select
Loop
objTextFile.close
End Sub
'
'
Class CSubGroupRole
Dim m_sInstance, m_sSGR, m_nResourceWorstState, m_sResourceTypeName
Private Sub Class_Initialize()
ResetAll
End Sub
Private Property Get ProblemState
ProblemState = GetProblemState(m_nResourceWorstState)
End Property
Private Property Get AlertLevel
AlertLevel = GetAlertLevel(m_nResourceWorstState)
End Property
Public Sub ResetAll()
m_nResourceWorstState = Empty
m_sResourceTypeName = Empty
m_sInstance = Empty
m_sSGR = Empty
End Sub
Public Sub Define(sInstance, sSGR)
m_sInstance = sInstance
m_sSGR = sSGR
End Sub
Public Sub AddState(nResourceState, sResourceTypeName)
If ProblemState <= GetProblemState(nResourceState) Then
If AlertLevel <= GetAlertLevel(nResourceState) Then
if m_nResourceWorstState = nResourceState Then
if Len(m_sResourceTypeName) > 1 Then
m_sResourceTypeName = m_sResourceTypeName + ", " + sResourceTypeName
Else
m_sResourceTypeName = sResourceTypeName
End if
else
m_sResourceTypeName = sResourceTypeName
End if
m_nResourceWorstState = nResourceState
End If
End If
End Sub
Public Function CreateAlert()
If AlertLevel = 0 Then
ScriptContext.Echo " * " & m_sSGR & " not submitted: AlertLevel(" & AlertLevel & ") not set."
Else
Dim oAlert
Set oAlert = ScriptContext.CreateAlert()
If .AlertLevel <> ALERT_WARNING And .AlertLevel <> ALERT_ERROR AND .AlertLevel <> ALERT_INFORMATION AND .ProblemState = PROBLEMSTATE_RED Then
If m_sSGR = "Group" Then
.Description = Replace(GROUP_STATE_DESCRIPTION_RED, "%1", m_sResourceTypeName)
Else
.Description = Replace(STATE_DESCRIPTION_RED, "%1", m_sResourceTypeName)
End If
ElseIf .ProblemState = PROBLEMSTATE_YELLOW Then
If m_sSGR = "Group" Then
If .AlertLevel = ALERT_INFORMATION Then
.Description = Replace(GROUP_STATE_DESCRIPTION_GREEN_ONNODE, "%1", m_sResourceTypeName)
Else
.Description = Replace(GROUP_STATE_DESCRIPTION_YELLOW, "%1", m_sResourceTypeName)
End If
ElseIf .AlertLevel = ALERT_INFORMATION Then
.Description = Replace(STATE_DESCRIPTION_GREEN_ONNODE, "%1", m_sResourceTypeName)
Else
.Description = Replace(STATE_DESCRIPTION_YELLOW, "%1", m_sResourceTypeName)
End If
Else
If m_sSGR = "Group" Then
.Description = Replace(GROUP_STATE_DESCRIPTION_GREEN, "%1", m_sResourceTypeName)
Else
.Description = Replace(STATE_DESCRIPTION_GREEN, "%1", m_sResourceTypeName)
End If
End If
End With
ScriptContext.Submit oAlert
ScriptContext.Echo "instance" & m_sInstance
ScriptContext.Echo " * " & m_sSGR & " set to ProblemState(" & ProblemState & "), AlertLevel(" & AlertLevel & ")"
End If
End Function
Private Function GetProblemState(nResourceState)
If IsEmpty(nResourceState) Then
GetProblemState = PROBLEMSTATE_NOTSET
Exit Function
End If
If m_sSGR = "Group" Then
Select Case (nResourceState)
Case "OFFLINE": GetProblemState = PROBLEMSTATE_RED
Case "FAULTED": GetProblemState = PROBLEMSTATE_RED
Case "STARTING", _
"PENDING", _
"STOPPING",_
"PARTIAL": GetProblemState = PROBLEMSTATE_YELLOW
Case "ONLINE": GetProblemState = PROBLEMSTATE_GREEN
Case "OFFLINE_ON_NODE": GetProblemState = PROBLEMSTATE_YELLOW
Case Else: GetProblemState = PROBLEMSTATE_GREEN
End Select
Else
Select Case (nResourceState)
Case "OFFLINE": GetProblemState = PROBLEMSTATE_RED
Case "FAULTED": GetProblemState = PROBLEMSTATE_RED
Case "ONLINE": GetProblemState = PROBLEMSTATE_GREEN
Case "OFFLINE_ON_NODE": GetProblemState = PROBLEMSTATE_YELLOW
Case Else: GetProblemState = PROBLEMSTATE_GREEN
End Select
End If
End Function
Private Function GetAlertLevel(nResourceState)
If IsEmpty(nResourceState) Then
GetAlertLevel = 0
Exit Function
End If
If m_sSGR = "Group" Then
Select Case (nResourceState)
Case "OFFLINE": GetAlertLevel = ALERT_SERVICE_UNAVAILABLE
Case "FAULTED": GetAlertLevel = ALERT_CRITICAL_ERROR
Case "PENDING", _
"PARTIAL",_
"STARTING",_
"STOPPING": GetAlertLevel = ALERT_WARNING
Case "ONLINE": GetAlertLevel = ALERT_SUCCESS
Case "OFFLINE_ON_NODE": GetAlertLevel = ALERT_INFORMATION
Case Else: GetAlertLevel = ALERT_SUCCESS
End Select
Else
Select Case (nResourceState)
Case "OFFLINE": GetAlertLevel = ALERT_SERVICE_UNAVAILABLE
Case "FAULTED": GetAlertLevel = ALERT_CRITICAL_ERROR
Case "ONLINE": GetAlertLevel = ALERT_SUCCESS
Case "OFFLINE_ON_NODE": GetAlertLevel = ALERT_INFORMATION
Case Else: GetAlertLevel = ALERT_SUCCESS
End Select
End If
End Function
End Class </Script></Body>
<Language>VBScript</Language>
<Name>VeritasCluster State Monitoring</Name>
<Parameters/>
<ManagementPackId>[Symantec.SFW.HA,,5.1.0000.0]</ManagementPackId>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="RunScriptAction"/>
</Composition>
</Composite>
</ModuleImplementation>
<InputType>SystemLibrary!System.BaseData</InputType>
</WriteActionModuleType>