-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathRecovery.Script.PowerShell.Advanced.mpx
More file actions
154 lines (139 loc) · 7.24 KB
/
Recovery.Script.PowerShell.Advanced.mpx
File metadata and controls
154 lines (139 loc) · 7.24 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
<ManagementPackFragment SchemaVersion="2.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--
%%
Description:
A RECOVERY for a Monitor that executes a generic PowerShell script.
The recovery is disabled by default. Set Enabled="true" if you want the recovery to run automatically.
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
MonitorID - the ID of the monitor that the recovery should run against such as Microsoft.Windows.Server.10.0.OperatingSystem.MemoryAvailableMBytes
ExecuteOnState - This is dependent on the designed state of monitor you target and is set to Warning or Error
UniqueID - We need a Unique ID for this Recovery to reuse the fragment multiple times in the same MP. NO SPACES OR SPECIAL CHARACTERS ALLOWED
Version: 1.0
LastModified: 06-Aug-2021
%%
In this fragment you need to replace:
##CompanyID##
##AppName##
##ClassID##
##MonitorID##
##ExecuteOnState##
##UniqueID##
This fragment depends on references:
RequiredReference: Alias="Windows", ID="Microsoft.Windows.Library"
RequiredReference: Alias="Health", ID="System.Health.Library"
@@Author=Kevin Holman@@
-->
<TypeDefinitions>
<ModuleTypes>
<WriteActionModuleType ID="##CompanyID##.##AppName##.##UniqueID##.PowerShell.Recovery.WA" Accessibility="Public" Batching="false">
<Configuration>
<xsd:element minOccurs="1" name="Param1" type="xsd:string" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
<xsd:element minOccurs="1" name="Param2" type="xsd:string" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
<xsd:element minOccurs="1" name="TimeoutSeconds" type="xsd:integer" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int" />
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<WriteAction ID="PSWA" TypeID="Windows!Microsoft.Windows.PowerShellWriteAction">
<ScriptName>##CompanyID##.##AppName##.##UniqueID##.PowerShell.Recovery.WA.ps1</ScriptName>
<ScriptBody>
#=================================================================================
# Generic Recovery Script
#
# Author: Kevin Holman
# Version: 1.0
#=================================================================================
param($Param1,$Param2)
# Manual Testing section - put stuff here for manually testing script - typically parameters:
#=================================================================================
# $Param1 = "foo"
# $Param2 = "bar"
#=================================================================================
# Constants section - modify stuff here:
#=================================================================================
# Assign script name variable for use in event logging
$ScriptName = "##CompanyID##.##AppName##.##UniqueID##.PowerShell.Recovery.WA.ps1"
$EventID = "4321"
#=================================================================================
# Starting Script section
#=================================================================================
# 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
#=================================================================================
# Begin MAIN script section
#=================================================================================
#Log script event that we are starting task
$momapi.LogScriptEvent($ScriptName,$EventID,0,"`nRecovery script is starting. `nRunning as ($whoami).")
#Using Write-Host in a recovery action will output your data to the monitor statechange context in Health Explorer
Write-Host "Recovery script is starting. Running as ($whoami)."
#Put your recovery actions here
Write-Host "Param1: $Param1"
Write-Host "Param2: $Param2"
#=================================================================================
# 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,"`nScript Completed. `nScript Runtime: ($ScriptTime) seconds.")
Write-Host "Script Completed. Script Runtime: ($ScriptTime) seconds."
#=================================================================================
# End of script
</ScriptBody>
<Parameters>
<Parameter>
<Name>Param1</Name>
<Value>$Config/Param1$</Value>
</Parameter>
<Parameter>
<Name>Param2</Name>
<Value>$Config/Param2$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="PSWA" />
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.BaseData</OutputType>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>
</ModuleTypes>
</TypeDefinitions>
<Monitoring>
<Recoveries>
<Recovery ID="##CompanyID##.##AppName##.##UniqueID##.PowerShell.Recovery" Accessibility="Public" Enabled="false" Target="##ClassID##" Monitor="##MonitorID##" ResetMonitor="false" ExecuteOnState="##ExecuteOnState##" Remotable="true" Timeout="300">
<Category>Custom</Category>
<WriteAction ID="PSWA" TypeID="##CompanyID##.##AppName##.##UniqueID##.PowerShell.Recovery.WA">
<Param1>foo</Param1> <!-- Example target variable $Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/NetworkName$ -->
<Param2>bar</Param2> <!-- Example monitor statechange context property variable $Data/StateChange/DataItem/Context/DataItem/Property[@Name='Name']$ -->
<TimeoutSeconds>240</TimeoutSeconds>
</WriteAction>
</Recovery>
</Recoveries>
</Monitoring>
<LanguagePacks>
<LanguagePack ID="ENU" IsDefault="true">
<DisplayStrings>
<DisplayString ElementID="##CompanyID##.##AppName##.##UniqueID##.PowerShell.Recovery">
<Name>##CompanyID## ##AppName## ##UniqueID## PowerShell Recovery</Name>
</DisplayString>
<DisplayString ElementID="##CompanyID##.##AppName##.##UniqueID##.PowerShell.Recovery.WA">
<Name>##CompanyID## ##AppName## ##UniqueID## PowerShell Recovery WriteAction</Name>
</DisplayString>
</DisplayStrings>
</LanguagePack>
</LanguagePacks>
</ManagementPackFragment>