################################################################################
# Main
################################################################################
# nice_base.env
if [ -f "${NICE_BASE_ENV}" ]; then
case ${ARCH} in
HP-UX)
case `uname -m` in
ia64) ARCH=hpia ;;
*) ARCH=hppa ;;
esac
;;
Linux)
case `uname -m` in
*86) ARCH=linux_x86 ;;
*86_64) ARCH=linux_x86_64 ;;
*s390x) ARCH=linux_s390x ;;
esac
;;
SunOS)
case `uname -m` in
sun*) ARCH=sol ;;
*86*) ARCH=sol_x86 ;;
esac
;;
AIX) ARCH=aix ;;
esac
if [ -f "/usr/bin/ksh" ]; then
echo "KSH_PATH=/usr/bin/ksh"
elif [ -f "/bin/ksh" ]; then
echo "KSH_PATH=/bin/ksh"
else
echo "KSH_PATH=n/a"
fi
fi</Script>
<Arguments/>
</ProbeAction>
<ProbeAction ID="DS2" TypeID="Windows!Microsoft.Windows.ScriptDiscoveryProbe">
<ScriptName>NiCELibraryComputerDiscovery.vbs</ScriptName>
<Arguments>"$Data[Default='']///*[local-name()='StdOut' or local-name()='ErrorCode']$" "$Data[Default='']///*[local-name()='StdErr' or local-name()='Message']$"</Arguments>
<ScriptBody><Script>'-------------------------------------------------------------------------------
'* VBScript Name: NiCELibraryComputerDiscovery.vbs
'* Description : Discover NiCEBinDirectory, NiCEDataDirectory, NiCEPerlDir
'-------------------------------------------------------------------------------
Option explicit
SetLocale("en-us")
Dim oAPI, SourceId, ManagedEntityId, oDiscoveryData, oDiscoveryInstance, oUnixDiscoveryInstance, oRelationshipInstance
Dim g_szComputerName, szValue, g_szBaseEnvLocation, g_bDiscoverRollup
Dim aData, szData
Dim Logger
'Start by setting up API object and creating a discovery data object.
Set oAPI = CreateObject("MOM.ScriptAPI")
'Setup variables sent by SCOM
SourceId = CStr("$MPElement$") 'GUID of discovery calling the script. Provided by the MPElement variable.
ManagedEntityId = CStr("$Target/Id$") 'GUID of target object. Provided by the Target/Id variable.
g_szComputerName = CStr("$Config/TargetSystem$")
g_szBaseEnvLocation = CStr("/var/opt/NiCE/conf/nice_base.env")
g_bDiscoverRollup = true
If InStr(1,"$Config/DiscoverRollup$","False", vbTextCompare) Then
g_bDiscoverRollup = false
End If
Set Logger = new NiCELogger.Init("","","$Config/Tracing$")
'******************************************************************
' MAIN
'******************************************************************
Dim FUNCTIONNAME : FUNCTIONNAME = "MAIN"
Set oDiscoveryData = oAPI.CreateDiscoveryData(0, SourceId, ManagedEntityId)
Call Logger.LogDebug(FUNCTIONNAME,"Script started with Arguments Count:" & WScript.Arguments.Count)
'Need to check arguments for all scripts.
If WScript.Arguments.Count > 0 then
Call Logger.LogDebug(FUNCTIONNAME,"Arguments(0):" & WScript.Arguments.Item(0))
If WScript.Arguments.Item(1) <> "" Then
Call Logger.LogError(FUNCTIONNAME,"The NiCE Library Computer Discovery for Computer '" & g_szComputerName & "' failed with error:" & VBCrLf & WScript.Arguments.Item(1))
ElseIf WScript.Arguments.Item(0) <> "" Then
Call Logger.LogDebug(FUNCTIONNAME,"Discovery for Computer: " & g_szComputerName)
Set oDiscoveryInstance = oDiscoveryData.CreateClassInstance("$MPElement[Name='NiCE.Library.X.Computer']$")
Call oDiscoveryInstance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", g_szComputerName)
Call oDiscoveryInstance.AddProperty("$MPElement[Name='Unix!Microsoft.Unix.Computer']/PrincipalName$", g_szComputerName)
Call oDiscoveryInstance.AddProperty("$MPElement[Name='NiCE.Library.X.Computer']/NiCEBaseEnvLocation$", g_szBaseEnvLocation)
aData = Split(WScript.Arguments.Item(0), "\n")
For Each szData in aData
If inStr(szData,"NICE_BIN_DIR=") > 0 Then
szData = Trim(szData)
szValue = Right(szData,Len(szData) - Len("NICE_BIN_DIR="))
Call Logger.LogDebug(FUNCTIONNAME,"NiCEBinDirectory: " & szValue)
Call oDiscoveryInstance.AddProperty("$MPElement[Name='NiCE.Library.X.Computer']/NiCEBinDirectory$", szValue)
End If
If inStr(szData,"NICE_DATA_DIR=") > 0 Then
szData = Trim(szData)
szValue = Right(szData,Len(szData) - Len("NICE_DATA_DIR="))
Call Logger.LogDebug(FUNCTIONNAME,"NiCEDataDirectory: " & szValue)
Call oDiscoveryInstance.AddProperty("$MPElement[Name='NiCE.Library.X.Computer']/NiCEDataDirectory$", szValue)
End If
If inStr(szData,"ARCH=") > 0 Then
szData = Trim(szData)
szValue = Right(szData,Len(szData) - Len("ARCH="))
Call Logger.LogDebug(FUNCTIONNAME,"Architecture: " & szValue)
Call oDiscoveryInstance.AddProperty("$MPElement[Name='NiCE.Library.X.Computer']/Architecture$", szValue)
End If
If inStr(szData,"KSH_PATH=") > 0 Then
szData = Trim(szData)
szValue = Right(szData,Len(szData) - Len("KSH_PATH="))
Call Logger.LogDebug(FUNCTIONNAME,"Ksh path: " & szValue)
Call oDiscoveryInstance.AddProperty("$MPElement[Name='NiCE.Library.X.Computer']/KshPath$", szValue)
End If
Next
If g_bDiscoverRollup Then
Set oUnixDiscoveryInstance = oDiscoveryData.CreateClassInstance("$MPElement[Name='NiCE.Library.Unix.Computer']$")
Call oUnixDiscoveryInstance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", g_szComputerName)
Call oUnixDiscoveryInstance.AddProperty("$MPElement[Name='Unix!Microsoft.Unix.Computer']/PrincipalName$", g_szComputerName)
Call oDiscoveryData.AddInstance(oUnixDiscoveryInstance)
Set oRelationshipInstance = oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='NiCE.Library.X.Unix.Computer.Contains.NiCE.LocalApplication']$")
oRelationshipInstance.Source = oUnixDiscoveryInstance
oRelationshipInstance.Target = oDiscoveryInstance
Call oDiscoveryData.AddInstance(oRelationshipInstance)
End If
End If
End If
'And now we just return the discovery data
Call oAPI.Return(oDiscoveryData)
'==================================================================================
' Class: NiCELogger
' Usage: Set Logger = new NiCELogger.Init("NiCEDataDirectory","ProductName","Tracing")
' Set Logger = new NiCELogger.Init("","","Tracing")
' Call Logger.LogDebug("funcname","message")
' Call Logger.LogError("funcname","message")
' Call Logger.LogWarning("funcname","message")
'==================================================================================
Class NiCELogger
Private m_TracingEnabled
Private m_ProductName
Private m_NiCEDataDirectory
Private m_LogDirectory
Private m_ConfDirectory
Private m_LogFileName
Private m_objFSO
Private m_WshShell
Private m_oAPI
'==================================================================================
' Property: TracingEnabled
' Returns: true or false
'==================================================================================
Public Property Get TracingEnabled
TracingEnabled = m_TracingEnabled
End Property
Public Default Function Init(NiCEDataDirectory, ProductName, Tracing)
Set m_objFSO = CreateObject("Scripting.FileSystemObject")
Set m_oAPI = CreateObject("MOM.ScriptAPI")
Set m_WshShell = WScript.CreateObject("WScript.Shell")
m_TracingEnabled = false
If InStr(1,Tracing,"True", vbTextCompare) Then
m_TracingEnabled = true
End If
m_LogFileName = Replace(WScript.ScriptName,".vbs","_Trace.log")
m_NiCEDataDirectory = RemoveSlash(CStr(NiCEDataDirectory))
m_ProductName = CStr(ProductName)
if m_ProductName <> "" And m_NiCEDataDirectory <> "" Then
m_LogDirectory = m_NiCEDataDirectory & "\log\" & m_ProductName & "\"
m_ConfDirectory = m_NiCEDataDirectory & "\conf\" & m_ProductName & "\"
Else
m_LogDirectory = RemoveSlash(m_WshShell.ExpandEnvironmentStrings("%temp%")) & "\"
m_ConfDirectory = RemoveSlash(m_WshShell.ExpandEnvironmentStrings("%temp%")) & "\"
End If
Call InitSpiCfg()
Set Init = Me
End Function
Private Sub InitSpiCfg()
Dim FUNCTIONNAME : FUNCTIONNAME = "NiCELogger::InitSpiCfg"
If m_TracingEnabled = false Then
Dim SpiCfgobjFile, SpiCfgFile, szSpiCfgLine
Dim TraceEnabled : TraceEnabled = false
Dim TraceProcess : TraceProcess = false
Dim SpiCfgPath : SpiCfgPath = m_ConfDirectory & m_ProductName & "_spi.cfg"
If not m_objFSO.FileExists(SpiCfgPath) Then
Dim temppath : temppath = RemoveSlash(m_WshShell.Environment("System")("TEMP"))
SpiCfgPath = temppath & "\" & m_ProductName & "_spi.cfg"
m_LogDirectory = temppath & "\"
m_ConfDirectory = temppath & "\"
End If
If m_objFSO.FileExists(SpiCfgPath) Then
Set SpiCfgobjFile = m_objFSO.GetFile(SpiCfgPath)
If SpiCfgobjFile.Size > 0 Then
Set SpiCfgFile = m_objFSO.OpenTextFile(SpiCfgPath,1)
Do While SpiCfgFile.AtEndOfStream <> True
szSpiCfgLine = SpiCfgFile.ReadLine
If InStr(1,szSpiCfgLine,"SPI_TRACE_STATUS", vbTextCompare) and InStr(1,szSpiCfgLine,"ON", vbTextCompare) Then
TraceEnabled = true
End If
If InStr(1,szSpiCfgLine,"SPI_TRACE_PROCESS", vbTextCompare) and (InStr(1,szSpiCfgLine,"ALL", vbTextCompare) or InStr(1,szSpiCfgLine,WScript.ScriptName, vbTextCompare)) Then
TraceProcess = true
End If
Loop
End If
End If
If TraceEnabled = true and TraceProcess = true Then
m_TracingEnabled = true
End If
End If
End Sub
'==================================================================================
' Sub: LogError
' Purpose: Logs an error event to the operations manager event log
'==================================================================================
Public Sub LogError(FUNCTIONNAME, szMessage)
Call LogEvent(FUNCTIONNAME,6121,1,szMessage)
Call LogDebugInternal(FUNCTIONNAME, "ERROR", szMessage)
End Sub
'==================================================================================
' Sub: LogWarning
' Purpose: Logs a warning event to the operations manager event log
'==================================================================================
Public Sub LogWarning(FUNCTIONNAME, szMessage)
Call LogEvent(FUNCTIONNAME,6122,2,szMessage)
Call LogDebugInternal(FUNCTIONNAME, "WARNING", szMessage)
End Sub
'==================================================================================
' Sub: LogInfo
' Purpose: Logs an info event to the operations manager event log
'==================================================================================
Public Sub LogInfo(FUNCTIONNAME, szMessage)
Call LogEvent(FUNCTIONNAME,6123,4,szMessage)
Call LogDebugInternal(FUNCTIONNAME, "INFO", szMessage)
End Sub
'==================================================================================
' Sub: LogDebug
' Purpose: Logs a debug message in the log file
'==================================================================================
Public Sub LogDebug(FUNCTIONNAME, szMessage)
Call LogDebugInternal(FUNCTIONNAME, "DEBUG", szMessage)
End Sub
Private Sub LogDebugInternal(FUNCTIONNAME, szServerity, szMessage)
If m_TracingEnabled = True Then
Dim LogFile
szMessage = Now & " - " & szServerity & " - " & FUNCTIONNAME & " - " & szMessage
If not m_objFSO.FolderExists(m_LogDirectory) then
CreateFolders(m_LogDirectory)
End If
If m_objFSO.FileExists(m_LogDirectory & m_LogFileName) Then
Set LogFile = m_objFSO.OpenTextFile(m_LogDirectory & m_LogFileName,8)
Call LogFile.WriteLine(szMessage)
Else
Set LogFile = m_objFSO.CreateTextFile(m_LogDirectory & m_LogFileName,true)
Call LogFile.WriteLine(szMessage)
End If
End If
End Sub
'==================================================================================
' Sub: LogEvent
' Purpose: Logs an event to the Operations Manager event log
'==================================================================================
Private Sub LogEvent(FUNCTIONNAME,EventNumber, EventLevel, szMessage)
szMessage = FUNCTIONNAME & VbCrLf & szMessage
Dim nLength, nNum, nStart, szNewMessage, i
nLength = Len(szMessage) / 30000
nNum = CInt(nLength + 0.5)
If nNum > 1 Then ' we have more than 30000 chars, split them into multiple parts'
For i = 0 to nNum-1
szNewMessage = "Part " & i+1 & "/" & nNum & VbCrLf
nStart = 1+(i*30000)
szNewMessage = szNewMessage & Mid(szMessage, nStart, 30000)
Call m_oAPI.LogScriptEvent(WScript.ScriptName, EventNumber, EventLevel, szNewMessage)
Next
Else
Call m_oAPI.LogScriptEvent(WScript.ScriptName, EventNumber, EventLevel, szMessage)
End If
End Sub
'==================================================================================
' Function: RemoveSlash
' Purpose: removes the last char of a string if it a forward or backward slash
'==================================================================================
Public Function RemoveSlash(Path)
Dim szLastChar
szLastChar = Right(Path,1)
If szLastChar = "\" OR szLastChar = "/" Then
removeSlash = Left(Path,Len(Path)-1)
Else
removeSlash = Path
End If
End Function
Public Sub CreateFolders(Path)
Dim FolderArray : FolderArray = Split(Path, "\")
Dim Folder,i
For i=0 to UBound(FolderArray)
If i <> 0 Then
Folder = FolderArray(i-1)
End If
Folder = Folder & FolderArray(i) & "\"
If not m_objFSO.FolderExists(Folder) Then
m_objFSO.CreateFolder(Folder)
End If