Creating a new task with overridable parameters
Couple of days ago I saw a question on one of the newsgroups regarding creating a task where the operator can specify one or more parameters that are used by the task when launching the task. Unfortunately it’s not possible to create such as task today in the OpsMgr console, however you can do this using the SP1 RC authoring console or just in XML. The key part is defining a new WriteAction and specifying which parameter can be overriden (see the highlighted section below). Here is a sample MP that shows how you can do this in XML:
<
ManagementPack xmlns:xsd="https://www.w3.org/2001/XMLSchema" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance">
<
Manifest>
<
Identity>
<
ID>SampleMP.UserConfigurableTaskParameters</ID>
<
Version>1.0.0000.0</Version>
</
Identity>
<
Name>Sample MP - User Configurable Tasks Parameters</Name>
<
References>
<
Reference Alias="System">
<
ID>System.Library</ID>
<
Version>6.0.5000.0</Version>
<
PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
</
Reference>
<
Reference Alias="SystemHealth">
<
ID>System.Health.Library</ID>
<
Version>6.0.5000.0</Version>
<
PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
</
Reference>
<
Reference Alias="SystemPerf">
<
ID>System.Performance.Library</ID>
<
Version>6.0.5000.0</Version>
<
PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
</
Reference>
<
Reference Alias="Windows">
<
ID>Microsoft.Windows.Library</ID>
<
Version>6.0.5000.0</Version>
<
PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
</
Reference>
<
Reference Alias="SC">
<
ID>Microsoft.SystemCenter.Library</ID>
<
Version>6.0.5000.0</Version>
<
PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
</
Reference>
</
References>
</
Manifest>
<
TypeDefinitions>
<
ModuleTypes>
<
WriteActionModuleType ID="SampleTaskWriteAction" Accessibility="Internal" Batching="false">
<
Configuration>
<
xsd:element name="Parameter1" type="xsd:string"/>
<
xsd:element name="Parameter2" type="xsd:string"/>
<
xsd:element name="Parameter3" type="xsd:string"/>
<
xsd:element name="TimeoutSeconds" type="xsd:int"/>
</
Configuration>
<
OverrideableParameters >
<
OverrideableParameterID="Parameter1"Selector="$Config/Parameter1$"ParameterType="string" />
<
OverrideableParameterID="Parameter2"Selector="$Config/Parameter2$"ParameterType="string" />
<
OverrideableParameterID="Parameter3"Selector="$Config/Parameter3$"ParameterType="string" />
<
OverrideableParameterID="TimeoutSeconds"Selector="$Config/TimeoutSeconds$"ParameterType="int" />
</
OverrideableParameters >
<
ModuleImplementation Isolation="Any">
<
Composite>
<
MemberModules>
<
WriteAction ID="WA" TypeID="Windows!Microsoft.Windows.ScriptWriteAction">
<
ScriptName>SampleScript.js</ScriptName>
<
Arguments>"$Config/Parameter1$" "$Config/Parameter2$" "$Config/Parameter3$"</Arguments>
<
ScriptBody>
var scriptArgs = WScript.Arguments;
WScript.Echo("Parameter 1 " + scriptArgs(0));
WScript.Echo("Parameter 2 " + scriptArgs(1));
WScript.Echo("Parameter 3 " + scriptArgs(2));
</
ScriptBody>
<
TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</
WriteAction>
</
MemberModules>
<
Composition>
<
Node ID="WA" />
</
Composition>
</
Composite>
</
ModuleImplementation>
<
InputType>System!System.BaseData</InputType>
</
WriteActionModuleType>
</
ModuleTypes>
</
TypeDefinitions>
<
Monitoring>
<
Tasks>
<
Task ID="SampleTask" Accessibility="Internal" Enabled="true" Target="Windows!Microsoft.Windows.Computer" Timeout="300" Remotable="true">
<
Category>Maintenance</Category>
<
WriteAction ID="WA" TypeID="SampleTaskWriteAction">
<
Parameter1>Parameter1Value</Parameter1>
<
Parameter2>Parameter2Value</Parameter2>
<
Parameter3>Parameter3Value</Parameter3>
<
TimeoutSeconds>300</TimeoutSeconds>
</
WriteAction>
</
Task>
</
Tasks>
</
Monitoring>
</
ManagementPack>
SampleMP.UserConfigurableTaskParameters.xml
Comments
- Anonymous
December 11, 2007
PingBack from http://www.absolutely-people-search.info/?p=5812 - Anonymous
July 12, 2008
Check out Boris Yanushpolsky's blog ( http://blogs.msdn.com/boris_yanushpolsky ). Boris is an SCOM - Anonymous
July 08, 2009
Is it possible to have mutiple target for the task ? - Anonymous
July 13, 2009
No. A task can target only a single type. However, the task will also work for any derived types. For example, if you target a task to Windows Computer, it will work for all instaces of WindowsComputer(2003,2008,...).