How to use Command line tool

Initialization

 

1. Copy the needed files (mdcmd.exe and config.xml) from <Miradore server installation directory>\Connectors\MDCmd to the directory where from you want to use the Command line tool.

2. Set the needed configuration values to config.xml file. This file has to be in same directory as mdcmd.exe. Config.xml should look like the following:

 

<?xml version="1.0" encoding="UTF-8" ?>

<Config>

<UserName>domain\username</UserName>

<Password>password</Password>    

<ServerName>server host name</ServerName>

<ServerPort>port</ServerPort>

<ServerInstance>server instance name</ServerInstance>

<UseHttps>https</UseHttps>

<UseProxy>use proxy</UseProxy>

<ProxyHostName>proxy host</ProxyHostName>

<ProxyPort>proxy port</ProxyPort>

<ProxyUserName>proxy user</ProxyUserName>

<ProxyPassword>proxy password</ProxyPassword>

<ProxyAuthMethod>authentication method</ProxyAuthMethod>

<VerifyPeer>peer</VerifyPeer>

<VerifyHost>host</VerifyHost>

<CertFile>cert file</CertFile>

<OutputFormat>output format</OutputFormat>

<MaxImportCount>import count</MaxImportCount>

<LogOnlyErrors>log only errors</LogOnlyErrors>

<Separator>separator</Separator>

</Config>

 

Bold text are the configurations that the user has to make and are described below.

Configuration

Description

Notice

domain\username

A user name which has access to Miradore server

If this is empty, user account which runs mdcmd.exe is used for authentication.

password

Password of the user

If this is empty, user account which runs mdcmd.exe is used for authentication.

use proxy

Determines whether the connector uses proxy server to connect with Miradore server. 0 = No, 1 = Yes

Default = 0

proxy host

Host name or IP-address of the proxy server.

 

proxy port

Proxy server's port.

 

proxy user

Username for proxy server.

 

proxy password

Password for proxy server.

Command line tool encrypts plain text password.

authentication method

Authentication method that the proxy server uses. Available methods: None, Basic, Digest, and NTLM.

 

server host name

Host name of the Miradore server

required

port

Http(s) port of the Miradore server

default = 80

server instance name

Instance name of the Miradore server

required

https

Determines if HTTPS is used instead of HTTP. Possible values: 0 = false, 1 = true.

 

peer

Determines if server's SSL certificate is verified. Possible values: 0 = false, 1 = true. It's not advised to use HTTPS without certificate verification.

If https and this is set to 1, file which contains certificate authority root certificates must be located in the same directory than mdcmd.exe.

default = 0

host

Determines if server's host name must match the name defined in the certificate. Possible values: 0 = false, 1 = true. Setting this 0 makes HTTPS connection less secure.

This is ignored if 'peer' is set to 0.

default = 0

cert file

The path of certificate authority root certificate file if default file (cacert.pem) is not used. Default file is created to working directory if it doesn't exist.

 

output format

How the output is formatted (see Output below). Possible values:

0 = Human readable database table format

1 = XML

2 = Separator separated format, separator can be set by user (see below)

default = 0

import count

Command line tool divides the items to be imported into groups which are then sent to Miradore server. The import count determines how many items are included into a single group. After import of each group, a log file from Miradore server is printed out before the next group is imported.

 

log only errors

0 = A message is always printed after the command has been executed.

1 = A message is only printed when an error occurs.

default = 0

separator

Separator that is used to separate fields if output format = 2. This can be one or multiple characters long.

default = ;

 

Syntax

Miradore command line tool uses the following syntax:

mdcmd <command> <object> <parameter list>

Where:

Value name

Description

Notice

<command>

create, remove, update or get. To get a list of available commands type: mdcmd ? See Available commands for more information.

case sensitive

<object>

Object of the command. Depends on given <command>. To get list of available objects type: mdcmd <command> ?. See Available commands for more information.

case sensitive

<parameter list>

List of used parameters. Depends on <command> and <object>. To get a list of available parameters, type: mdcmd <command> <object> ?. Parameters are inputted by giving first a parameter handle and then a parameter value separated by space. If the parameter value has spaces, use quotations marks around the parameter.

Parameter handles are case sensitive.

