Detección de cola

Microsoft.MSMQ.6.3.DataSource.QueueDiscovery (DataSourceModuleType)

Origen de datos para la detección de cola.

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityInternal
RunAsMicrosoft.MSMQ.6.3.QueueAccessProfile
OutputTypeSystem.Discovery.Data

Member Modules:

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

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$Intervalo en segundos
DiscoverPublicbool$Config/DiscoverPublic$Detectar colas públicas
DiscoverPrivatebool$Config/DiscoverPrivate$Detectar colas privadas
LogDetailbool$Config/LogDetail$Datos de registro
TimeoutSecondsint$Config/TimeoutSeconds$Tiempo de espera en segundos

Source Code:

<DataSourceModuleType ID="Microsoft.MSMQ.6.3.DataSource.QueueDiscovery" Accessibility="Internal" RunAs="Microsoft.MSMQ.6.3.QueueAccessProfile" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="IntervalSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="ComputerName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="ServiceName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="DiscoverPublic" type="xsd:boolean"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="DiscoverPrivate" type="xsd:boolean"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="WorkgroupServer" type="xsd:boolean"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="LogDetail" type="xsd:boolean"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="TimeoutSeconds" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="DiscoverPublic" Selector="$Config/DiscoverPublic$" ParameterType="bool"/>
<OverrideableParameter ID="DiscoverPrivate" Selector="$Config/DiscoverPrivate$" ParameterType="bool"/>
<OverrideableParameter ID="LogDetail" Selector="$Config/LogDetail$" ParameterType="bool"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedScript.DiscoveryProvider">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<SyncTime/>
<ScriptName>DiscoverQueues.vbs</ScriptName>
<Arguments>$MPElement$ $Target/Id$ "$Config/ComputerName$" "$Config/ServiceName$" "$Config/DiscoverPublic$" "$Config/DiscoverPrivate$" "$Config/WorkgroupServer$" "$Config/LogDetail$"</Arguments>
<ScriptBody><Script>option explicit
SetLocale("en-us")

Const SCRIPT_NAME = "DiscoverQueues.vbs"

Const EVENTNO_SCRIPT_STARTED = 14201
Const EVENTNO_SCRIPT_ENDED = 14202
Const EVENTNO_DISCOVER_PRIVATEQUEUES = 14210
Const EVENTNO_BYPASS_PRIVATEQUEUES = 14211
Const EVENTNO_DISCOVER_PUBLICQUEUES = 14212
Const EVENTNO_BYPASS_PUBLICQUEUES = 14213
Const EVENTNO_FOUND_QUEUE = 14221
Const EVENTNO_MSMQSERVICE_NOTRUNNING = 14230
Const EVENTNO_ERROR_ADLOOKUP = 14231
Const EVENTNO_ERROR_COULDNOTOPENQUEUE = 14232

Const EVENT_LEVEL_ERROR = 1
Const EVENT_LEVEL_WARNING = 2
Const EVENT_LEVEL_INFO = 4

Const HKEY_LOCAL_MACHINE = &amp;H80000002

Const MSMQ_REGROOT = "SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Modules\MSMQ Management Pack"
Const PUBLICQUEUE_VALUENAME = "Public Queues"

Dim SourceId, ManagedentityId, sComputer, sServiceName, bDiscoverPublicQueues, bDiscoverPrivateQueues, bWorkgroupServer, bLogDetail
Dim oApi, oDiscoveryData
Dim wshNetwork, sUser, sDomain, sMessage
Dim bIsCluster, WshShell, objWshShell, sName
Dim oMSMQApp
Dim sQueue, oQueue
Dim aPublicQueues, i

If WScript.Arguments.Count &lt; 7 Then Call ShowUsage()
SourceId = WScript.Arguments(0)
ManagedEntityId = WScript.Arguments(1)
sComputer = WScript.Arguments(2)
sServiceName = WScript.Arguments(3)
bDiscoverPublicQueues = cbool(WScript.Arguments(4))
bDiscoverPrivateQueues = cbool(WScript.Arguments(5))
bWorkgroupServer = cbool(WScript.Arguments(6))
bLogDetail = CBool(WScript.Arguments(7))

If IsMSMQServiceRunning = False Then
Call ThrowScriptError(EVENTNO_MSMQSERVICE_NOTRUNNING,EVENT_LEVEL_WARNING,"Queue Discovery did not execute because the MSMQ service is not running.",True)
End If

Set oAPI = CreateObject("MOM.ScriptAPI")
Set oDiscoveryData = oAPI.CreateDiscoveryData(0, SourceId, ManagedEntityId)

Set wshNetwork = CreateObject("Wscript.Network")
sUser = wshNetwork.UserName
sDomain = wshNetwork.UserDomain

