'**********************************************************************************
' Script Name - Huawei Pool Properites Discovery
' Author: Muralidhar L, Vignesh Pandian
'
' Description:
' Discovery of Huawei Pool and all it's attributes.
'
' (c) Copyright Huawei Inc. 2013-2015. All rights reserved
'**********************************************************************************
Option Explicit
SetLocale("en-us")
Dim oAPI, oDiscoveryData, oInst
Set oAPI = CreateObject("MOM.ScriptAPI")
Dim oArgs
set oArgs = wscript.arguments
If oArgs.Count > 27 Then
Call oAPI.LogScriptEvent("DiscoverdiskDomainProperites.vbs",101,0, _
"script was called with fewer than three arguments and was not executed.")
Wscript.Quit -1
End If
Set oDiscoveryData = oAPI.CreateDiscoveryData(0, SourceID, ManagedEntityID)
Dim oFSo
Set oFso = CreateObject("Scripting.FileSystemObject")
Set oInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='Huawei.ISM.Management.Pack.huawei.Class.StoragePool']$")
Call oInst.AddProperty("$MPElement[Name='SNL!System.NetworkManagement.Node']/DeviceKey$", deviceKey)
Call oInst.AddProperty("$MPElement[Name='Huawei.ISM.Management.Pack.huawei.Class.StoragePool']/id$", PoolId)
Call oInst.AddProperty("$MPElement[Name='Huawei.ISM.Management.Pack.huawei.Class.StoragePool']/poolName$", UTF8BadDecode(PoolName))
Call oInst.AddProperty("$MPElement[Name='Huawei.ISM.Management.Pack.huawei.Class.StoragePool']/poolDiskDomainID$", PoolDiskDomainID)
Call oInst.AddProperty("$MPElement[Name='Huawei.ISM.Management.Pack.huawei.Class.StoragePool']/poolDiskDomainName$", PoolDiskDomainName)
Call oInst.AddProperty("$MPElement[Name='Huawei.ISM.Management.Pack.huawei.Class.StoragePool']/poolHealthStatus$",ConversionStatus(PoolHealthStatus))
Call oInst.AddProperty("$MPElement[Name='Huawei.ISM.Management.Pack.huawei.Class.StoragePool']/poolRunningStatus$", ConversionRunningStatus(PoolRunningStatus))
Call oInst.AddProperty("$MPElement[Name='Huawei.ISM.Management.Pack.huawei.Class.StoragePool']/poolTotalCapacity$", ConversionCapacity(PoolTotalCapacity))
Call oInst.AddProperty("$MPElement[Name='Huawei.ISM.Management.Pack.huawei.Class.StoragePool']/poolSubscribedCapacity$", ConversionCapacity(PoolSubscribedCapacity))
Call oInst.AddProperty("$MPElement[Name='Huawei.ISM.Management.Pack.huawei.Class.StoragePool']/poolFreeCapacity$", ConversionCapacity(PoolFreeCapacity))
Call oInst.AddProperty("$MPElement[Name='Huawei.ISM.Management.Pack.huawei.Class.StoragePool']/poolProtectionCapacity$", ConversionCapacity(PoolProtectionCapacity))
Call oInst.AddProperty("$MPElement[Name='Huawei.ISM.Management.Pack.huawei.Class.StoragePool']/poolTier0Capacity$", ConversionCapacity(PoolTier0Capacity))
Call oInst.AddProperty("$MPElement[Name='Huawei.ISM.Management.Pack.huawei.Class.StoragePool']/poolTier1Capacity$", ConversionCapacity(PoolTier1Capacity))
Call oInst.AddProperty("$MPElement[Name='Huawei.ISM.Management.Pack.huawei.Class.StoragePool']/poolTier2Capacity$", ConversionCapacity(PoolTier2Capacity))
Call oInst.AddProperty("$MPElement[Name='Huawei.ISM.Management.Pack.huawei.Class.StoragePool']/poolRelocationTriggerMode$", ConvertTriggerModel(PoolRelocationTriggerMode))
Call oDiscoveryData.AddInstance(oInst)
Function ConvertTriggerModel(model)
select case model
case 1
ConvertTriggerModel = "Schedule"
case 2
ConvertTriggerModel = "Manual"
case Else
ConvertTriggerModel = model
end select
End Function
Function ConversionStatus(status)
select case status
case 0
ConversionStatus = "--"
case 1
ConversionStatus = "Normal"
case 2
ConversionStatus = "Fault"
case 3
ConversionStatus = "Pre-Fail"
case 4
ConversionStatus = "Partially broken"
case Else
ConversionStatus = status
end select
End Function
Function ConversionCapacity(capacity)
On Error Resume Next
If capacity >= 1048576 Then
ConversionCapacity = Round(capacity / 1048576 , 3) & " TB"
ElseIf capacity >= 1024 Then
ConversionCapacity = Round(capacity / 1024,3) & " GB"
Else
ConversionCapacity = Round(capacity / 1,3) & " MB"
End If
If Err.Number <> 0 Then
If isOpen = 0 Then
OpenLogFile()
End IF
logMessage = "ERROR : Script -LUN Capacity Conversion error.cpacity:" & capacity
MOMDebugLog 1, logMessage
End If
Err.Clear
End Function
'形式类如code=E7-0x-0x93-0x9C-0xE7-0x93-0x9C-0x5F-0x30-0x30-0x39
Public Function UTF8BadDecode(ByVal code)
If code = "" Then
UTF8BadDecode = ""
Exit Function
End If
Dim tmp
Dim decodeStr
Dim codelen
Dim leftStr
Dim result
Dim str
str = code
result = ""
On Error Resume Next
code = Trim(code)
'将字符串中的 “-0x”替换为“.”
code = Replace(code, "-0x", ".")
'获取左边的第一个字符
leftStr = Left(code, 1)
If leftStr = "" Then
UTF8BadDecode = ""
Exit Function
ElseIf leftStr <> "." Then
result = str
ElseIf leftStr = "." Then
codelen = Len(code)
If (Mid(code, 2, 1) = "C" Or Mid(code, 2, 1) = "B") Then
decodeStr = Replace(Mid(code, 1, 6), ".", "")
tmp = c10ton(CLng("&H" & Hex(CLng("&H" & decodeStr) And &H1F3F)), 2)
tmp = String(16 - Len(tmp), "0") & tmp
result = result & ChrW(CLng("&H" & c2to16(Mid(tmp, 3, 4)) & c2to16(Mid(tmp, 7, 2) & Mid(tmp, 11, 2)) & Right(decodeStr, 1))) & UTF8BadDecode(Right(code, codelen - 6))
ElseIf (Mid(code, 2, 1) = "E") Then
decodeStr = Replace(Mid(code, 1, 9), ".", "")
tmp = c10ton((CLng("&H" & Mid(Hex(CLng("&H" & decodeStr) And &HF3F3F), 2, 3))), 2)
tmp = String(10 - Len(tmp), "0") & tmp
result = result & ChrW(CLng("&H" & (Mid(decodeStr, 2, 1) & c2to16(Mid(tmp, 1, 4)) & c2to16(Mid(tmp, 5, 2) & Right(tmp, 2)) & Right(decodeStr, 1)))) & UTF8BadDecode(Right(code, codelen - 9))
Else
result = Chr(CLng("&H" & (Mid(code, 2, 2)))) & UTF8BadDecode(Right(code, codelen - 3))
End If
End If
If Err.Number <> 0 Then
result = str
If isOpen = 0 Then
OpenLogFile()
End IF
logMessage = "ERROR : Script -Hexadecimal string parsing error.code:" & str
MOMDebugLog 1, logMessage
End If
Err.Clear
UTF8BadDecode = result
End Function
'二进制代码转换为十六进制代码
Public Function c2to16(ByVal x)
On Error Resume Next
Dim i, strinfo
i = 1
strinfo = ""
For i = 1 To Len(x) Step 4
strinfo = strinfo & Hex(c2to10(Mid(x, i, 4)))
Next
c2to16 = strinfo
If Err.Number <> 0 Then
If isOpen = 0 Then
OpenLogFile()
End IF
logMessage = "ERROR : Script -Binary code into hex code error.code:" & x
MOMDebugLog 1, logMessage
End If
Err.Clear
End Function
'二进制代码转换为十进制代码
Public Function c2to10(ByVal x)
On Error Resume Next
c2to10 = 0
If x = "0" Then Exit Function
Dim i
i = 0
For i = 0 To Len(x) - 1
If Mid(x, Len(x) - i, 1) = "1" Then c2to10 = c2to10 + 2 ^ (i)
Next
If Err.Number <> 0 Then
If isOpen = 0 Then
OpenLogFile()
End IF
logMessage = "ERROR : Script -Binary to decimal code error.code:" & x
MOMDebugLog 1, logMessage
End If
Err.Clear
End Function
'10进制转n进制(默认2)
Public Function c10ton(ByVal x, ByVal n)
On Error Resume Next
Dim i
i = x \ n
If i > 0 Then
If x Mod n > 10 Then
c10ton = c10ton(i, n) + Chr(x Mod n + 55)
Else
c10ton = c10ton(i, n) + CStr(x Mod n)
End If
Else
If x > 10 Then
c10ton = Chr(x + 55)
Else
c10ton = CStr(x)
End If
End If
If Err.Number <> 0 Then
If isOpen = 0 Then
OpenLogFile()
End IF
logMessage = "ERROR : Script -Decimal code into binary code error.code:" & x
MOMDebugLog 1, logMessage
End If
Err.Clear
End Function
Function ConversionRunningStatus(status)
select case status
case 0
ConversionRunningStatus = "--"
case 1
ConversionRunningStatus = "Normal"
case 2
ConversionRunningStatus = "Running"
case 3
ConversionRunningStatus = "Not running"
case 4
ConversionRunningStatus = "Not existed"
case 5
ConversionRunningStatus = "Sleep in high temperature"
case 6
ConversionRunningStatus = "Starting"
case 7
ConversionRunningStatus = "Power failure protection"
case 8
ConversionRunningStatus = "Spin down"
case 9
ConversionRunningStatus = "Started"
case 10
ConversionRunningStatus = "Link Up"
case 11
ConversionRunningStatus = "Link Down"
case 12
ConversionRunningStatus = "Powering on"
case 13
ConversionRunningStatus = "Powered off"
case 14
ConversionRunningStatus = "Precopy"
case 15
ConversionRunningStatus = "Copyback"
case 16
ConversionRunningStatus = "Reconstruction"
case 17
ConversionRunningStatus = "Expansion"
case 18
ConversionRunningStatus = "Unformatted"
case 19
ConversionRunningStatus = "Formatting"
case 20
ConversionRunningStatus = "Unmapped"
case 21
ConversionRunningStatus = "Initial synchronizing"
case 22
ConversionRunningStatus = "Consistent"
case 23
ConversionRunningStatus = "Synchronizing"
case 24
ConversionRunningStatus = "Synchronized"
case 25
ConversionRunningStatus = "Unsynchronized"
case 26
ConversionRunningStatus = "Splited"
case 27
ConversionRunningStatus = "Online"
case 28
ConversionRunningStatus = "Offline"
case 29
ConversionRunningStatus = "Locked"
case 30
ConversionRunningStatus = "Enabled"
case 31
ConversionRunningStatus = "Disabled"
case 32
ConversionRunningStatus = "balancing"
case 33
ConversionRunningStatus = "To be recovered"
case 34
ConversionRunningStatus = "Interrupted"
case 35
ConversionRunningStatus = "Invalid"
case 36
ConversionRunningStatus = "Not start"
case 37
ConversionRunningStatus = "Queuing"
case 38
ConversionRunningStatus = "Stopped"
case 39
ConversionRunningStatus = "Copying"
case 40
ConversionRunningStatus = "Completed"
case 41
ConversionRunningStatus = "Paused"
case 42
ConversionRunningStatus = "Reverse synchronizing"
case 43
ConversionRunningStatus = "Activated"
case 44
ConversionRunningStatus = "Restore"
case 45
ConversionRunningStatus = "Inactive"
case 46
ConversionRunningStatus = "Idle"
case 47
ConversionRunningStatus = "Powering off"
case Else
ConversionRunningStatus = status
end select
End Function