'**********************************************************************************
' Script Name - Huawei Host Properites Discovery
' Author: Muralidhar L, Vignesh Pandian
'
' Description:
' Discovery of Huawei Host 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 > 8 Then
Call oAPI.LogScriptEvent("DiscoverHostProperites.vbs",101,0, _
"script was called with fewer than three arguments and was not executed.")
Wscript.Quit -1
End If
' 取得入参
Dim SourceID, ManagedEntityID, deviceKey, deviceIp
Dim hostID, hostName, hostOs, hostIP
Public Function OS(system)
select Case system
Case 0
OS="Linux"
Case 1
OS="Windows"
Case 2
OS="Solaris"
Case 3
OS="HP-UX"
Case 4
OS="AIX"
Case 5
OS="enServer"
Case 6
OS="Mac OS"
Case 7
OS="VMware ESX"
Case 8
OS="Linux"
Case 9
OS="Windows Server 2012"
Case Else
OS=""
End select
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
Call oAPI.Return(oDiscoveryData)