sMessage = "Discovery started with following parameters: " &amp; VbCrLf &amp; _
"Source ID: " &amp; SourceId &amp; VbCrLf &amp; _
"Managed Entity ID: " &amp; ManagedEntityId &amp; VbCrLf &amp; _
"Computer: " &amp; sComputer &amp; VbCrLf &amp; _
"Network: " &amp; wshNetwork.ComputerName &amp; VbCrLf &amp; _
"Discover Public Queues: " &amp; bDiscoverPublicQueues &amp; VbCrLf &amp; _
"Discover Private Queues: " &amp; bDiscoverPrivateQueues &amp; VbCrLf &amp; _
"User credentials: " &amp; sDomain &amp; "\" &amp; sUser

Call LogDetail(EVENTNO_SCRIPT_STARTED,sMessage)

bIsCluster = false
If IsCluster = True then
bIsCluster = true
set WshShell = CreateObject("WScript.Shell")
set objWshShell = WshShell.Environment("Process")
sName = GetQueueServer(sComputer)
objWshShell("_CLUSTER_NETWORK_NAME_") = sName
objWshShell("_CLUSTER_NETWORK_HOSTNAME_") = sName
End If

Set oMSMQApp = CreateObject("MSMQ.MSMQApplication")
oMSMQApp.Machine = sComputer
oMSMQApp.Connect

'Private Queues
If bDiscoverPrivateQueues = True Then
Call LogDetail(EVENTNO_DISCOVER_PRIVATEQUEUES,"Discovering private queues.")
For Each sQueue In oMSMQApp.PrivateQueues
Set oQueue = NewQueueInstance(sComputer,sQueue,False)
If Not oQueue Is Nothing Then
Call SubmitQueue(oQueue)
Call WriteDetailEvent(oQueue)
End If
Next
Else
Call LogDetail(EVENTNO_BYPASS_PRIVATEQUEUES,"Bypassed discovery of private queues.")
End If

'Public Queues
Call InitializeRegistry(sComputer,MSMQ_REGROOT,PUBLICQUEUE_VALUENAME)
If bDiscoverPublicQueues = True And bWorkgroupServer = False Then

Call LogDetail(EVENTNO_DISCOVER_PUBLICQUEUES,"Discovering public queues.")

aPublicQueues = GetPublicQueues(sComputer)
For i = 0 To UBound(aPublicQueues)
Set oQueue = NewQueueInstance(sComputer,aPublicQueues(i),True)
If Not oQueue Is Nothing Then
Call SubmitQueue(oQueue)
Call WriteDetailEvent(oQueue)
Call WriteQueueToRegistry(oQueue,sComputer)
End If
Next
Else
Call LogDetail(EVENTNO_BYPASS_PUBLICQUEUES,"Bypassed discovery of public queues.")

End If

if bIsCluster = true then
objWshShell.Remove("_CLUSTER_NETWORK_NAME_")
objWshShell.Remove("_CLUSTER_NETWORK_HOSTNAME_")
End If

Call oAPI.Return(oDiscoveryData)
Call LogDetail(EVENTNO_SCRIPT_ENDED,"Queue Discovery script ended.")

Function GetQueueServer(Path)

If InStr(Path,".") &gt; 0 THEN
GetQueueServer = Left(Path, InStr(Path,".")-1)
Else
GetQueueServer = Path
End if

End Function

Function IsCluster()

Dim wshNetwork

Set wshNetwork = CreateObject("Wscript.Network")
if StrComp(wshNetwork.ComputerName, GetQueueServer(sComputer), 1) &lt;&gt; 0 then
IsCluster = True
else
IsCluster = False
End if

End Function

Function GetPublicQueues(Computer)
Dim MSMQQuery, Queues, QueueInfo, QueueServer, Message
Dim PublicQueues()
ReDim PublicQueues(0)

Set MSMQQuery = CreateObject("MSMQ.MSMQQuery")

