Dim fileSize, strOutFile
Const strFileName = "DellDiscovery_Sensor.log"
Const ForAppending = 8
Const ForWriting = 2
Const MaxFileSize = 524288 'File Size is limited to 512 KB
dim wsShell : Set wsShell = Createobject("WScript.Shell")
dim wshSysEnv : Set wshSysEnv = wsShell.Environment
dim tFolder : tFolder = wshSysEnv("TEMP")
dim wshPrcEnv : Set wshPrcEnv = wsShell.Environment("Process")
tFolder = Replace(tFolder, "%SystemRoot%", wshPrcEnv("SYSTEMROOT"), 1, -1, vbTextCompare)
Set objLogFSO = CreateObject("Scripting.FileSystemObject")
If Not objLogFSO.FolderExists(tFolder) Then
objLogFSO.CreateFolder(tFolder)
End If
strOutFile = tFolder & "\"& strFileName
WScript.Echo strOutFile
If Not objLogFSO.FileExists(strOutFile) Then
Set objLogTextFile = objLogFSO.CreateTextFile(strOutFile)
objLogTextFile.Close()
End If
fileSize = objLogFSO.GetFile(strOutFile).Size
If (fileSize > MaxFileSize) Then
Set objLogTextFile = objLogFSO.OpentextFile(strOutFile, ForWriting, True)
Else
Set objLogTextFile = objLogFSO.OpentextFile(strOutFile, ForAppending, True)
End If
MOMDebugLog 1, "------------------------------------------------------"
MOMDebugLog 1, "INFO: Script - Dell Server Sensor Detailed Discovery Start()"
Err.Clear
End If
Sub MOMDebugLog (ByVal debugLevel, ByVal Message)
On Error Resume Next
If (debugLevel > 0) and (debugLevel <= logLevel) Then
objLogTextFile.WriteLine(Now() & " ---- " & Message)
Err.Clear
End If
End Sub
Dim oAPI, oDiscoveryData, oInst, strComputer, objDellConnection
Set oAPI = CreateObject("MOM.ScriptAPI")
set oDiscoveryData = oAPI.CreateDiscoveryData(0, sourceId, managedEntityId)
strComputer = "."
set objDellConnection = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2\Dell")
If IsEmpty(objDellConnection) Or (Err.Number <> 0) Then
logMessage = "Unable to open WMI Namespace root-cimv2-dell. Check to see if the WMI service is enabled and running, and Install/Re-Install ServerAdministrator to ensure this WMI namespace exists. " & Err
MOMDebugLog 1, logMessage
Else
DiscoverSensors()
End If
' Submit the data
Call oAPI.Return(oDiscoveryData)
Set oDiscoveryData = Nothing
Set oAPI = Nothing
Set objDellConnection = Nothing
' Close file used for logs
If logLevel <> 0 Then
objLogTextFile.Close
Set objLogTextFile = Nothing
Set objLogFSO = Nothing
End If
'*************************************************************************
' Function : DiscoverSensors()
' Desc : To discover Sensor instances using CIM
' Arguments : Nothing
'*************************************************************************
Function DiscoverSensors()
On Error resume next
Dim sQuery, colItems, objItem, objItemSensor
Dim elementName, sensorType, deviceId, SecurityBreach
Dim FanSensorGroupFlag, CurrentSensorGroupFlag, VoltageSensorGroupFlag, BatterySensorGroupFlag, TemperatureSensorGroupFlag
sQuery = "Select * from CIM_Sensor"
Set colItems = GetObjectSet(objDellConnection, sQuery, "Name", "CIM_Sensor")
If Err.Number <> 0 Then
If Err.Number = -2147023169 Then
End If
Err.Clear
End If
If (colItems is Nothing) or (IsNull(colItems)) Then
Err.Clear
Else
For Each objItemSensor in colItems
'Error checking
If Err.Number <> 0 Then
Err.Clear
End If
'Object Retrieval
If not objItemSensor is nothing Then
FanSensorGroupFlag = True
CurrentSensorGroupFlag = True
VoltageSensorGroupFlag = True
BatterySensorGroupFlag = True
TemperatureSensorGroupFlag = True
If sensorType = 4 Then
If Not IsNull(elementName) Then
If CurrentSensorGroupFlag = True Then
set oInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='Dell.WindowsServer.CurrentSensorGroup']$")
call oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", targetComputer)
call oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.LogicalDevice']/DeviceID$", targetComputer)
call oInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "CurrentSensorGroup")
call oDiscoveryData.AddInstance(oInst)
CurrentSensorGroupFlag = False
logMessage = "Current Sensor Group created"
MOMDebugLog 1, logMessage
End If
logMessage = "Current Sensor discovered with Name: " & elementName
MOMDebugLog 1, logMessage
End If
ElseIf sensorType = 5 Then
If Not IsNull(elementName) Then
If FanSensorGroupFlag = True Then
set oInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='Dell.WindowsServer.FanSensorGroup']$")
call oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", targetComputer)
call oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.LogicalDevice']/DeviceID$", targetComputer)
call oInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "FanSensorGroup")
call oDiscoveryData.AddInstance(oInst)
FanSensorGroupFlag = False
logMessage = "Fan Sensor Group created"
MOMDebugLog 1, logMessage
End If
set oInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='Dell.WindowsServer.FanSensor']$")
call oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", targetComputer)
call oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.LogicalDevice']/DeviceID$", targetComputer)
call oInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", elementName)
call oInst.AddProperty("$MPElement[Name='Dell.WindowsServer.FanSensor']/DeviceID$", "FanSensor-" & deviceId)
call oInst.AddProperty("$MPElement[Name='Dell.WindowsServer.FanSensor']/ElementName$", elementName)
call oDiscoveryData.AddInstance(oInst)
logMessage = "Fan Sensor discovered with Name: " & elementName
MOMDebugLog 1, logMessage
End If
ElseIf sensorType = 3 Then
If Not IsNull(elementName) Then
If VoltageSensorGroupFlag = True Then
set oInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='Dell.WindowsServer.VoltageSensorGroup']$")
call oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", targetComputer)
call oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.LogicalDevice']/DeviceID$", targetComputer)
call oInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "VoltageSensorGroup")
call oDiscoveryData.AddInstance(oInst)
VoltageSensorGroupFlag = False
logMessage = "Voltage Sensor Group created"
MOMDebugLog 1, logMessage
End If
set oInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='Dell.WindowsServer.VoltageSensor']$")
call oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", targetComputer)
call oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.LogicalDevice']/DeviceID$", targetComputer)
call oInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", elementName)
call oInst.AddProperty("$MPElement[Name='Dell.WindowsServer.VoltageSensor']/DeviceID$", "VoltageSensor-" & deviceId)
call oInst.AddProperty("$MPElement[Name='Dell.WindowsServer.VoltageSensor']/ElementName$", elementName)
call oDiscoveryData.AddInstance(oInst)
logMessage = "Voltage Sensor discovered with Name: " & elementName
MOMDebugLog 1, logMessage
End If
ElseIf sensorType = 13 Then
If Not IsNull(elementName) Then
If BatterySensorGroupFlag = True Then
set oInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='Dell.WindowsServer.BatterySensorGroup']$")
call oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", targetComputer)
call oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.LogicalDevice']/DeviceID$", targetComputer)
call oInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "BatterySensorGroup")
call oDiscoveryData.AddInstance(oInst)
BatterySensorGroupFlag = False
logMessage = "Battery Sensor Group created"
MOMDebugLog 1, logMessage
End If
set oInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='Dell.WindowsServer.BatterySensor']$")
call oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", targetComputer)
call oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.LogicalDevice']/DeviceID$", targetComputer)
call oInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", elementName)
call oInst.AddProperty("$MPElement[Name='Dell.WindowsServer.BatterySensor']/DeviceID$", "BatterySensor-" & deviceId)
call oInst.AddProperty("$MPElement[Name='Dell.WindowsServer.BatterySensor']/ElementName$", elementName)
call oDiscoveryData.AddInstance(oInst)
logMessage = "Battery Sensor discovered with Name: " & elementName
MOMDebugLog 1, logMessage
End If
ElseIf sensorType = 2 Then
If Not IsNull(elementName) Then
If TemperatureSensorGroupFlag = True Then
set oInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='Dell.WindowsServer.TemperatureSensorGroup']$")
call oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", targetComputer)
call oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.LogicalDevice']/DeviceID$", targetComputer)
call oInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "TemperatureSensorGroup")
call oDiscoveryData.AddInstance(oInst)
TemperatureSensorGroupFlag = False
logMessage = "Temperature Sensor Group created"
MOMDebugLog 1, logMessage
End If
set oInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='Dell.WindowsServer.TemperatureSensor']$")
call oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", targetComputer)
call oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.LogicalDevice']/DeviceID$", targetComputer)
call oInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", elementName)
call oInst.AddProperty("$MPElement[Name='Dell.WindowsServer.TemperatureSensor']/DeviceID$", "TemperatureSensor-" & deviceId)
call oInst.AddProperty("$MPElement[Name='Dell.WindowsServer.TemperatureSensor']/ElementName$", elementName)
call oDiscoveryData.AddInstance(oInst)
logMessage = "Temperature Sensor discovered with Name: " & elementName
MOMDebugLog 1, logMessage
End If
End If
End If
Next
End If
sQuery = "Select * from CIM_PhysicalFrame"
Set colItems = GetObjectSet(objDellConnection, sQuery, "Name", "CIM_PhysicalFrame")
If Err.Number <> 0 Then
If Err.Number = -2147023169 Then
End If
Err.Clear
End If
If (colItems is Nothing) or (IsNull(colItems)) Then
Err.Clear
Else
For Each objItemSensor in colItems
'Error checking
If Err.Number <> 0 Then
Err.Clear
End If
'Object Retrieval
If not objItemSensor is nothing Then
SecurityBreach = objItemSensor.SecurityBreach
If Not IsNull(SecurityBreach) Then
If SecurityBreach <> 2 Then ' Status 2 indicates the unknown status of chassis intrusion sensor
set oInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='Dell.WindowsServer.ChassisIntrusionSensor']$")
call oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", targetComputer)
call oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.LogicalDevice']/DeviceID$", targetComputer)
call oInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "Chassis Intrusion Sensor")
call oInst.AddProperty("$MPElement[Name='Dell.WindowsServer.ChassisIntrusionSensor']/DeviceID$", "Chassis Intrusion Sensor")
call oInst.AddProperty("$MPElement[Name='Dell.WindowsServer.ChassisIntrusionSensor']/ElementName$", "Chassis Intrusion Sensor")
call oDiscoveryData.AddInstance(oInst)
logMessage = "Chassis Intrusion Sensor discovered"
MOMDebugLog 1, logMessage
End If
End If
End If
Next
End If
Set colItems = Nothing
End Function
'**************************************
' Function to retrieve the object
'**************************************
Function GetObjectSet(ByRef objDellConnection, SelectQuery, Attributes, objName)
Dim retry, retryFlag
Dim objItem, arrURL, logMessage
On Error Resume Next
RetryFlag = False
For retry = 0 To 1
MOMDebugLog 1, "Retrying for " & retry & " time..."
Set GetObjectSet = objDellConnection.ExecQuery(SelectQuery)
LogErrorNumber(objName)
If (GetObjectSet is Nothing) Or (IsNull(GetObjectSet)) Then
logMessage = "INFO: Unable to retrieve " & objName & " Attributes"
MOMDebugLog 1, logMessage
WScript.Sleep(1000)
RetryFlag = True
Else
logMessage= "INFO: " & objName & " attributes retrieved successfully"
MOMDebugLog 1, logMessage
If Attributes = "__COUNT__" Then
Exit For
End If
For Each objItem in GetObjectSet
If LogErrorNumber(objName) = 0 Then
If Not objItem is nothing Then
Dim attrVal : attrVal = objItem.Properties_.Item(Attributes)
If IsNull(attrVal) Or Len(attrVal) <= 0 Then
MOMDebugLog 1, Attributes & " value is null or empty"
RetryFlag = True
WScript.Sleep(500)
Exit For
Else
Exit Function
End If
End If
End If
Next
If RetryFlag = False Then
Exit For
End If
End If
Next
End Function
Function LogErrorNumber(objName)
Dim logMessage
LogErrorNumber = Err.Number
If Err.Number <> 0 Then
Select Case Err.Number
Case -2147749904
logMessage = "CIM Object not found"
Case -2147749902
logMessage = "Dell CIM object not found"
Case -2147023169
logMessage = "RPC Failure occurred for namespace root-cimv2-dell"
Case -2147217389
logMessage = "Please Install/Re-Install ServerAdministrator on Dell Server!"
Case -2147217394 '0x8004100E
logMessage = "Not able to find Dell CIM object"
Case -2147217392 '0x8004100C
logMessage = "Not able to find the collection"
Case -2147749890
logMessage = "Object cannot be found"
Case -2147749892
logMessage = "Object cannot be found"
Case Else
logMessage = "Unable to retrieve " & objName
logMessage = logMessage & " Err Number:" & Err.Number
logMessage = logMessage & " Err Descr:" & Err.Description
End Select
MOMDebugLog 1, "ERROR: " & logMessage
End If
End Function </Script></ScriptBody>
<TimeoutSeconds>300</TimeoutSeconds>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DS"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>