Parameter values can contain Transact-SQL wildcard characters.

 

Examples

mdcmd ?

Returns available commands.

mdcmd get ?

Returns list of available objects which have the 'get' command implemented.

mdcmd get hw ?

Returns a list of available parameters that can be used to filter results of 'get' command of hardware basic data.

mdcmd get hw -hwm lenovo -m "thinkpad t61"

Returns all hardware basic data items of which the manufacturer is Lenovo and the model is Thinkpad T61.

mdcmd create hwmanufacturer -n "Test Manufacturer"

Creates a new hardware manufacturer which name is Test Manufacturer.

Notice that also quotes and other special characters can be used with the parameters by using two quotes around the whole parameter and using the special characters inside the string in doubles. See the examples below.

mdcmd.exe update assetconfig -dn L0000086 -pw “asd””123”

The input value of the password parameter is: asd"123

mdcmd.exe update assetconfig -dn L0000086 -pw “asd\\123”

The input value of the password parameter is: asd\123

 

Output

Command line tool’s output is important with get command which is used to get data about CIs. Command line tool prints its output to standard output. This can be redirected using command prompt’s ‘>’ operator. Command line tool supports three different output formats. These formats are database table like, XML and separator separated outputs. Output format is selected in configs.xml (see Initialization above).

Database table like format is human readable format which arranges data easily readable columns and rows.

XML formatted output prints out an XML document which contains all data returned from the server. Format of this XML document is shown below.

Separator separated format prints all data related to one CI on a single line separated by some string. This string can be defined in configs.xml file using the Separator element. Fields are printed in the same order than the columns in the database table like output.

 

When the output format is set to XML (see Initialization above), the Command line tool prints its output as XML in the following format:

 

<?xml version="1.0" encoding="UTF-8" ?>

<Response>

 

   <!-- Return code from server (0 = server side error, > 0 id of first Item that is processed)  -->

   <ReturnCode>Return code</ReturnCode>  

    

   <!-- Messages from server -->

   <Message>

      <Line>Message line 1</Line>

      <Line>Message line 2</Line>

      <Line>Message line N</Line>

   </Message>

    

   <!-- Information about processed command -->

   <Command>

 

      <!-- Name of target object that was processed -->

      <Target name="Target name">

 

         <-- Column names of target object that are read from database (used only with ‘get’ command -->

         <Columns>

             <Column name="Column 1" />

             <Column name="Column 2" />

             <Column name="Column N" />

         </Columns>

         </Target>

      

         <!-- Items that are found with ‘get’ command -->

         <ResultItems>

 

         <!-- Information about first found item -->

             <Item id="ID1">

 

                <!-- Database columns of first found item -->

                <Columns>

                    <Column name=" Column 1" value="Value of Column 1 of Item ID1" />

                    <Column name=" Column 2" value="Value of Column 2 of Item ID1" />

                    <Column name=" Column N" value="Value of Column N of Item ID1" />

                </Columns>

            </Item>

             

         <!-- Information about second found item -->

         <Item id="ID2">

            <Columns>

                <Column name=" Column 1" value="Value of Column 1 of Item ID2" />

                <Column name=" Column 2" value="Value of Column 2 of Item ID2" />

                <Column name=" Column N" value="Value of Column N of Item ID2" />

            </Columns>

         </Item>

         

 <!-- Information about Nth found item -->

         <Item id="IDN">

             <Columns>

                <Column name=" Column 1" value="Value of Column 1 of Item IDN" />

                <Column name=" Column 2" value="Value of Column 2 of Item IDN" />

                <Column name=" Column N" value="Value of Column N of Item IDN" />

             </Columns>

         </Item>

        </ResultItems>

    </Command>

</Response>

Exit codes

Command line tool returns following codes:

Code

Description

>0

Success, ID of first handled object

 0

Server side error

-1

Requested object is not found

-2

Failed to load response xml document

-3

Failed to create request xml document

-4

Failed to read response xml document

-5

Failed to open temporary file

-6

Failed to read temporary file

-7

Server name not found from configurations file.

-8

Server instance not found from configurations file

-9

Failed to initialize http connection

-10

Configurations file (config.xml) not found.

-11

Failed to send http request to server.

-12

Failed to write SSL root certificate file (cacert.pem)