Services discovery data source

Dell.WindowsClient.ClientServicesDiscovery (DataSourceModuleType)

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
OutputTypeSystem.Discovery.Data

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource Microsoft.Windows.TimedScript.DiscoveryProvider Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$Interval SecondsInterval Seconds
LogLevelint$Config/LogLevel$Log LevelLog Level

Source Code:

<DataSourceModuleType ID="Dell.WindowsClient.ClientServicesDiscovery" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element name="IntervalSeconds" type="xsd:integer"/>
<xsd:element name="Computer" type="xsd:string"/>
<xsd:element name="LogLevel" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="LogLevel" Selector="$Config/LogLevel$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedScript.DiscoveryProvider">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<SyncTime/>
<ScriptName>ClientServicesDiscovery.vbs</ScriptName>
<Arguments>$MPElement$ $Target/Id$ $Config/Computer$ $Config/LogLevel$</Arguments>
<ScriptBody><Script>

'*******************************************************************************
' Script Name - Dell Client Services Discovery
' Author: Muralidhar, Kathiresan.R.S
'
' Description:
' Discover Dell Client OMCI / Dell Command | Monitor Services
'
' (c) Copyright Dell Inc. 2007-2012 All rights reserved
'*******************************************************************************

Option Explicit
On Error Resume Next
Const DebugScript = False
SetLocale("en-us")
Dim oArgs
Set oArgs = WScript.Arguments
if oArgs.Count &lt; 4 Then
Wscript.Quit -1
End If

Dim sourceID, managedEntityId, targetComputer
Dim omciServicesFlag, dcmServicesFlag
Dim iapServiceDispName, iapServiceDesc, iapServiceStartMode, iapSvcName
Dim objLogFSO, objLogTextFile, logMessage, debugLevel, logLevel

sourceID = oArgs(0)
managedEntityId = oArgs(1)
targetComputer = oArgs(2)
logLevel = oArgs(3)

Dim oAPI, oDiscoveryData, oInst
Set oAPI = CreateMOMScriptAPI()
set oDiscoveryData = CreateDiscoveryData(oAPI, sourceID, managedEntityId)

' Begin Logheader
If logLevel &lt;&gt; 0 Then
Dim fileSize, strOutFile
Const strFileName = "Discovery_DellWindowsClientServices.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 &amp; "\"&amp; strFileName
If Not objLogFSO.FileExists(strOutFile) Then
Set objLogTextFile = objLogFSO.CreateTextFile(strOutFile)
objLogTextFile.Close()
End If
fileSize = objLogFSO.GetFile(strOutFile).Size
If (fileSize &gt; MaxFileSize) Then
Set objLogTextFile = objLogFSO.OpentextFile(strOutFile, ForWriting, True)
Else
Set objLogTextFile = objLogFSO.OpentextFile(strOutFile, ForAppending, True)
End If
logMessage = "INFO: Script - Dell Client Discovery : Start()"
MOMDebugLog 1, logMessage
Err.Clear
End If

Sub MOMDebugLog (ByVal debugLevel, ByVal Message)
On Error Resume Next
DebugOut Message
If (debugLevel &gt; 0) and (debugLevel &lt;= logLevel) Then
objLogTextFile.WriteLine(Now() &amp; " ---- " &amp; Message)
Err.Clear
End If
End Sub
' End of Logheader
getOMCIServiceType()
getOMCIServices()

Function getOMCIServiceType()
Dim omciVersion,b
omciVersion = ""
Dim objRegistry, Key
Set objRegistry = CreateObject("Wscript.shell")
omciVersion = objRegistry.RegRead("HKLM\Software\Dell Computer Corporation\OpenManage\Applications\Client\Version")
logMessage = "OMCI / Dell Command | Monitor after reading registry "
MOMDebugLog 1, logMessage

b = split(omciVersion, ".")
If (b(0) &gt; 8) Then
'if version number is 9 or above, It should be shown as DCM
dcmServicesFlag = 1
End If
End Function

If omciServicesFlag=1 Then
logMessage = " Creating Service with display name : OMCI / Dell Command | Monitor Service"
MOMDebugLog 1, logMessage

'attribute value checking for empty string, if so set as "Not Available"
AttributeValueCheck iapServiceDesc
AttributeValueCheck iapServiceStartMode
AttributeValueCheck iapSvcName

set oInst = CreateClassInstance(oDiscoveryData, "$MPElement[Name='Dell.WindowsClient.IAPService']$")
call oInstAddProperty(oInst, "$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", targetComputer)
call oInstAddProperty(oInst, "$MPElement[Name='Windows!Microsoft.Windows.LogicalDevice']/DeviceID$", targetComputer)
If dcmServicesFlag=1 Then
call oInstAddProperty(oInst, "$MPElement[Name='System!System.Entity']/DisplayName$", "Dell Command | Monitor")
call oInstAddProperty(oInst, "$MPElement[Name='Dell.WindowsClient.IAPService']/Description$", "Dell Command | Monitor")
Else
call oInstAddProperty(oInst, "$MPElement[Name='System!System.Entity']/DisplayName$", "OMCI Service")
call oInstAddProperty(oInst, "$MPElement[Name='Dell.WindowsClient.IAPService']/Description$", iapServiceDesc)
End If
call oInstAddProperty(oInst, "$MPElement[Name='Dell.WindowsClient.IAPService']/StartMode$", iapServiceStartMode)
call oInstAddProperty(oInst, "$MPElement[Name='Dell.WindowsClient.IAPService']/ServiceName$", iapSvcName)
call AddInstanceToDiscoveryData(oDiscoveryData, oInst)

