Доступные версии документации

Приложение 2. Пример Generic Script

Скрипт hres.vbs выполняет контроль работы системы резервирования в Windows Cluster.

'Script-Level Global Variables
Dim serverStatus, databaseStatus
serverStatus   = "Undefined"
databaseStatus = "Undefined"

'  Utility functions
Function GetServerStatus()
  serverStatus   = "Undefined"
  Set goWSH = CreateObject("WScript.Shell")
  Set aRet = goWSH.Exec("E:\LINTER_32\EXEC\srvcmd.exe -getstate")
  Do While Not aRet.StdOut.AtEndOfStream
    strStdOut = aRet.StdOut.ReadLine()
    searchString = "server state = "
    If InStr(strStdOut, searchString) > 0 Then
      Resource.LogInformation("GetServerStatus " & Mid(strStdOut, Len(searchString) + 1))
      serverStatus = Mid(strStdOut, Len(searchString) + 1)
      Exit Do
    End If
  Loop     GetServerStatus = serverStatus
End Function

Function GetServerAndDatabaseStatus()
  serverStatus = "Undefined"
  databaseStatus = "Undefined"
  count = 0
  Set goWSH = CreateObject("WScript.Shell")
  Set aRet = goWSH.Exec("E:\LINTER_32\EXEC\srvcmd.exe -getstate")
  Do While Not aRet.StdOut.AtEndOfStream
    strStdOut = aRet.StdOut.ReadLine()
    searchServerString = "server state = "
    searchDatabaseString = "Last work database state    = "
    If InStr(strStdOut, searchDatabaseString) > 0 Then
      Resource.LogInformation("GetServerAndDatabaseStatus " &  Mid(strStdOut, Len(searchDatabaseString) + 1))
      databaseStatus = Mid(strStdOut, Len(searchDatabaseString) + 1)
      If 1 = count Then
        count = count + 1
        Exit Do
      End If
      count = count + 1
    End If
    If InStr(strStdOut, searchServerString) > 0 Then
      Resource.LogInformation("GetServerAndDatabaseStatus " &  Mid(strStdOut, Len(searchServerString) + 1))
      serverStatus = Mid(strStdOut, Len(searchServerString) + 1)
      If 1 = count Then
        count = count + 1
        Exit Do
      End If
      count = count + 1
    End If
  Loop
  Do While Not aRet.StdErr.AtEndOfStream
    strStdErr = aRet.StdErr.ReadLine()
    Resource.LogInformation(strStdErr)
  Loop
  If 2 = count Then
    GetServerAndDatabaseStatus = 0
  Else
    Resource.LogInformation("GetServerAndDatabaseStatus Error: database or server status not found")
    GetServerAndDatabaseStatus = 1
  End If
End Function

'  Entry points
Function Online( )
  Resource.LogInformation "Entering Online"
  Resource.LogInformation "Exiting Online"
  Online = true
End Function

Function Offline( )
  Resource.LogInformation "Entering Offline"
  If InStr(GetServerStatus(), "MAIN") > 0 Then
    Change state to SLAVE
    Set goWSH = CreateObject("WScript.Shell")
    goWSH.Exec("E:\LINTER_32\EXEC\srvcmd.exe -slave")
  End If
  Resource.LogInformation "Exiting Offline"
  Offline = true
End Function

Function LooksAlive( )
  Resource.LogInformation "Entering LooksAlive"
  LooksAlive = true
End Function

' IsAlive pool interval set to 20 seconds
Function IsAlive( )
  Resource.LogInformation "Entering IsAlive"
  retVal = GetServerAndDatabaseStatus()
  If retVal <> 0 Then
    Resource.LogInformation "IsAlive = false. Exiting IsAlive"
    IsAlive = false
    Exit Function
  End If
  If retVal = 0 And InStr(serverStatus, "SLAVE") > 0 And InStr(databaseStatus, "SLAVE") > 0 Then
    '   Change state to MAIN
      Set goWSH = CreateObject("WScript.Shell")
      goWSH.Exec("E:\LINTER_32\EXEC\srvcmd.exe -main")
    End If
    If retVal = 0 And InStr(serverStatus, "SLAVE") > 0 And InStr(databaseStatus, "UNDEFINED") > 0 Then
      Resource.LogInformation "IsAlive = false. Exiting IsAlive"
      IsAlive = false
      Exit Function
    End If
    Resource.LogInformation "IsAlive = true. Exiting IsAlive"
    IsAlive = true
End Function

Function Open( )
  Open = 0
End Function

Function Close( )
  Close = 0
End Function

Function Terminate( )
  Resource.LogInformation "Entering Terminate"
  Terminate = true
End Function
Заметили ошибку?
Выделите текст и нажмите Ctrl + Enter