On Error Resume Next
Set Queues = MSMQQuery.LookupQueue()
Set QueueInfo = Queues.Next
If Err = 0 Then
On Error GoTo 0
While Not QueueInfo Is Nothing
QueueServer = Split(QueueInfo.PathNameDNS,"\")(0)
If lcase(Computer) = lcase(QueueServer) Then
PublicQueues(UBound(PublicQueues)) = QueueInfo.PathName
ReDim Preserve PublicQueues(UBound(PublicQueues)+1)
End If
Set QueueInfo = Queues.Next
Wend
Else
Message = "Error searching Active Directory while discovering public queues." &amp; VbCrLf &amp; _
"Error number: " &amp; Err.Number &amp; VbCrLf &amp; _
"Error Description: " &amp; Err.Description
On Error GoTo 0
Call ThrowScriptError(EVENTNO_ERROR_ADLOOKUP,EVENT_LEVEL_ERROR,Message,False)
End If

ReDim Preserve PublicQueues(UBound(PublicQueues)-1)
GetPublicQueues = PublicQueues

End Function

Function NewQueueInstance(Computer,QueuePath,PublicQueue)

Dim oQueue, QueueInfo, sMessage

Set oQueue = New Queue
oQueue.ComputerName = Computer
oQueue.PathName = QueuePath
oQueue.IsPublic = CBool(PublicQueue)

'Validate that we have access to the queue.
'If not, we will throw an error and continue.
'If so, we will gather available settings.
On Error Resume Next
Set QueueInfo = CreateObject("MSMQ.MSMQQueueInfo")
QueueInfo.PathName = QueuePath
QueueInfo.Refresh

If Err = 0 Then

On Error GoTo 0
oQueue.FormatName = QueueInfo.FormatName
oQueue.IsTransactional = CBool(QueueInfo.IsTransactional)
oQueue.Label = QueueInfo.Label
oQueue.PrivilegeLevel = QueueInfo.PrivLevel
oQueue.Quota = QueueInfo.Quota
oQueue.JournalEnabled = CBool(QueueInfo.Journal)
oQueue.JournalQuota = QueueInfo.JournalQuota

If oQueue.IsPublic = True Then oQueue.AdsPath = QueueInfo.ADsPath
If QueueInfo.ServiceTypeGuid = "{55EE8F33-CCE9-11CF-B108-0020AFD61CE9}" Then
oQueue.IsTestQueue = True
Else
oQueue.IsTestQueue = False
End If

Set NewQueueInstance = oQueue

Else

On Error GoTo 0
sMessage = "Error connecting to queue: " &amp; QueuePath &amp; "." &amp; VbCrLf &amp; _
"Validate that the MSMQ Queue Access profile has access to read the queue properties."
Call ThrowScriptError(EVENTNO_ERROR_COULDNOTOPENQUEUE,EVENT_LEVEL_ERROR,sMessage,False)

Set NewQueueInstance = Nothing

End If

End Function

Sub SubmitQueue(NewQueue)
Dim oInstance
Set oInstance = oDiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.MSMQ.6.3.Queues']$")
With oInstance
.AddProperty "$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", NewQueue.ComputerName
.AddProperty "$MPElement[Name='Microsoft.MSMQ.6.3.Queue']/PathName$",NewQueue.PathName
.AddProperty "$MPElement[Name='Microsoft.MSMQ.6.3.Queue']/IsPublic$",NewQueue.IsPublic
.AddProperty "$MPElement[Name='Microsoft.MSMQ.6.3.Queue']/FormatName$",NewQueue.FormatName
.AddProperty "$MPElement[Name='Microsoft.MSMQ.6.3.Queue']/IsTransactional$",NewQueue.IsTransactional
.AddProperty "$MPElement[Name='Microsoft.MSMQ.6.3.Queue']/Label$",NewQueue.Label
.AddProperty "$MPElement[Name='Microsoft.MSMQ.6.3.Queue']/PrivilegeLevel$",NewQueue.PrivilegeLevel
.AddProperty "$MPElement[Name='Microsoft.MSMQ.6.3.Queue']/Quota$",NewQueue.Quota
.AddProperty "$MPElement[Name='Microsoft.MSMQ.6.3.Queue']/JournalEnabled$",NewQueue.JournalEnabled
.AddProperty "$MPElement[Name='Microsoft.MSMQ.6.3.Queue']/JournalQuota$",NewQueue.JournalQuota
.AddProperty "$MPElement[Name='Microsoft.MSMQ.6.3.Queue']/ADsPath$",NewQueue.ADsPath
.AddProperty "$MPElement[Name='Microsoft.MSMQ.6.3.Queue']/IsTestQueue$",NewQueue.IsTestQueue
End With

Call oDiscoveryData.AddInstance(oInstance)

End Sub

Sub WriteDetailEvent(NewQueue)
Dim sMessage
sMessage = "PrincipalName: " &amp; NewQueue.ComputerName &amp; VbCrLf &amp; _
"Public: " &amp; NewQueue.IsPublic &amp; VbCrLf &amp; _
"PathName: " &amp; NewQueue.PathName &amp; VbCrLf &amp; _
"ADsPath: " &amp; NewQueue.ADsPath &amp; VbCrLf &amp; _
"Format Name: " &amp; NewQueue.FormatName &amp; VbCrLf &amp; _
"IsTransactional: " &amp; NewQueue.IsTransactional &amp; VbCrLf &amp; _
"Label: " &amp; NewQueue.Label &amp; VbCrLf &amp; _
"PrivilegeLevel: " &amp; NewQueue.PrivilegeLevel
Call LogDetail(EVENTNO_FOUND_QUEUE,sMessage)

End Sub

Sub WriteQueueToRegistry(NewQueue,Computer)
Dim oReg, sRegRoot
Set oReg=GetObject("winmgmts:\\" &amp; Computer &amp; "\root\default:StdRegProv")

If NewQueue.IsPublic = True Then

sRegRoot = MSMQ_REGROOT &amp; "\" &amp; Computer &amp; "\" &amp; PUBLICQUEUE_VALUENAME &amp; "\" &amp; NewQueue.Label
oReg.CreateKey HKEY_LOCAL_MACHINE,sRegRoot
oReg.SetStringValue HKEY_LOCAL_MACHINE,sRegRoot,"PathName",NewQueue.PathName
oReg.SetStringValue HKEY_LOCAL_MACHINE,sRegRoot,"FormatName",NewQueue.FormatName
oReg.SetStringValue HKEY_LOCAL_MACHINE,sRegRoot,"Quota",NewQueue.Quota
oReg.SetStringValue HKEY_LOCAL_MACHINE,sRegRoot,"JournalEnabled",NewQueue.JournalEnabled
oReg.SetStringValue HKEY_LOCAL_MACHINE,sRegRoot,"JournalQuota",NewQueue.JournalQuota

End If

End Sub


Sub InitializeRegistry(Computer,KeyPath,ValueName)
Dim oReg
Set oReg=GetObject("winmgmts:\\" &amp; Computer &amp; "\root\default:StdRegProv")

oReg.CreateKey HKEY_LOCAL_MACHINE,KeyPath
oReg.CreateKey HKEY_LOCAL_MACHINE,KeyPath &amp; "\" &amp; Computer
oReg.CreateKey HKEY_LOCAL_MACHINE,KeyPath &amp; "\" &amp; Computer &amp; "\" &amp; PUBLICQUEUE_VALUENAME

End Sub


Sub AddToPublicQueuesRegistry(Computer,KeyPath,ValueName,Value)
Dim oReg, sValue, i

Set oReg=GetObject("winmgmts:\\" &amp; Computer &amp; "\root\default:StdRegProv")
Call oReg.GetMultiStringValue(HKEY_LOCAL_MACHINE,KeyPath,ValueName,aValues)
i = 0

For Each sValue In aValues
ReDim Preserve aNewValues(i)
aNewValues(i) = sValue
i=i+1
Next

ReDim Preserve aNewValues(i)
aNewValues(i) = Value
Call oReg.SetMultiStringValue(HKEY_LOCAL_MACHINE,KeyPath,ValueName,aNewValues)

End Sub

Sub ThrowScriptError(EventNo,Severity,Message,Abort)

Message = VbCrLf &amp; Message
Call oAPI.LogScriptEvent(SCRIPT_NAME,EventNo,Severity,Message)
If Abort = True Then WScript.Quit

End Sub


Sub LogDetail(EventNo,Message)

Message = VbCrLf &amp; "Calling MP Element ID: $MPElement$" &amp; vbcrlf &amp; Message
If bLogDetail = True Then
Call oAPI.LogScriptEvent(SCRIPT_NAME,EventNo,EVENT_LEVEL_INFO,Message)
End If

End Sub

Function IsMSMQServiceRunning()
Dim WMI, Services, Service
Set WMI = GetObject("winmgmts:\\" &amp; sComputer &amp; "\root\cimv2")
Set Services = WMI.ExecQuery("select * from win32_service where name = '" &amp; sServiceName &amp; "'")
For Each Service In Services
If lcase(Service.State) = "running" Then
IsMSMQServiceRunning = True
Else
IsMSMQServiceRunning = False
End If
Next

End Function

Sub ShowUsage

WScript.Echo "Usage: "
WScript.Echo "cscript DiscoverQueues.vbs &lt;CallingRuleGUID&gt; &lt;TargetEntityGUID&gt; &lt;Computer&gt; &lt;ServiceName&gt; &lt;DiscoverPublicQueues&gt; &lt;DiscoverPrivateQueues&gt; &lt;WorkgroupServer&gt; &lt;LogDetail&gt;"
WScript.Echo
WScript.Echo "Example:"
WScript.Echo "cscript DiscoverQueues.vbs {b3e9befe-173b-78a2-3e41-e19ecb58d9d5} {2fa43439-afc4-cc64-9b3a-9642ec898c1c} srv1.contoso.com true true false false"

WScript.Quit

End Sub

Class Queue

Public ComputerName
Public PathName
Public FormatName
Public IsPublic
Public IsTransactional
Public Label
Public PrivilegeLevel
Public Quota
Public JournalEnabled
Public JournalQuota
Public AdsPath
Public IsTestQueue

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