logMessage = " Created Service with display name : OMCI / Dell Command | Monitor"
MOMDebugLog 1, logMessage
End If

' Submit the data
Call ReturnDiscoveryData (oAPI, oDiscoveryData)

Set oDiscoveryData = Nothing
Set oAPI = Nothing
Set oInst = Nothing

' Close file used for logs
If logLevel &lt;&gt; 0 Then
objLogTextFile.Close
Set objLogTextFile = Nothing
Set objLogFSO = Nothing
End If

Function getOMCIServices
Dim strComputer, wbemServices, wbemObjectSet, wbemObject, sQuery, OMServicesFlag
strComputer="."

Set wbemServices = GetObject("winmgmts:" &amp; "{impersonationLevel=impersonate}!\\" &amp; strComputer &amp; "\root\cimv2")
If IsEmpty(wbemServices) Then
logMessage = "Unable to open WMI Namespace root-cimv2. Check to see if the WMI service is enabled and running, and ensure this WMI namespace exists." &amp; Err.Description
MOMDebugLog 1, logMessage
Else
sQuery = "SELECT * FROM Win32_Service WHERE ( Name = 'Iap' or Name ='dcstor32' or Name = 'dcstor64')"
Set wbemObjectSet = wbemServices.ExecQuery(sQuery)
If IsEmpty(wbemObjectSet) Or Err.Number &lt;&gt; 0 Then
logMessage = "The Query '" &amp; sQuery &amp; "' returned an invalid result set. Please check to see if this is a valid WMI Query." &amp; Err.Description
MOMDebugLog 1, logMessage
Err.Clear
Else
For Each wbemObject In wbemObjectSet
If Err.Number &lt;&gt; 0 Then
logMessage = "Win32_Service SubObjectQuery Error Number:" &amp; Err.Number &amp; "Description:" &amp; Err.Description
MOMDebugLog 1, logMessage
Err.Clear
End If
omciServicesFlag = 1
iapServiceDispName = GetStringValue(wbemObject.DisplayName)
iapServiceDesc = "OpenManage Client Instrumentation Services"
iapServiceStartMode = GetStringValue(wbemObject.StartMode)
iapSvcName = GetStringValue(wbemObject.Name)
Next
End If
Set wbemObjectSet = Nothing
Set wbemObject = Nothing
End If
End Function

Function GetStringValue(Byval input)
Dim stringValue
If IsNull(input) Then
stringValue = ""
Else
stringValue = input
End If

GetStringValue = stringValue
End Function

'*************************************************************************
' Function : AttributeValueCheck()
' Desc : To replace empty string with Not Available string
' Arguments : pass ByReference Attribute
'*************************************************************************
Public Function AttributeValueCheck(ByRef Attribute)
On Error Resume Next
SetLocale("en-us")
Attribute= trim(Attribute)
if Attribute = "" Then
Attribute = "Not Available"
End if
End Function

'********** SCOM Functions
Function CreateMOMScriptAPI
If DebugScript = False Then
Set CreateMOMScriptAPI = CreateObject("MOM.ScriptAPI")
Else
Set CreateMOMScriptAPI = New RegExp
End If
logMessage = "INFO: New MOM.ScriptAPI"
MOMDebugLog 1, logMessage
End Function

Function CreateDiscoveryData(ByRef oAPI, ByRef SourceId, ByRef ManagedEntityId)
If DebugScript = False Then
set CreateDiscoveryData = oAPI.CreateDiscoveryData(0, SourceId, ManagedEntityId)
Else
Set CreateDiscoveryData = New RegExp
End If
logMessage = "INFO: New Discovery Data"
MOMDebugLog 1, logMessage
End Function

Function ReturnDiscoveryData (ByRef oAPI, ByRef oDiscoveryData)
If DebugScript = False Then
Call oAPI.Return(oDiscoveryData)
End If
logMessage = "INFO: Returning Discovery Data"
MOMDebugLog 1, logMessage
End Function

Sub oInstAddProperty(ByRef oInst, prop, val)
If DebugScript = False Then
Call oInst.AddProperty(prop, val)
End If
logMessage = "INFO: Set " &amp; prop &amp; " = " &amp; val
MOMDebugLog 1, logMessage
End Sub

Function CreateClassInstance(ByRef oDiscoveryData, classid)
If DebugScript = False Then
set CreateClassInstance = oDiscoveryData.CreateClassInstance(classid)
Else
Set CreateClassInstance = New RegExp
End If
logMessage = "INFO: New Class Instance" &amp; classid
MOMDebugLog 1, logMessage
End Function

Sub AddInstanceToDiscoveryData(ByRef oDiscoveryData, ByRef oInst)
If DebugScript = False Then
Call oDiscoveryData.AddInstance(oInst)
End If
logMessage = "INFO: AddInstance to Discovery Data"
MOMDebugLog 1, logMessage
End Sub


Function DebugOut(message)
If DebugScript Then WScript.Echo message
End Function


</Script></ScriptBody>
<TimeoutSeconds>300</TimeoutSeconds>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DS"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>