Create Tasks

Applies To: Operations Manager 2007 R2

This topic provides information on how to create a management pack task that replaces a file on a managed server.

Create a Task to Replace a File

This topic describes how to create a task that updates the script to a known version on demand, which allows the administrator to easily correct an alert on any system that is being monitored.

This task uses Secure File Transfer Protocol (SFTP) to perform the transfer. The source file points to a folder and file that are located on the Operations Manager management server. The target file points to the location of the file on the monitored server.

Notice that the authentication that is used is coming from the action account that is configured in Operations Manager as the Run As account. You do not have to include any additional Run As notation within a workflow.

    <Tasks>
      <Task ID="Microsoft.SCX.Authoring.Guide.CopyScript.Task" Accessibility="Internal" Enabled="true" Target="Unix!Microsoft.Unix.Computer" Timeout="300" Remotable="true">
        <Category>Custom</Category>
        <WriteAction ID="sftp" TypeID="Unix!Microsoft.Unix.SFTPTransfer.WriteAction">
          <Host>$Target/Property[Type="Unix!Microsoft.Unix.Computer"]/PrincipalName$</Host>
          <Port>>$Host/Property[Type="Unix!Microsoft.Unix.Computer"]/SSHPort$</Port>
          <UserName>$RunAs[Name="Unix!Microsoft.Unix.ActionAccount"]/UserName$</UserName>
          <Password>$RunAs[Name="Unix!Microsoft.Unix.ActionAccount"]/Password$</Password>
          <SourceFile>C:\SampleScripts\SampleAppHealth.sh</SourceFile>
          <TargetFile>/tmp/SampleAppHealth.sh</TargetFile>
        </WriteAction>
      </Task>
    </Tasks>

In the Microsoft.SCX.Authoring.Guide.xml file that you created earlier, replace the preceding XML in the <Tasks/> subsection under the <Monitoring> section.

Save the file Microsoft.SCX.Authoring.Guide.xml and import the updated management pack into the management group, as described in the Required Management Pack Definitions topic.

Invoking a Task

To observe the computer that is being monitored, the health of the sample application and the available tasks, navigate to the Diagram View for the computer by following the instructions that are described in the Enable Application Discovery topic. On the right side of the Diagram View is a list of actions. Look for the list of Unix Computer Tasks. There should be a task that is named Microsoft.XCS.Authoring.Guide.CopyScript.Task. Click the task to open the Run Task dialog box. Click Run to start the task. The Diagram View should update the System Health to healthy the next that is that time the monitor runs.

Customizing a Task

Tasks can perform most of the individual actions that are handled by a monitor, on demand. This can be useful while you are isolating problems.

Below is a task equivalent to the discovery monitor that is described earlier. Notice that the probe action is identical to the one used in the discovery.

      <Task ID="Microsoft.SCX.Authoring.Guide.CheckFile.Task" Accessibility="Internal" Enabled="true" Target="Unix!Microsoft.Unix.Computer" Timeout="300" Remotable="true">
        <Category>Maintenance</Category>
        <ProbeAction ID="RunScript" TypeID="Unix!Microsoft.Unix.WSMan.Invoke.ProbeAction">
          <TargetSystem>$Target/Property[Type="Unix!Microsoft.Unix.Computer"]/PrincipalName$</TargetSystem>
          <Uri>https://schemas.microsoft.com/wbem/wscim/1/cim-schema/2/SCX_OperatingSystem?__cimnamespace=root/scx</Uri>
          <Selector />
          <InvokeAction>ExecuteCommand</InvokeAction>
          <Input><![CDATA[ <p:ExecuteCommand_INPUT xmlns:p="https://schemas.microsoft.com/wbem/wscim/1/cim-schema/2/SCX_OperatingSystem"><p:command>ls /tmp/SampleAppHealth.sh</p:command><p:timeout>10</p:timeout></p:ExecuteCommand_INPUT> ]]></Input>
        </ProbeAction>
      </Task>

The following task returns the MD5 hash of a target file. Notice that the probe action is identical to the earlier script monitor. When it is targeted correctly, this task is useful when you update the script monitor with a new hash value for a new replacement file.

      <Task ID="Microsoft.SCX.Authoring.Guide.GetMD5Script.Task" Accessibility="Internal" Enabled="true" Target="Unix!Microsoft.Unix.Computer" Timeout="300" Remotable="true">
        <Category>Maintenance</Category>
        <ProbeAction ID="RunScript" TypeID="Unix!Microsoft.Unix.WSMan.Invoke.ProbeAction">
          <TargetSystem>$Target/Property[Type="Unix!Microsoft.Unix.Computer"]/PrincipalName$</TargetSystem>
          <Uri>https://schemas.microsoft.com/wbem/wscim/1/cim-schema/2/SCX_OperatingSystem?__cimnamespace=root/scx</Uri>
          <Selector />
          <InvokeAction>ExecuteCommand</InvokeAction>
          <Input><![CDATA[ <p:ExecuteCommand_INPUT xmlns:p="https://schemas.microsoft.com/wbem/wscim/1/cim-schema/2/SCX_OperatingSystem"><p:command>md5sum /tmp/SampleAppHealth.sh</p:command><p:timeout>10</p:timeout></p:ExecuteCommand_INPUT> ]]></Input>
        </ProbeAction>
      </Task>