Command Line adapter request and response for Microsoft Windows


In a Microsoft Windows environment, adapter requests use XML documents and need special formatting to handle the commands properly. Any directory or file name containing spaces must be enclosed in double quotation marks (" "). The backward slash \ must be escaped with an additional \ when used as a command or an attribute value. If double quotation marks are used in an attribute, the attribute value must be enclosed within single quotation marks ('') (single quotes) instead of the standard "".

When you use a context item as an input for an adapter request, you must enclose the adapter request in the <request-data> elements. However, when you create a static request, <request-data> is not required and the adapter request starts with the <adapterName-adapter-request> element.

BMC recommends that you do not include unused elements in the adapter configuration because they might cause errors.

Warning

Note

You cannot execute commands for the Windows Command Line adapter by using a domain administration account that has local administration rights.

The following table describes the elements of an adapter request for the Command Line adapter.

 Elements of an adapter request for the Command Line adapter

The following figure shows a sample Windows adapter request for the Command Line adapter.

XML sample of the Command Line adapter request for Windows

 

<command-request>
 <commands>
   <command>dir c:\\TempDirectory</command>
   <command>dir c:\\"Documents and Settings"</command>
   <command working dir="c:\\Windows\System32">dir</command>
   <command working dir='c:\\"Documents and Settings"'>dir</command>
   <command read-buffer-size="1024"></command>
 </commands>
</command-request>

The Command Line adapter returns an adapter response containing the results of the commands defined in the adapter request.

The following table describes the elements of a Command Line adapter response.

 Elements of a Command Line adapter response

 

The following figure illustrates a sample adapter response for the Command Line adapter.

XML sample of the Command Line adapter response

<command-result>
 <response-metadata>
  <status>success</status>
  <error>Present only with status of 'error'</error>
 </response-metadata>
 <targets-output>
  <target-output>
   <target-metadata>
     <os-id>system type</os-id>
     <os-version>system version</os-version>
     <os-arch>system architecture</os-arch>
     <status>success</status>
     <error>Present only with status of 'error'</error>
   </target-metadata>
   <commands-output>
    <command-output>
     <metadata>
      <command>ls -l</command>
      <working-dir>/</working-dir>
      <line-count>5</line-count>
      <execution-milliseconds>169</execution-milliseconds>
      <exit-code>0</exit-code>
      <status>success</status>
      <error>Present only with status of 'error'</error>
     </metadata>
     <output>
      <line index="1">total 12617</line>
      <line index="2">drwxrwxr-x 89 root admin 3026 4 Feb 19:29 Apps</line>
      <line index="3">drwxr-xr-x 4 root wheel 136 27 Jan 09:14 System</line>
      <line index="4">drwxrwxr-t 7 root admin 238 16 Aug 16:02 Users</line>
      <line index="5">drwxrwxrwt 5 root admin 170 12 Feb 23:48 Volumes</line>
     </output>
   </command-output>
  </commands-output>
  </target-output>
</targets-output>
</command-result>

The following figure shows a sample adapter request (Windows) for the Command Line adapter to set environment variables.

XML sample of the Command Line adapter request to set environment variables for Windows

<adapter-request>
  <env-variables>
     <env-variable>
       <name>New_Variable11</name>
       <value>New_varaible11_value</value>
     </env-variable>
     <env-variable>
       <name>New_Variable22</name>
       <value>New_varaible22_value</value>
     </env-variable>
  </env-variables>  
 <command-request>    
   <commands>         
     <command>dir</command>
   </commands>   
 </command-request>
</adapter-request>

The following figure shows a sample adapter request (Windows) for the Command Line adapter to clear environment variables.

XML sample of the Command Line adapter request to clear environment variables for Windows

<adapter-request>
  <env-variables>
     <env-variable>
       <name>New_Variable11</name>
       <value/>
     </env-variable>
     <env-variable>
       <name>New_Variable22</name>
       <value/>
     </env-variable>
  </env-variables>
<command-request>
   <commands>
     <command>dir</command>
   </commands>
</command-request>
</adapter-request>

  The following figure illustrates the sample adapter response (Windows) for the Command Line adapter explaining environment variables.

XML sample of the Command Line adapter response explaining environment variables for Windows

