VeritasCluster State Monitoring

VeritasCluster_State_Monitoring (WriteActionModuleType)

Monitors the state of VCS service groups and resources

Element properties:

TypeWriteActionModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
InputTypeSystem.BaseData

Member Modules:

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

Source Code:

<WriteActionModuleType ID="VeritasCluster_State_Monitoring" Accessibility="Internal" Batching="false">
<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 Isolation="Any">
<Composite>
<MemberModules>
<WriteAction ID="RunScriptAction" TypeID="MomBackwardCompatibility!System.Mom.BackwardCompatibility.ScriptResponse">
<AlertGeneration>$Config/AlertGeneration$</AlertGeneration>
<InvokerType>$Config/InvokerType$</InvokerType>
<Body><Script>
Option explicit
Const WindowsFolder = 0
Const ForWriting = 2
Const ForReading = 1

Public FILENAME
Public FILE_DIRECTORY

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."

'
' Problem States
'
Const PROBLEMSTATE_NOTSET = 0
Const PROBLEMSTATE_GREEN = 1
Const PROBLEMSTATE_YELLOW = 3 ' Yellow = Red+(Warning|Error)
Const PROBLEMSTATE_RED = 3
'
' Alerts
'
Const ALERT_SUCCESS = 10
Const ALERT_INFORMATION = 20
Const ALERT_WARNING = 30
Const ALERT_ERROR = 40
Const ALERT_CRITICAL_ERROR = 50
Const ALERT_SECURITY_BREACH = 60
Const ALERT_SERVICE_UNAVAILABLE = 70
'
' Cluster Group States
'
Const CLUSTER_GROUP_ONLINE = 0
Const CLUSTER_GROUP_OFFLINE = 1
Const CLUSTER_GROUP_FAILED = 2
Const CLUSTER_GROUP_PARTIAL_ONLINE = 3
Const CLUSTER_GROUP_PENDING = 4
Const CLUSTER_GROUP_STATE_UNKNOWN = -1


'
' Cluster Resource States
'

Const CLUSTER_RESOURCE_INHERITED = 0
Const CLUSTER_RESOURCE_INITIALIZING = 1
Const CLUSTER_RESOURCE_ONLINE = 2
Const CLUSTER_RESOURCE_OFFLINE = 3
Const CLUSTER_RESOURCE_FAILED = 4
Const CLUSTER_RESOURCE_PENDING = 128
Const CLUSTER_RESOURCE_ONLINE_PENDING = 129
Const CLUSTER_RESOURCE_OFFLINE_PENDING = 130
Const CLUSTER_RESOURCE_STATE_UNKNOWN = -1



Sub Main()
Dim objFSO, objShell, wfolder
Dim objTextFile, strAPIState

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set wfolder = objFSO.GetSpecialFolder(WindowsFolder)

FILENAME = "\\Temp\\StateMntr_" + ScriptContext.TargetNetbiosComputer+ ".txt"
FILE_DIRECTORY = wfolder

'Create Current StateFile
Dim objScriptExec
Set objScriptExec = objShell.Exec("%VCS_HOME%\Bin\MOMUtil.exe discover")
Set objTextFile = objFSO.OpenTextFile(FILE_DIRECTORY &amp; FILENAME, ForWriting, True)

strAPIState = objScriptExec.StdOut.ReadAll
If InStr (1, strAPIState, "error", 1) &gt; 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 &amp; 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 &lt;&gt; 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.ResetAll
oService.ResetAll

oGroup.Define arrServiceList(1), "Group"
oService.Define arrServiceList(1), "Service"

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 &lt;= GetProblemState(nResourceState) Then
If AlertLevel &lt;= GetAlertLevel(nResourceState) Then
if m_nResourceWorstState = nResourceState Then
if Len(m_sResourceTypeName) &gt; 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 " * " &amp; m_sSGR &amp; " not submitted: AlertLevel(" &amp; AlertLevel &amp; ") not set."
Else
Dim oAlert
Set oAlert = ScriptContext.CreateAlert()

With oAlert
.AlertSource = STATE_ALERTSOURCE
.Name = Replace(STATE_NAME, "%1", m_sInstance)
.ServerRole = "VeritasCluster"
.ServerRoleInstance = m_sInstance
.Component = m_sSGR
.ProblemState = ProblemState
.AlertLevel = AlertLevel

If .AlertLevel &lt;&gt; ALERT_WARNING And .AlertLevel &lt;&gt; ALERT_ERROR AND .AlertLevel &lt;&gt; 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" &amp; m_sInstance
ScriptContext.Echo " * " &amp; m_sSGR &amp; " set to ProblemState(" &amp; ProblemState &amp; "), AlertLevel(" &amp; AlertLevel &amp; ")"
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>