-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathRule.Performance.Collection.PowerShellScript.mpx
More file actions
164 lines (150 loc) · 7.48 KB
/
Rule.Performance.Collection.PowerShellScript.mpx
File metadata and controls
164 lines (150 loc) · 7.48 KB
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
<ManagementPackFragment SchemaVersion="2.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--
%%
Description:
A RULE that uses a PowerShell script to collect data and output/map it to Performance data for collection
CompanyID - is a short abbreviation for your company with NO SPACES OR SPECIAL CHARACTERS ALLOWED
AppName - is a short name for your app with NO SPACES OR SPECIAL CHARACTERS ALLOWED
ClassID - is the targeted class such as your custom class or Windows!Microsoft.Windows.Server.OperatingSystem
UniqueID - Is a unique short description of the workflow purpose (NO SPACES OR SPECIAL CHARACTERS ALLOWED) such as "CountFilesInFolder"
ObjectName, CounterName, and InstanceName - you can make up in this case, as we are mapping the data from PowerShell to a made up Performance Counter
Version: 1.2
LastModified: 4-Nov-2017
%%
In this fragment you need to replace:
##CompanyID##
##AppName##
##ClassID##
##UniqueID##
##ObjectName##
##InstanceName##
##CounterName##
This fragment depends on references:
RequiredReference: Alias="SC", ID="Microsoft.SystemCenter.Library"
RequiredReference: Alias="System", ID="System.Library"
RequiredReference: Alias="Windows", ID="Microsoft.Windows.Library"
RequiredReference: Alias="Perf", ID="System.Performance.Library"
RequiredReference: Alias="MSDL", ID="Microsoft.SystemCenter.DataWarehouse.Library"
@@Author=Kevin Holman@@
-->
<TypeDefinitions>
<ModuleTypes>
<DataSourceModuleType ID="##CompanyID##.##AppName##.##UniqueID##.Script.Perf.Datasource" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element minOccurs="1" type="xsd:integer" name="IntervalSeconds" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
<xsd:element minOccurs="0" type="xsd:string" name="SyncTime" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
<xsd:element minOccurs="1" type="xsd:integer" name="TimeoutSeconds" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int" />
<OverrideableParameter ID="SyncTime" Selector="$Config/SyncTime$" ParameterType="string" />
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int" />
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="Scheduler" TypeID="System!System.Scheduler">
<Scheduler>
<SimpleReccuringSchedule>
<Interval Unit="Seconds">$Config/IntervalSeconds$</Interval>
<SyncTime>$Config/SyncTime$</SyncTime>
</SimpleReccuringSchedule>
<ExcludeDates />
</Scheduler>
</DataSource>
<ProbeAction ID="PA" TypeID="Windows!Microsoft.Windows.PowerShellPropertyBagTriggerOnlyProbe">
<ScriptName>##CompanyID##.##AppName##.##UniqueID##.Script.Perf.Datasource.ps1</ScriptName>
<ScriptBody>
#=================================================================================
# Describe Script Here
#
# Author:
# v1.0
#=================================================================================
# Constants section - modify stuff here:
#=================================================================================
# Assign script name variable for use in event logging.
$ScriptName = "##CompanyID##.##AppName##.##UniqueID##.Script.Perf.Datasource.ps1"
$EventID = "1234"
#=================================================================================
# Starting Script section - All scripts get this
#=================================================================================
# Gather the start time of the script
$StartTime = Get-Date
#Set variable to be used in logging events
$whoami = whoami
# Load MOMScript API
$momapi = New-Object -comObject MOM.ScriptAPI
# Load PropertyBag function
$bag = $momapi.CreatePropertyBag()
#Log script event that we are starting task
$momapi.LogScriptEvent($ScriptName,$EventID,0,"`n Script is starting. `n Running as ($whoami).")
#=================================================================================
# Begin MAIN script section
#=================================================================================
#Setting a Value to an arbitrary number for example purposes
$Value = "347"
#Adding the value from the script into the propertybag
$bag.AddValue("Value",$Value)
# Return all bags
$bag
#=================================================================================
# End MAIN script section
# End of script section
#=================================================================================
#Log an event for script ending and total execution time.
$EndTime = Get-Date
$ScriptTime = ($EndTime - $StartTime).TotalSeconds
$momapi.LogScriptEvent($ScriptName,$EventID,0,"`n Script Completed. `n Script Runtime: ($ScriptTime) seconds.")
#=================================================================================
# End of script
</ScriptBody>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="PA">
<Node ID="Scheduler" />
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
</DataSourceModuleType>
</ModuleTypes>
</TypeDefinitions>
<Monitoring>
<Rules>
<Rule ID="##CompanyID##.##AppName##.##UniqueID##.Script.Perf.Rule" Enabled="true" Target="##ClassID##" ConfirmDelivery="false" Remotable="true" Priority="Normal" DiscardLevel="100">
<Category>PerformanceCollection</Category>
<DataSources>
<DataSource ID="DS" TypeID="##CompanyID##.##AppName##.##UniqueID##.Script.Perf.Datasource">
<IntervalSeconds>900</IntervalSeconds>
<SyncTime></SyncTime>
<TimeoutSeconds>120</TimeoutSeconds>
</DataSource>
</DataSources>
<ConditionDetection ID="System.Performance.DataGenericMapper" TypeID="Perf!System.Performance.DataGenericMapper">
<ObjectName>##ObjectName##</ObjectName>
<CounterName>##CounterName##</CounterName>
<InstanceName>##InstanceName##</InstanceName>
<Value>$Data/Property[@Name='Value']$</Value>
</ConditionDetection>
<WriteActions>
<WriteAction ID="WriteToDB" TypeID="SC!Microsoft.SystemCenter.CollectPerformanceData" /> <!-- Can be optional - collect this data to the Operations Database. -->
<WriteAction ID="WriteToDW" TypeID="MSDL!Microsoft.SystemCenter.DataWarehouse.PublishPerformanceData" /> <!-- Can be optional - collect this data to the Data Warehouse Database -->
</WriteActions>
</Rule>
</Rules>
</Monitoring>
<LanguagePacks>
<LanguagePack ID="ENU" IsDefault="true">
<DisplayStrings>
<DisplayString ElementID="##CompanyID##.##AppName##.##UniqueID##.Script.Perf.Rule">
<Name>##CompanyID## ##AppName## ##UniqueID## Script Performance Collection Rule</Name>
<Description></Description>
</DisplayString>
</DisplayStrings>
</LanguagePack>
</LanguagePacks>
</ManagementPackFragment>