Skip to content

Commit 894a079

Browse files
authored
Merge pull request #3 from spa5603/v1.1.0.0
Add files via upload
2 parents 42f49b1 + 0b6d955 commit 894a079

1 file changed

Lines changed: 106 additions & 14 deletions

File tree

OpsMgr.GenericServiceMonitoring/OpsMgr.GenericServiceMonitoring.xml

Lines changed: 106 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<Manifest>
44
<Identity>
55
<ID>OpsMgr.GenericServiceMonitoring</ID>
6-
<Version>1.0.0.0</Version>
6+
<Version>1.1.0.0</Version>
77
</Identity>
88
<Name>OpsMgr.GenericServiceMonitoring</Name>
99
<References>
@@ -57,11 +57,12 @@
5757
# NAME: OpsMgr.GenericServiceMonitoring.Scripts.GetServicesToMonitor.Script.ps1
5858
# AUTHOR: Sebastian Pabst
5959
# CREATED: 29.08.2018
60-
# UPDATE: 12.09.2018
60+
# UPDATE: 11.01.2019
6161
# PARAMETER: $sourceId,$managedEntityId,$OverrideValue,$computerName
62-
# VERSION: 1.1
63-
# CHANGES: 1.1 CleanUp script
64-
# HISTORY: 1.0 Initial script creation
62+
# VERSION: 1.2
63+
# CHANGES: 1.2 Add some logging for better usage
64+
# HISTORY: 1.1 CleanUp script
65+
# 1.0 Initial script creation
6566
###########################################################################################
6667
6768
# Declaration of Parameters
@@ -211,11 +212,11 @@ if ($Error.Count -gt 0) {$API.LogScriptEvent($ScriptName,5603,1,"The following E
211212
# NAME: OpsMgr.GenericServiceMonitoring.Scripts.StartGenSerMonIngestionScript.ps1
212213
# AUTHOR: Sebastian Pabst
213214
# CREATED: 30.08.2018
214-
# UPDATE: -
215+
# UPDATE: 11.01.2019
215216
# PARAMETER: -
216-
# VERSION: 1.0
217-
# CHANGES: -
218-
# HISTORY: -
217+
# VERSION: 1.1
218+
# CHANGES: 1.1 Add some logging for better usage
219+
# HISTORY: 1.0 Initial script creation
219220
###########################################################################################
220221
221222
# Declaration of Parameters
@@ -226,14 +227,20 @@ param(
226227
# Declaration of Scriptname
227228
[string]$ScriptName = 'OpsMgr.GenericServiceMonitoring.Scripts.StartGenSerMonIngestionScript.ps1'
228229
230+
# Initialization of MOMAPI
231+
$API = New-Object -comObject 'MOM.ScriptAPI'
232+
233+
# Write Start Event to OperationsManager Log
234+
$API.LogScriptEvent($ScriptName,5603,0,"Script is starting!")
235+
229236
# Declaration of Variables
230237
$ManagementPack = Get-SCOMManagementPack -Name 'OpsMgr.GenericServiceMonitoring'
231238
$Discovery = Get-SCOMDiscovery -Name 'OpsMgr.GenericServiceMonitoring.OpsMgr.GenericServiceMonitoring.Discoveries.GetServicesToMonitor.Discovery'
232239
$Target = Get-SCOMClass -Name 'Microsoft.SystemCenter.ManagedComputerServer'
233240
234241
# Test Path of Service CSV
235242
if (!(Test-Path -Path $ServiceFilePath)) {
236-
"ServiceFile not found in $ServiceFilePath!"
243+
$API.LogScriptEvent($ScriptName,5603,1,"ServiceFile not found in $ServiceFilePath! Script will be terminated!")
237244
exit 0
238245
}
239246
@@ -248,7 +255,7 @@ If ($ServicesToIngest.count -eq 0) {
248255
$Override.Status = 'PendingDelete'
249256
$ManagementPack.Verify()
250257
$ManagementPack.AcceptChanges()
251-
'No Service is configured to monitor and the configured override was deleted!'
258+
$API.LogScriptEvent($ScriptName,5603,0,"No Service is configured to monitor and the configured override was deleted!")
252259
exit 0
253260
}
254261
}
@@ -264,7 +271,7 @@ foreach ($ServiceToIngest in $ServicesToIngest) {
264271
$OverrideString = $OverrideString.Substring(0,$OverrideString.Length-1)
265272
266273
# Write information Event to OperationsManager Log
267-
"The following String is used for Override:" + "`n" + $OverrideString
274+
$API.LogScriptEvent($ScriptName,5603,0,"The following String is used for Override:" + "`n" + $OverrideString)
268275
269276
# Setup the Override
270277
$OverrideName = 'OpsMgr.GenericServiceMonitoring.Overrides.SetMonitoredServices.Override'
@@ -281,12 +288,12 @@ $ManagementPack.AcceptChanges()
281288
282289
# Write Event to OperationsManager Log in case of Error
283290
if ($Error.Count -gt 0) {
284-
"The following Errors occured: $Error"
291+
$API.LogScriptEvent($ScriptName,5603,1,"The following Errors occured: $Error")
285292
}
286293
287294
# Write Success Event to OperationsManager Log
288295
else {
289-
"Script has finished successfully."
296+
$API.LogScriptEvent($ScriptName,5603,0,"Script has finished successfully.")
290297
}]]></ScriptBody>
291298
<Parameters>
292299
<Parameter>
@@ -322,6 +329,82 @@ else {
322329
</DataSource>
323330
</Discovery>
324331
</Discoveries>
332+
<Rules>
333+
<Rule ID="OpsMgr.GenericServiceMonitoring.OpsMgr.GenericServiceMonitoring.Rules.NotFoundServices.Rule" Target="SystemCenter!Microsoft.SystemCenter.ManagedComputerServer" Enabled="true" ConfirmDelivery="false" Remotable="true" Priority="Normal" DiscardLevel="100">
334+
<Category>Alert</Category>
335+
<DataSources>
336+
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.EventProvider">
337+
<ComputerName>$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/NetworkName$</ComputerName>
338+
<LogName>Operations Manager</LogName>
339+
<Expression>
340+
<And>
341+
<Expression>
342+
<SimpleExpression>
343+
<ValueExpression>
344+
<XPathQuery Type="UnsignedInteger">EventDisplayNumber</XPathQuery>
345+
</ValueExpression>
346+
<Operator>Equal</Operator>
347+
<ValueExpression>
348+
<Value Type="UnsignedInteger">5603</Value>
349+
</ValueExpression>
350+
</SimpleExpression>
351+
</Expression>
352+
<Expression>
353+
<SimpleExpression>
354+
<ValueExpression>
355+
<XPathQuery Type="String">PublisherName</XPathQuery>
356+
</ValueExpression>
357+
<Operator>Equal</Operator>
358+
<ValueExpression>
359+
<Value Type="String">Health Service Script</Value>
360+
</ValueExpression>
361+
</SimpleExpression>
362+
</Expression>
363+
<Expression>
364+
<SimpleExpression>
365+
<ValueExpression>
366+
<XPathQuery Type="String">EventLevel</XPathQuery>
367+
</ValueExpression>
368+
<Operator>Equal</Operator>
369+
<ValueExpression>
370+
<Value Type="Integer">2</Value>
371+
</ValueExpression>
372+
</SimpleExpression>
373+
</Expression>
374+
<Expression>
375+
<RegExExpression>
376+
<ValueExpression>
377+
<XPathQuery Type="String">EventDescription</XPathQuery>
378+
</ValueExpression>
379+
<Operator>ContainsSubstring</Operator>
380+
<Pattern>following Services should be discoverd:</Pattern>
381+
</RegExExpression>
382+
</Expression>
383+
</And>
384+
</Expression>
385+
</DataSource>
386+
</DataSources>
387+
<WriteActions>
388+
<WriteAction ID="WA" TypeID="Health!System.Health.GenerateAlert">
389+
<Priority>1</Priority>
390+
<Severity>1</Severity>
391+
<AlertName />
392+
<AlertDescription />
393+
<AlertOwner />
394+
<AlertMessageId>$MPElement[Name="OpsMgr.GenericServiceMonitoring.Rules.NotFoundServices.Rule.AlertMessage"]$</AlertMessageId>
395+
<AlertParameters>
396+
<AlertParameter1>$Data[Default='']/EventDescription$</AlertParameter1>
397+
</AlertParameters>
398+
<Suppression>
399+
<SuppressionValue>$Data/EventDisplayNumber$</SuppressionValue>
400+
<SuppressionValue>$Data/PublisherName$</SuppressionValue>
401+
<SuppressionValue>$Data/EventLevel$</SuppressionValue>
402+
<SuppressionValue>$Data/EventDescription$</SuppressionValue>
403+
</Suppression>
404+
</WriteAction>
405+
</WriteActions>
406+
</Rule>
407+
</Rules>
325408
<Tasks>
326409
<Task ID="OpsMgr.GenericServiceMonitoring.OpsMgr.GenericServiceMonitoring.Tasks.StartGenSerMonIngestion.Task" Accessibility="Internal" Target="SystemCenter!Microsoft.SystemCenter.ManagementServer" Enabled="true" Timeout="300" Remotable="true">
327410
<Category>Custom</Category>
@@ -427,6 +510,7 @@ else {
427510
</FolderItems>
428511
<StringResources>
429512
<StringResource ID="OpsMgr.GenericServiceMonitoring.OpsMgr.GenericServiceMonitoring.Monitors.ServiceWatcher.UnitMonitor.AlertMessage" />
513+
<StringResource ID="OpsMgr.GenericServiceMonitoring.Rules.NotFoundServices.Rule.AlertMessage" />
430514
</StringResources>
431515
</Presentation>
432516
<LanguagePacks>
@@ -472,6 +556,14 @@ else {
472556
<Name>NotRunning</Name>
473557
<Description>NotRunning</Description>
474558
</DisplayString>
559+
<DisplayString ElementID="OpsMgr.GenericServiceMonitoring.OpsMgr.GenericServiceMonitoring.Rules.NotFoundServices.Rule">
560+
<Name>OpsMgr GenericServiceMonitoring Rules NotFoundServices Rule</Name>
561+
<Description>Description for the new rule</Description>
562+
</DisplayString>
563+
<DisplayString ElementID="OpsMgr.GenericServiceMonitoring.Rules.NotFoundServices.Rule.AlertMessage">
564+
<Name>OpsMgr GenericServiceMonitoring Service not Found</Name>
565+
<Description>{0}</Description>
566+
</DisplayString>
475567
<DisplayString ElementID="OpsMgr.GenericServiceMonitoring.OpsMgr.GenericServiceMonitoring.Tasks.StartGenSerMonIngestion.Task">
476568
<Name>Start Service Ingestion</Name>
477569
<Description>Description for the new agent task.</Description>

0 commit comments

Comments
 (0)