My favorites | Sign in
Project Home Downloads Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
<ManagementPack ContentReadable="true" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<Manifest>
<Identity>
<ID>TG.WinAutoSvc</ID>
<Version>1.0.0.66</Version>
</Identity>
<Name>TG.WinAutoSvc</Name>
<References>
<Reference Alias="SC">
<ID>Microsoft.SystemCenter.Library</ID>
<Version>6.1.7221.0</Version>
<PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
</Reference>
<Reference Alias="MicrosoftSystemCenterNTServiceLibrary">
<ID>Microsoft.SystemCenter.NTService.Library</ID>
<Version>6.1.7221.0</Version>
<PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
</Reference>
<Reference Alias="Windows">
<ID>Microsoft.Windows.Library</ID>
<Version>6.1.7221.0</Version>
<PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
</Reference>
<Reference Alias="Health">
<ID>System.Health.Library</ID>
<Version>6.1.7221.0</Version>
<PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
</Reference>
<Reference Alias="System">
<ID>System.Library</ID>
<Version>6.1.7221.0</Version>
<PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
</Reference>
</References>
</Manifest>
<TypeDefinitions>
<EntityTypes>
<ClassTypes>
<ClassType ID="TG.WinAutoSvc.Service" Accessibility="Public" Abstract="false" Base="MicrosoftSystemCenterNTServiceLibrary!Microsoft.SystemCenter.OwnProcessNTService" Hosted="true" Singleton="false" />
<ClassType ID="TG.WinAutoSvc.SharedService" Accessibility="Public" Abstract="false" Base="MicrosoftSystemCenterNTServiceLibrary!Microsoft.SystemCenter.SharedProcessNTService" Hosted="true" Singleton="false" />
</ClassTypes>
</EntityTypes>
<ModuleTypes>
<DataSourceModuleType ID="TG.WinAutoSvc.ServiceDiscoveryDS" Accessibility="Public" Batching="false">
<Configuration>
<IncludeSchemaTypes>
<SchemaType>System!System.Discovery.MapperSchema</SchemaType>
<SchemaType>System!System.ExpressionEvaluatorSchema</SchemaType>
</IncludeSchemaTypes>
<xsd:element minOccurs="1" name="IntervalSeconds" type="xsd:integer" />
<xsd:element minOccurs="1" name="ComputerName" type="xsd:string" />
<xsd:element minOccurs="1" name="TimeoutSeconds" type="xsd:integer" />
<xsd:element minOccurs="1" name="ScriptName" type="xsd:string" />
<xsd:element minOccurs="1" name="Debug" type="xsd:boolean" />
<xsd:element minOccurs="1" name="ClassId" type="xsd:string" />
<xsd:element minOccurs="1" name="InstanceSettings" type="SettingsType" />
<xsd:element minOccurs="1" name="Filter" type="ExpressionType" />
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int" />
<OverrideableParameter ID="Debug" Selector="$Config/Debug$" ParameterType="bool" />
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int" />
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="Scheduler" TypeID="System!System.Discovery.Scheduler">
<Scheduler>
<SimpleReccuringSchedule>
<Interval>$Config/IntervalSeconds$</Interval>
<SyncTime>23:30</SyncTime>
</SimpleReccuringSchedule>
<ExcludeDates />
</Scheduler>
</DataSource>
<ProbeAction ID="PropertyBag" TypeID="TG.WinAutoSvc.Probe.VBSPropertyBag">
<ScriptName>$Config/ScriptName$</ScriptName>
<ComputerName>$Config/ComputerName$</ComputerName>
<Debug>$Config/Debug$</Debug>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
<ConditionDetection ID="Mapper" TypeID="System!System.Discovery.ClassSnapshotDataMapper">
<ClassId>$Config/ClassId$</ClassId>
<InstanceSettings>$Config/InstanceSettings$</InstanceSettings>
</ConditionDetection>
<ConditionDetection ID="Filter" TypeID="System!System.ExpressionFilter">
<Expression>$Config/Filter$</Expression>
</ConditionDetection>
</MemberModules>
<Composition>
<Node ID="Mapper">
<Node ID="Filter">
<Node ID="PropertyBag">
<Node ID="Scheduler" />
</Node>
</Node>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>
<ProbeActionModuleType ID="TG.WinAutoSvc.Probe.VBSPropertyBag" Accessibility="Internal" Batching="false" PassThrough="false">
<Configuration>
<xsd:element minOccurs="1" name="ScriptName" type="xsd:string" />
<xsd:element minOccurs="1" name="ComputerName" type="xsd:string" />
<xsd:element minOccurs="1" name="Debug" type="xsd:boolean" />
<xsd:element minOccurs="1" name="TimeoutSeconds" type="xsd:integer" />
</Configuration>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<ProbeAction ID="PropertyBag" TypeID="Windows!Microsoft.Windows.ScriptPropertyBagProbe">
<ScriptName>$Config/ScriptName$</ScriptName>
<Arguments>$Config/ComputerName$ $Config/Debug$</Arguments>
<ScriptBody><![CDATA[
Option Explicit

Dim computerName, keyPath, wmiObject, automaticServices, automaticService, serviceName, debugEnabled, scriptParameters, serviceClass
Dim scomApi, scomPropertyBag, serviceObject, returnValue

'''
' Get registry values into array
'''

CONST HKLM = &H80000002
CONST REG_SZ = 1
CONST REG_EXPAND_SZ = 2
CONST REG_BINARY = 3
CONST REG_DWORD = 4
CONST REG_MULTI_SZ = 7
CONST SCOM_INFO = 2
CONST SCOM_WARNING = 1
CONST SCOM_ERROR = 0
CONST SCOM_SCRIPT_INFORMATION = 19200
CONST SCOM_SCRIPT_WARNING = 19201
CONST SCOM_SCRIPT_ERROR = 19202
CONST SCOM_DEBUG = 19999


CheckParameters 2
computerName = CStr(scriptParameters(0))
debugEnabled = CBool(scriptParameters(1))

Set wmiObject = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & computerName & "\root\cimv2")
Set automaticServices = wmiObject.ExecQuery("Select * from Win32_Service where StartMode = 'Auto'")

If NOT IsNull(automaticServices) Then
If automaticServices.Count >= 0 And Err.Number = 0 Then
' We got a "hit" on a service name configured in the registry
' Create the SCOM property bag instances and return them to SCOM
Set scomApi = CreateObject("MOM.ScriptAPI")

For Each automaticService In automaticServices
serviceName = automaticService.Name
' Add one property bag per service
LogEvent SCOM_DEBUG,SCOM_INFO,"Found automatic service: " & serviceName

If Err.Number = 0 Then
With automaticService
Set scomPropertyBag = scomApi.CreatePropertyBag() ' Instance of a new property bag

' Start adding values to the propertybag
Call scomPropertyBag.AddValue("Name",Cstr(.Name))
Call scomPropertyBag.AddValue("DisplayName",Cstr(.DisplayName))
If .Description <> vbNull Then
Call scomPropertyBag.AddValue("Description",Cstr(.Description))
Else
Call scomPropertyBag.AddValue("Description","")
End If
Call scomPropertyBag.AddValue("SystemName",Cstr(.SystemName))
Call scomPropertyBag.AddValue("PathName",Cstr(.PathName))
Call scomPropertyBag.AddValue("ProcessID",Cstr(.ProcessID))
Call scomPropertyBag.AddValue("ServiceUser",Cstr(.StartName))
Call scomPropertyBag.AddValue("State",Cstr(.State))
Call scomPropertyBag.AddValue("Status",Cstr(.Status))
Call scomPropertyBag.AddValue("StartMode",Cstr(.StartMode))
Call scomPropertyBag.AddValue("ServiceType",Cstr(.ServiceType))
Call scomPropertyBag.AddValue("TagID",Cstr(.TagID))

Call scomApi.AddItem(scomPropertyBag) ' Add the property bag to the collection
End With
Else
Select Case returnValue
Case 242100
LogEvent SCOM_SCRIPT_WARNING, SCOM_WARNING, "Could not properly connect to the service repository on " & computerName & ", check RunAs user rights."
Case 242101
LogEvent SCOM_SCRIPT_WARNING, SCOM_WARNING, "Could not match registry value """ & serviceName & """to an existing service."
Case 424
LogEvent SCOM_SCRIPT_WARNING, SCOM_WARNING, "Connection to WMI-service on " & computerName & " failed. Check network connections and RunAs user rights."
Case Else
LogEvent SCOM_SCRIPT_WARNING, SCOM_WARNING, "An unhandled script event occured, please contact your SCOM admins." & vbCrLf & "Err.number = " & Err.Number
End Select
End If

Set serviceObject = Nothing
Next
Call scomApi.ReturnItems() ' Return the property bag collection to SCOM
Set scomApi = Nothing
Else
' Got no services from WMI query
LogEvent SCOM_DEBUG,SCOM_INFO,"Found no automatic services" & vbCrLf & _
"Error code: " & Err.Num & vbCrLf & _
"Error Description: " & Err.Description
End If
Else
' Could not read from WMI, perhaps user rights is insufficent?
LogEvent SCOM_DEBUG,SCOM_INFO,"Could not connect to WMI, check user rights!"
End If


'''
' Clean things up
'''
Set wmiObject = Nothing


'''
' Helper funktions
'''

Sub CheckParameters(numRequiredParams)
'''
' Simple check to verify the number of arguments passed
' to the script
' Sets the global variable scriptParameters to a Wscript.Arguments array
'
' Bit of a hack, yes, but it works for now.
'''
Dim scriptArguments
Set scriptArguments = WScript.Arguments

If IsNumeric(numRequiredParams) Then
If scriptArguments.Count >= numRequiredParams Then
Set scriptParameters = scriptArguments
Else
LogEvent SCOM_SCRIPT_ERROR,SCOM_ERROR,"Script was not called with all the required parameters."
WScript.Quit
End If
Else
LogEvent SCOM_SCRIPT_ERROR,SCOM_ERROR,"The CheckParameters() sub was called with numRequiredParams as not numeric."
WScript.Quit
End If
Set scriptArguments = Nothing
End Sub


Sub LogEvent(logEventID, logSeverity, logMessage)
'''
' Logs a MOM ScriptEvent into the Operations Manager eventlog
'''
Dim scomApi, scriptName
scriptName = WScript.ScriptName

If logEventID <> SCOM_DEBUG Then
Set scomApi = CreateObject("MOM.ScriptAPI")
Call scomApi.LogScriptEvent(scriptName,logEventID,logSeverity,logMessage)
Set scomApi = Nothing
Else
If debugEnabled Then
Set scomApi = CreateObject("MOM.ScriptAPI")
Call scomApi.LogScriptEvent(scriptName,logEventID,logSeverity,logMessage)
Set scomApi = Nothing
End If
End If
End Sub

]]></ScriptBody>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="PropertyBag" />
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
<InputType>System!System.TriggerData</InputType>
</ProbeActionModuleType>
</ModuleTypes>
</TypeDefinitions>
<Monitoring>
<Discoveries>
<Discovery ID="TG.WinAutoSvc.OwnProcessService.Discovery" Enabled="false" Target="Windows!Microsoft.Windows.Server.Computer" ConfirmDelivery="true" Remotable="true" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="TG.WinAutoSvc.Service">
<Property TypeID="MicrosoftSystemCenterNTServiceLibrary!Microsoft.SystemCenter.NTService" PropertyID="ServiceName" />
<Property TypeID="MicrosoftSystemCenterNTServiceLibrary!Microsoft.SystemCenter.NTService" PropertyID="ServiceProcessName" />
<Property TypeID="MicrosoftSystemCenterNTServiceLibrary!Microsoft.SystemCenter.NTService" PropertyID="DisplayName" />
<Property TypeID="MicrosoftSystemCenterNTServiceLibrary!Microsoft.SystemCenter.NTService" PropertyID="Description" />
</DiscoveryClass>
</DiscoveryTypes>
<DataSource ID="ServiceDS" TypeID="TG.WinAutoSvc.ServiceDiscoveryDS">
<IntervalSeconds>14400</IntervalSeconds>
<ComputerName>$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/NetworkName$</ComputerName>
<TimeoutSeconds>300</TimeoutSeconds>
<ScriptName>TGWinAutoSvcDiscovery.vbs</ScriptName>
<Debug>false</Debug>
<ClassId>$MPElement[Name="TG.WinAutoSvc.Service"]$</ClassId>
<InstanceSettings>
<Settings>
<Setting>
<Name>$MPElement[Name='MicrosoftSystemCenterNTServiceLibrary!Microsoft.SystemCenter.NTService']/ServiceName$</Name>
<Value>$Data/Property[@Name='Name']$</Value>
</Setting>
<Setting>
<Name>$MPElement[Name='MicrosoftSystemCenterNTServiceLibrary!Microsoft.SystemCenter.NTService']/DisplayName$</Name>
<Value>$Data/Property[@Name='DisplayName']$</Value>
</Setting>
<Setting>
<Name>$MPElement[Name='MicrosoftSystemCenterNTServiceLibrary!Microsoft.SystemCenter.NTService']/ServiceProcessName$</Name>
<Value>$Data/Property[@Name='PathName']$</Value>
</Setting>
<Setting>
<Name>$MPElement[Name='MicrosoftSystemCenterNTServiceLibrary!Microsoft.SystemCenter.NTService']/Description$</Name>
<Value>$Data/Property[@Name='Description']$</Value>
</Setting>
<Setting>
<Name>$MPElement[Name="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Name>
<Value>$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Value>
</Setting>
</Settings>
</InstanceSettings>
<Filter>
<RegExExpression>
<ValueExpression>
<XPathQuery>Property[@Name='ServiceType']</XPathQuery>
</ValueExpression>
<Operator>ContainsSubstring</Operator>
<Pattern>Own Process</Pattern>
</RegExExpression>
</Filter>
</DataSource>
</Discovery>
<Discovery ID="TG.WinAutoSvc.SharedProcessService.Discovery" Enabled="false" Target="Windows!Microsoft.Windows.Server.Computer" ConfirmDelivery="true" Remotable="true" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="TG.WinAutoSvc.SharedService">
<Property TypeID="MicrosoftSystemCenterNTServiceLibrary!Microsoft.SystemCenter.NTService" PropertyID="ServiceName" />
<Property TypeID="MicrosoftSystemCenterNTServiceLibrary!Microsoft.SystemCenter.NTService" PropertyID="ServiceProcessName" />
<Property TypeID="MicrosoftSystemCenterNTServiceLibrary!Microsoft.SystemCenter.NTService" PropertyID="DisplayName" />
<Property TypeID="MicrosoftSystemCenterNTServiceLibrary!Microsoft.SystemCenter.NTService" PropertyID="Description" />
</DiscoveryClass>
</DiscoveryTypes>
<DataSource ID="ServiceDS" TypeID="TG.WinAutoSvc.ServiceDiscoveryDS">
<IntervalSeconds>14400</IntervalSeconds>
<ComputerName>$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/NetworkName$</ComputerName>
<TimeoutSeconds>300</TimeoutSeconds>
<ScriptName>TGWinAutoSvcDiscovery.vbs</ScriptName>
<Debug>false</Debug>
<ClassId>$MPElement[Name="TG.WinAutoSvc.SharedService"]$</ClassId>
<InstanceSettings>
<Settings>
<Setting>
<Name>$MPElement[Name='MicrosoftSystemCenterNTServiceLibrary!Microsoft.SystemCenter.NTService']/ServiceName$</Name>
<Value>$Data/Property[@Name='Name']$</Value>
</Setting>
<Setting>
<Name>$MPElement[Name='MicrosoftSystemCenterNTServiceLibrary!Microsoft.SystemCenter.NTService']/DisplayName$</Name>
<Value>$Data/Property[@Name='DisplayName']$</Value>
</Setting>
<Setting>
<Name>$MPElement[Name='MicrosoftSystemCenterNTServiceLibrary!Microsoft.SystemCenter.NTService']/ServiceProcessName$</Name>
<Value>$Data/Property[@Name='PathName']$</Value>
</Setting>
<Setting>
<Name>$MPElement[Name='MicrosoftSystemCenterNTServiceLibrary!Microsoft.SystemCenter.NTService']/Description$</Name>
<Value>$Data/Property[@Name='Description']$</Value>
</Setting>
<Setting>
<Name>$MPElement[Name="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Name>
<Value>$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Value>
</Setting>
</Settings>
</InstanceSettings>
<Filter>
<RegExExpression>
<ValueExpression>
<XPathQuery>Property[@Name='ServiceType']</XPathQuery>
</ValueExpression>
<Operator>ContainsSubstring</Operator>
<Pattern>Share Process</Pattern>
</RegExExpression>
</Filter>
</DataSource>
</Discovery>
</Discoveries>
</Monitoring>
<LanguagePacks>
<LanguagePack ID="ENU" IsDefault="true">
<DisplayStrings>
<DisplayString ElementID="TG.WinAutoSvc">
<Name>TG Windows Automatic Service</Name>
<Description>Management Pack to simplify windows service monitoring.</Description>
</DisplayString>
<DisplayString ElementID="TG.WinAutoSvc.OwnProcessService.Discovery">
<Name>TG Windows Automatic Service Discovery</Name>
<Description>Discover services with "Automatic" startup settings</Description>
</DisplayString>
<DisplayString ElementID="TG.WinAutoSvc.Probe.VBSPropertyBag">
<Name>TG Windows Automatic Service Probe VBS PropertyBag</Name>
</DisplayString>
<DisplayString ElementID="TG.WinAutoSvc.Service">
<Name>Windows Automatic Service</Name>
<Description>Custom monitoring for automatic services</Description>
</DisplayString>
<DisplayString ElementID="TG.WinAutoSvc.ServiceDiscoveryDS">
<Name>Windows Automatic Services Discovery DS</Name>
</DisplayString>
<DisplayString ElementID="TG.WinAutoSvc.SharedProcessService.Discovery">
<Name>TG Windows Automatic Shared Service Discovery</Name>
<Description>Discover services with "Automatic" startup settings running under a shared process</Description>
</DisplayString>
<DisplayString ElementID="TG.WinAutoSvc.SharedService">
<Name>Windows Automatic Shared Service</Name>
<Description>Windows Service with automatic startup and shared process like services running under svchost.exe for example.</Description>
</DisplayString>
</DisplayStrings>
</LanguagePack>
</LanguagePacks>
</ManagementPack>

Change log

r5 by samuel.t...@hartati.se on Apr 7, 2011   Diff
Corrected class ref. for Share Process
Go to: 
Project members, sign in to write a code review

Older revisions

r2 by samuel.t...@hartati.se on Apr 7, 2011   Diff
[No log message]
All revisions of this file

File info

Size: 19922 bytes, 422 lines
Powered by Google Project Hosting