<command-result>
 <metadata>
   <status>success</status>
 </metadata>
 <targets-output>
   <target-output>
     <metadata>
       <os-id>Windows XP</os-id>
       <os-version>5.1</os-version>
       <os-arch>x86</os-arch>
       <status>success</status>
     </metadata>
       <commands-output>
        <command-output>
         <metadata>
           <command>ipconfig</command>
           <line-count>18</line-count>
           <execution-milliseconds>875</execution-milliseconds>
           <exit-code>0</exit-code>
           <status>success</status>
         </metadata>
         <output>
           <line index="1">Windows IP Configuration</line>
           <line index="2">Ethernet adapter Local Area Connection:</line>
           <line index="3">Media State . . . . . . . . . . . : Media disconnected
           </line>
           <line index="4">Ethernet adapter Wireless Network Connection:
           </line>
           <line index="5">Connection-specific DNS Suffix  . : </line>
           <line index="6">IP Address. . . . . . . . . . . . : 192.168.1.2
           </line>
           <line index="7">Subnet Mask . . . . . . . . . . . : 255.255.255.0
           </line>
             ...
           <line index="18">       Default Gateway . . . . . . . . . : 172.28.0.21
           </line>
         </output>
         </command-output>
        <command-output>
         <metadata>
           <command>set</command>
           <line-count>44</line-count>
           <execution-milliseconds>47</execution-milliseconds>
           <exit-code>0</exit-code>
           <status>success</status>
         </metadata>
         <output>
           <line index="1">abc2=abc2</line>
           <line index="2">ALLUSERSPROFILE=C:\Documents and Settings\All Users
           </line>
           <line index="3">APPDATA=C:\Documents and Settings\dbhola\Application Data
           </line>
           <line index="4">BAO_INSTALL_HOME=C:\Program Files\ABC Software\AO
           </line>
           <line index="5">BMCDEVSTUDIO_HOME=C:\Dev13758\studio
           </line>
       ......
         <line index="42">USERPROFILE=C:\Documents and Settings\dbhola
         </line>
           <line index="43">
            VSEDEFLOGDIR=C:\Documents and Settings\All Users\Application Data\McAfee\DesktopProtection
           </line>
           <line index="44">windir=C:\WINDOWS</line>
         </output>
        </command-output>
       </commands-output>
   </target-output>
 </targets-output>
</command-result>

The following figure shows a sample adapter request (Windows) for the Command Line adapter using multiple commands.

XML sample of the Command Line adapter request using multiple commands for Windows

<windows-commandline-request>
 <commands
   <command>ipconfig</command>
   <command>systeminfo</command>
 </commands>
</windows-commandline-request>

The following figure shows a sample adapter response (Windows) for the Command Line adapter using multiple command.

XML sample of the Command Line adapter response using multiple commands - Windows

 <adapter-response>
  <execution-duration>23</execution-duration>
  <status>success</status>
  <messageBase64></messageBase64>
  <data> <windows-command-output>
  <metadata> <status>success</status> </metadata>
  <targets-output>
    <target-output host="10.128.248.76">
    <metadata>
    <os-id>Windows 2003</os-id>
    <os-version>5.2 Build 3790 Service Pack 2</os-version>
    <status>success</status> </metadata>
    <commands-output> <command-output>
    <metadata>
     <command>ipconfig</command>
     <line-count>15</line-count>
     <execution-milliseconds>5922</execution-milliseconds>
     <exit-code>0</exit-code>
     <status>success</status>
   </metadata> <output>
   <line index="1">Copyright 2010 ABCD Ltd, Version: 1.1 </line>
   <line index="2">Connecting to remote service...</line>
   <line index="3">Connected to remote host.</line>
   <line index="4">Windows IP Configuration</line>
   <line index="5">Ethernet adapter Local Area Connection 2:</line>
   <line index="6">Connection-specific DNS Suffix . : </line>
   <line index="7"> Autoconfiguration IP Address..: 169.254.240.152</line>
   <line index="8"> Subnet Mask . . . . . . . . . . . : 255.255.0.0</line>
   <line index="9"> Default Gateway . . . . . . . . . : </line>
   <line index="10">Ethernet adapter Local Area Connection:</line>
   <line index="11"> Connection-specific DNS Suffix . : </line>
   <line index="12"> IP Address. . . . . . . . . . . . : 10.128.248.76</line>
   <line index="13"> Subnet Mask . . . . . . . . . . . : 255.255.254.0</line>
   <line index="14"> Default Gateway . . . . . . . . . : 10.128.248.1</line>
   <line index="15">Remote application exited with code: 0 </line>
  </output>
 </command-output>
 <command-output>
             <metadata>
             <command>systeminfo</command>
             <line-count>285</line-count>
             <execution-milliseconds>11281</execution-milliseconds>
             <exit-code>0</exit-code>
             <status>success</status>
             </metadata>
             <output>
              <line index="1">Copyright 2011 ABC Software Ltd, Version: 1.1 </line>
              <line index="2">Connecting to remote service...</line>
              <line index="3">Connected to remote host.</line>
              <line index="4">Host Name: S-17125</line>
              <line index="5">OS Name: Microsoft(R) Windows(R) Server
              2003, Standard Edition</line>
              <line index="6">OS Version: 5.2.3790 Service Pack 2 Build
              3790</line>
              <line index="7">OS Manufacturer: Microsoft Corporation</line>
              <line index="8">OS Configuration: Primary Domain Controller</line>
              <line index="9">OS Build Type: Multiprocessor Free</line>
              <line index="10">Registered Owner: Global</line>
              <line index="11">Registered Organization: ABC</line>
              <line index="12">Product ID: 69712-641-0555857-45451</line>
              <line index="13">Original Install Date: 8/30/2007, 8:35:36 PM</line>
              <line index="14">System Up Time: 1 Days, 14 Hours, 24 Minutes, 4
              .
              .
               .
             </output>
             </command-output>
            </commands-output>
           </target-output>
          </targets-output>
         </windows-command-output>
        </data>
</adapter-response>

 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*

BMC Atrium Orchestrator Content 20.14.02